Skip to content
This repository has been archived by the owner on Sep 12, 2024. It is now read-only.

Commit

Permalink
add the error message (optional) if exists
Browse files Browse the repository at this point in the history
  • Loading branch information
ThakeeNathees committed Jul 30, 2024
1 parent a7f0c71 commit c01fcf6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
10 changes: 4 additions & 6 deletions jaclang/compiler/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,10 @@ def transform(self, ir: ast.AstNode) -> ast.Module:
catch_error.pos_start = e.pos_in_stream or 0
catch_error.pos_end = catch_error.pos_start + 1

# TODO: Based on the lark error generate the message (consice).
# Example:
# Unexpected token, Unexpected End of File,
# Non terminated string literal, Invalid hex number (0x1zfk),
# Expected a semicollon, etc.
self.error("Syntax Error", node_override=catch_error)
error_msg = "Syntax Error"
if len(e.args) >= 1 and isinstance(e.args[0], str):
error_msg += e.args[0]
self.error(error_msg, node_override=catch_error)

except Exception as e:
self.error(f"Internal Error: {e}")
Expand Down
4 changes: 0 additions & 4 deletions jaclang/runtimelib/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,6 @@ def get_codeobj(

if result.errors_had or not result.ir.gen.py_bytecode:
for alrt in result.errors_had:
# logger.error(
# f"While importing {len(result.errors_had)} errors"
# f" found in {full_target}"
# )
logger.error(alrt.pretty_print())
return None
if result.ir.gen.py_bytecode is not None:
Expand Down
10 changes: 8 additions & 2 deletions jaclang/tests/test_language.py
Original file line number Diff line number Diff line change
Expand Up @@ -607,9 +607,12 @@ def test_pyfunc_3(self) -> None:

py_out_path = os.path.join(self.fixture_abs_path("./"), "pyfunc_3.py")
with open(py_out_path) as f:
file_source = f.read()
output = PyastBuildPass(
input_ir=ast.PythonModuleAst(
py_ast.parse(f.read()), mod_path=py_out_path
py_ast.parse(file_source),
mod_path=py_out_path,
file_source=file_source,
),
).ir.unparse()
self.assertIn("if 0 <= x<= 5 {", output)
Expand Down Expand Up @@ -726,9 +729,12 @@ def test_random_check(self) -> None:
module_path + ".py",
)
with open(file_path) as f:
file_source = f.read()
jac_ast = PyastBuildPass(
input_ir=ast.PythonModuleAst(
py_ast.parse(f.read()), mod_path=file_path
py_ast.parse(file_source),
mod_path=file_path,
file_source=file_source,
)
)
ir = jac_pass_to_pass(jac_ast).ir
Expand Down

0 comments on commit c01fcf6

Please sign in to comment.