Skip to content

Commit

Permalink
fixing stamp parsing order
Browse files Browse the repository at this point in the history
  • Loading branch information
decrovert committed Aug 9, 2022
1 parent eb6d1fd commit c3452e9
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
21 changes: 19 additions & 2 deletions pobrelang.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
8 changes: 0 additions & 8 deletions pobrelanglib/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down
4 changes: 4 additions & 0 deletions test.pbr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c3452e9

Please sign in to comment.