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

Commit

Permalink
file_source added to tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
ThakeeNathees committed Jul 30, 2024
1 parent a771c73 commit a7f0c71
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions jaclang/compiler/passes/main/pyast_load_pass.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class PyastBuildPass(Pass[ast.PythonModuleAst]):
def __init__(self, input_ir: ast.PythonModuleAst) -> None:
"""Initialize parser."""
self.mod_path = input_ir.loc.mod_path
self.file_source = input_ir.loc.file_source
Pass.__init__(self, input_ir=input_ir, prior=None)

def nu(self, node: T) -> T:
Expand Down Expand Up @@ -151,6 +152,7 @@ class FunctionDef(stmt):
value = node.name if node.name not in reserved_keywords else f"<>{node.name}"
name = ast.Name(
file_path=self.mod_path,
file_source=self.file_source,
name=Tok.NAME,
value=value,
line=node.lineno,
Expand Down Expand Up @@ -264,6 +266,7 @@ class ClassDef(stmt):
"""
name = ast.Name(
file_path=self.mod_path,
file_source=self.file_source,
name=Tok.NAME,
value=node.name,
line=node.lineno,
Expand All @@ -275,6 +278,7 @@ class ClassDef(stmt):
)
arch_type = ast.Token(
file_path=self.mod_path,
file_source=self.file_source,
name=Tok.KW_CLASS,
value="class",
line=node.lineno,
Expand All @@ -293,6 +297,7 @@ class ClassDef(stmt):
):
tok = ast.Name(
file_path=self.mod_path,
file_source=self.file_source,
name=Tok.KW_INIT,
value="init",
line=node.lineno,
Expand Down Expand Up @@ -383,6 +388,7 @@ class ClassDef(stmt):
continue
pintok = ast.Token(
file_path=self.mod_path,
file_source=self.file_source,
name=Tok.PYNLINE,
value=py_ast.unparse(class_body_stmt),
line=node.lineno,
Expand Down Expand Up @@ -914,6 +920,7 @@ class Attribute(expr):
):
tok = ast.Name(
file_path=self.mod_path,
file_source=self.file_source,
name=Tok.KW_SUPER,
value="super",
line=node.lineno,
Expand All @@ -927,6 +934,7 @@ class Attribute(expr):
# exit()
attribute = ast.Name(
file_path=self.mod_path,
file_source=self.file_source,
name=Tok.NAME,
value=(
("<>" + node.attr)
Expand Down Expand Up @@ -1038,6 +1046,7 @@ def proc_break(self, node: py_ast.Break) -> ast.CtrlStmt:
"""Process python node."""
break_tok = ast.Token(
file_path=self.mod_path,
file_source=self.file_source,
name=Tok.KW_BREAK,
value="break",
line=0,
Expand Down Expand Up @@ -1149,6 +1158,7 @@ class Constant(expr):

return type_mapping[value_type](
file_path=self.mod_path,
file_source=self.file_source,
name=token_type,
value=(
f'"{repr(node.value)[1:-1]}"'
Expand All @@ -1165,6 +1175,7 @@ class Constant(expr):
elif node.value == Ellipsis:
return ast.Ellipsis(
file_path=self.mod_path,
file_source=self.file_source,
name=Tok.ELLIPSIS,
value="...",
line=node.lineno,
Expand All @@ -1181,6 +1192,7 @@ def proc_continue(self, node: py_ast.Continue) -> ast.CtrlStmt:
"""Process python node."""
continue_tok = ast.Token(
file_path=self.mod_path,
file_source=self.file_source,
name=Tok.KW_CONTINUE,
value="continue",
line=0,
Expand Down Expand Up @@ -1258,6 +1270,7 @@ class ExceptHandler(excepthandler):
if not type and not node.name:
type = ast.Name(
file_path=self.mod_path,
file_source=self.file_source,
name=Tok.NAME,
value="Exception",
line=node.lineno,
Expand All @@ -1269,6 +1282,7 @@ class ExceptHandler(excepthandler):
)
name = ast.Name(
file_path=self.mod_path,
file_source=self.file_source,
name=Tok.NAME,
value="e",
line=node.lineno,
Expand All @@ -1281,6 +1295,7 @@ class ExceptHandler(excepthandler):
else:
# type = ast.Name(
# file_path=self.mod_path,
# file_source=self.file_source,
# name=Tok.NAME,
# value=no,
# line=node.lineno,
Expand All @@ -1293,6 +1308,7 @@ class ExceptHandler(excepthandler):
name = (
ast.Name(
file_path=self.mod_path,
file_source=self.file_source,
name=Tok.NAME,
value=node.name,
line=node.lineno,
Expand Down Expand Up @@ -1393,6 +1409,7 @@ class Global(stmt):
names.append(
ast.Name(
file_path=self.mod_path,
file_source=self.file_source,
name=Tok.NAME,
value=id,
line=node.lineno,
Expand Down Expand Up @@ -1456,6 +1473,7 @@ class Import(stmt):
raise self.ice()
lang = ast.Name(
file_path=self.mod_path,
file_source=self.file_source,
name=Tok.NAME,
value="py",
line=node.lineno,
Expand Down Expand Up @@ -1486,6 +1504,7 @@ class ImportFrom(stmt):
"""
lang = ast.Name(
file_path=self.mod_path,
file_source=self.file_source,
name=Tok.NAME,
value="py",
line=node.lineno,
Expand All @@ -1501,6 +1520,7 @@ class ImportFrom(stmt):
modpaths.append(
ast.Name(
file_path=self.mod_path,
file_source=self.file_source,
name=Tok.NAME,
value=i,
line=node.lineno,
Expand Down Expand Up @@ -1665,6 +1685,7 @@ class MatchAs(pattern):
pattern = self.convert(node.pattern) if node.pattern else None
name = ast.Name(
file_path=self.mod_path,
file_source=self.file_source,
name=Tok.NAME,
value=node.name if node.name else "_",
line=node.lineno,
Expand Down Expand Up @@ -1719,6 +1740,7 @@ class MatchClass(pattern):
names.append(
ast.Name(
file_path=self.mod_path,
file_source=self.file_source,
name=Tok.NAME,
value=kwd_attrs,
line=node.lineno,
Expand Down Expand Up @@ -1779,6 +1801,7 @@ class MatchMapping(pattern):
if node.rest:
name = ast.Name(
file_path=self.mod_path,
file_source=self.file_source,
name=Tok.NAME,
value=node.rest,
line=node.lineno,
Expand Down Expand Up @@ -1824,6 +1847,7 @@ class MatchSingleton(pattern):
ret_type = ast.Null if node.value is None else ast.Bool
value = ret_type(
file_path=self.mod_path,
file_source=self.file_source,
name=type,
value=str(node.value),
line=node.lineno,
Expand All @@ -1846,6 +1870,7 @@ class MatchStar(pattern):
"""
name = ast.Name(
file_path=self.mod_path,
file_source=self.file_source,
name=Tok.NAME,
value=node.name if node.name else "_",
line=node.lineno,
Expand Down Expand Up @@ -1889,6 +1914,7 @@ class Name(expr):
value = node.id if node.id not in reserved_keywords else f"<>{node.id}"
ret = ast.Name(
file_path=self.mod_path,
file_source=self.file_source,
name=Tok.NAME,
value=value,
line=node.lineno,
Expand Down Expand Up @@ -1935,6 +1961,7 @@ class Nonlocal(stmt):
names.append(
ast.Name(
file_path=self.mod_path,
file_source=self.file_source,
name=Tok.NAME,
value=value,
line=node.lineno,
Expand All @@ -1952,6 +1979,7 @@ def proc_pass(self, node: py_ast.Pass) -> ast.Semi:
"""Process python node."""
return ast.Semi(
file_path=self.mod_path,
file_source=self.file_source,
name=Tok.SEMI,
value=";",
line=0,
Expand Down Expand Up @@ -2220,6 +2248,7 @@ class alias(AST):
"""
name = ast.Name(
file_path=self.mod_path,
file_source=self.file_source,
name=Tok.NAME,
value=node.name,
line=node.lineno,
Expand All @@ -2232,6 +2261,7 @@ class alias(AST):
asname = (
ast.Name(
file_path=self.mod_path,
file_source=self.file_source,
name=Tok.NAME,
value=node.asname,
line=node.lineno,
Expand Down Expand Up @@ -2266,6 +2296,7 @@ class arg(AST):
value = node.arg if node.arg not in reserved_keywords else f"<>{node.arg}"
name = ast.Name(
file_path=self.mod_path,
file_source=self.file_source,
name=Tok.NAME,
value=value,
line=node.lineno,
Expand All @@ -2280,6 +2311,7 @@ class arg(AST):
if node.annotation
else ast.Name(
file_path=self.mod_path,
file_source=self.file_source,
name=Tok.NAME,
value="Any",
line=node.lineno,
Expand Down Expand Up @@ -2314,6 +2346,7 @@ class arguments(AST):
if vararg and isinstance(vararg, ast.ParamVar):
vararg.unpack = ast.Token(
file_path=self.mod_path,
file_source=self.file_source,
name=Tok.STAR_MUL,
value="*",
line=vararg.loc.first_line,
Expand All @@ -2340,6 +2373,7 @@ class arguments(AST):
if kwarg and isinstance(kwarg, ast.ParamVar):
kwarg.unpack = ast.Token(
file_path=self.mod_path,
file_source=self.file_source,
name=Tok.STAR_POW,
value="**",
line=kwarg.loc.first_line,
Expand Down Expand Up @@ -2386,6 +2420,7 @@ def operator(self, tok: Tok, value: str) -> ast.Token:
"""Create an operator token."""
return ast.Token(
file_path=self.mod_path,
file_source=self.file_source,
name=tok,
value=value,
line=0,
Expand Down Expand Up @@ -2551,6 +2586,7 @@ class keyword(AST):
"""
arg = ast.Name(
file_path=self.mod_path,
file_source=self.file_source,
name=Tok.NAME,
value=node.arg if node.arg else "_",
line=node.lineno,
Expand Down

0 comments on commit a7f0c71

Please sign in to comment.