Skip to content

Commit

Permalink
When running as main, handle leading python
Browse files Browse the repository at this point in the history
  • Loading branch information
akamgm authored and saulpw committed Oct 27, 2023
1 parent 7ea7dce commit c0c638d
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion aipl/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,9 @@ def clean_to_id(s:str) -> str:
if __name__ == '__main__':
for file in sys.argv[1:]:
print("Parsing: ", file)
parse_tree = aipl_grammar.parse(open(file).read())
# prepend `!!python` to the input to correctly handle any leading python code
# see also: AIPL.run() method in interpreter.py
parse_tree = aipl_grammar.parse('!!python\n' + open(file).read())
print("Parse tree: ", parse_tree.pretty())
for command in ToAst().transform(parse_tree):
print(command)

0 comments on commit c0c638d

Please sign in to comment.