From c3452e99816228a0e34ed336c00676153a92b33b Mon Sep 17 00:00:00 2001 From: decrovert Date: Tue, 9 Aug 2022 11:26:24 +0100 Subject: [PATCH] fixing stamp parsing order --- pobrelang.py | 21 +++++++++++++++++++-- pobrelanglib/parser.py | 8 -------- test.pbr | 4 ++++ 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/pobrelang.py b/pobrelang.py index 23f0e64..a53b309 100755 --- a/pobrelang.py +++ b/pobrelang.py @@ -28,6 +28,23 @@ del filename -while not parser.line_number == len(file_content): - parser.line_number += 1 +def iterate_file_content(activity) -> None: + while not parser.line_number == len(file_content): + parser.line_number += 1 + activity() + +def process_stamps() -> None: + line = file_content[parser.line_number - 1] + + line_tokens = lexer.lex_line(line) + + if len(line_tokens) > 0 and parser.is_token(line_tokens[0], "STM"): + parser.parse_line(line_tokens) + +def parse_linearly() -> None: parser.parse_line(lexer.lex_line(file_content[parser.line_number - 1])) + +iterate_file_content(process_stamps) +del process_stamps +parser.line_number = 0 +iterate_file_content(parse_linearly) diff --git a/pobrelanglib/parser.py b/pobrelanglib/parser.py index bd408e1..a3801ab 100644 --- a/pobrelanglib/parser.py +++ b/pobrelanglib/parser.py @@ -163,14 +163,6 @@ def parse_line(line: list[str]) -> None: logging.error(quotes.rms_quote(name)) sys.exit() - if not name in stamps: - try: - assert money - variable_cost > 0 - except AssertionError: - lt_panic("try to create a stamp with no money") - - money -= variable_cost - stamps[name] = line_number case "SPR": diff --git a/test.pbr b/test.pbr index f3566a5..f2b7b7a 100644 --- a/test.pbr +++ b/test.pbr @@ -19,10 +19,14 @@ item PobreLang/shit 3 item PobreLang/shit 3 item PobreLang/shit 3 +sprint PobreLang/skip + stamp PobreLang/shit scream Hello world! if 1>3 PobreLang/shit +stamp PobreLang/skip + burn PobreLang/shit item PobreLang/shit 0