From 81f0f8de331b382caad8e82348a3ccbac5bb150e Mon Sep 17 00:00:00 2001 From: jakobst1n Date: Fri, 20 Oct 2023 19:35:32 +0200 Subject: Run black, and do some changes for enabling better syntax expandability --- src/journal_lib/utils.py | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) (limited to 'src/journal_lib/utils.py') diff --git a/src/journal_lib/utils.py b/src/journal_lib/utils.py index b8f645d..71d7fe4 100644 --- a/src/journal_lib/utils.py +++ b/src/journal_lib/utils.py @@ -2,28 +2,40 @@ from pathlib import Path from journal_lib.dataclasses import Journal from journal_lib.parse import JournalParser, JournalLexer, preprocess_includes + def journal_from_str(data: str, debug: bool = False) -> Journal: - """ Read a string of Journal entries into a Journal object """ - if debug: print("= Building lexer ===========") + """Read a string of Journal entries into a Journal object""" + if debug: + print("= Building lexer ===========") lexer = JournalLexer(debug=debug) - if debug: print("= Building parser ==========") + if debug: + print("= Building parser ==========") parser = JournalParser(debug=debug) - if debug: print("= PARSE ====================") + if debug: + print("= PARSE ====================") journal = parser.parse(data, lexer=lexer) - if debug: print("= JOURNAL ==================") + if debug: + print("= JOURNAL ==================") return journal + def journal_from_file(filename: Path, debug: bool = False) -> Journal: - """ Read a journal file into a Journal object """ + """Read a journal file into a Journal object""" journal_raw = preprocess_includes(filename) return journal_from_str(journal_raw, debug=debug) def test(): from argparse import ArgumentParser + parser = ArgumentParser() parser.add_argument("-f", "--file", help="The journal file to read") - parser.add_argument("-d", "--debug", action="store_true", help="Print more debug information from lexing and parsing") + parser.add_argument( + "-d", + "--debug", + action="store_true", + help="Print more debug information from lexing and parsing", + ) args = parser.parse_args() if args.file is not None: @@ -61,4 +73,3 @@ end comment Assets:Cash """ print(journal_from_str(data, debug=args.debug)) - -- cgit v1.2.3