diff options
Diffstat (limited to 'src/journal_lib/utils.py')
-rw-r--r-- | src/journal_lib/utils.py | 27 |
1 files changed, 19 insertions, 8 deletions
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)) - |