Skip to content

Commit

Permalink
Merge pull request #140 from nbuilding/bug-fix
Browse files Browse the repository at this point in the history
Hotfix v1.2.2
  • Loading branch information
SheepTester authored Apr 26, 2021
2 parents eee7141 + 40e9d2c commit 309cb3b
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 19 deletions.
8 changes: 6 additions & 2 deletions python/scope.py
Original file line number Diff line number Diff line change
Expand Up @@ -967,7 +967,9 @@ async def eval_expr(self, expr):
"""

async def eval_command(self, tree):
if tree.data == "if" or tree.data == "ifelse":
if tree.data == "main_instruction" or tree.data == "last_instruction":
tree = tree.children[0]
if tree.data == "if" or tree.data == "ifelse" or tree.data == "for" or tree.data == "for_legacy":
tree = lark.tree.Tree("instruction", [tree])
elif tree.data == "code_block":
exit, value = (False, None)
Expand Down Expand Up @@ -1662,7 +1664,9 @@ def type_check_expr(self, expr):
"""

def type_check_command(self, tree):
if tree.data == "if" or tree.data == "ifelse":
if tree.data == "main_instruction" or tree.data == "last_instruction":
tree = tree.children[0]
if tree.data == "if" or tree.data == "ifelse" or tree.data == "for" or tree.data == "for_legacy":
tree = lark.tree.Tree("instruction", [tree])
elif tree.data == "code_block":
exit_point = None
Expand Down
40 changes: 24 additions & 16 deletions python/syntax.lark
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
start: [instruction*]

instruction: declare (";" | "\n")
| function_callback (";" | "\n")
| function_callback_pipe (";" | "\n")
| for (";" | "\n")?
| for_legacy (";" | "\n")?
| imp (";" | "\n")
| return (";" | "\n")
| if (";" | "\n")?
| ifelse (";" | "\n")?
| vary (";" | "\n")
| enum_definition (";" | "\n")
| alias_definition (";" | "\n")
| class_definition (";" | "\n")
start: [main_instruction* last_instruction]

main_instruction: instruction (";" | "\n")
| if (";" | "\n")?
| ifelse (";" | "\n")?
| for (";" | "\n")?
| for_legacy (";" | "\n")?

last_instruction: instruction (";" | "\n")?
| if (";" | "\n")?
| ifelse (";" | "\n")?
| for (";" | "\n")?
| for_legacy (";" | "\n")?

instruction: declare
| function_callback
| function_callback_pipe
| imp
| return
| vary
| enum_definition
| alias_definition
| class_definition

// functions
vary: "var " NAME "=" expression
Expand Down Expand Up @@ -40,7 +48,7 @@ name_type: pattern [":" types]
function_dec_call: NAME (" " [name_type (" " name_type)*])?
function_call: literal "(" [expression ("," expression)*] ")"
pipe_function_call: literal ["(" [expression ("," expression)*] ")"]
code_block: "{" [instruction (("\n" | ";") instruction)*] "}"
code_block: "{" [main_instruction* last_instruction] "}"
function_def: arguments ["->" types] code_block
arguments: "[" generic_declaration? arg_name_type* "]"
arg_name_type: definite_pattern [":" types]
Expand Down
6 changes: 5 additions & 1 deletion python/syntax_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ def format_error(e, file):
if isinstance(e, lark.exceptions.UnexpectedEOF):
spaces = " " * (len(str(len(file.lines) + 1) + " |") + 1) + " " * (-1)
spaces_arrow = " " * (len(str(len(file.lines) + 1) + " |") - 3)
formatted_chars = ", ".join(e.expected)
formatted_chars = ""
try:
formatted_chars = ", ".join(e.expected)
except:
formatted_chars = ", ".join([term.name for term in e.expected])
print(
f"{Fore.RED}{Style.BRIGHT}Error{Style.RESET_ALL}: Unexpected end of file, expected: [{formatted_chars}]"
)
Expand Down

0 comments on commit 309cb3b

Please sign in to comment.