jaclang 0.5.11__py3-none-any.whl → 0.5.15__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of jaclang might be problematic. Click here for more details.
- jaclang/cli/cli.py +20 -0
- jaclang/compiler/__init__.py +35 -19
- jaclang/compiler/absyntree.py +103 -95
- jaclang/compiler/generated/jac_parser.py +4069 -0
- jaclang/compiler/jac.lark +655 -0
- jaclang/compiler/parser.py +44 -31
- jaclang/compiler/passes/main/fuse_typeinfo_pass.py +92 -37
- jaclang/compiler/passes/main/import_pass.py +8 -5
- jaclang/compiler/passes/main/pyast_gen_pass.py +512 -352
- jaclang/compiler/passes/main/pyast_load_pass.py +271 -64
- jaclang/compiler/passes/main/registry_pass.py +3 -7
- jaclang/compiler/passes/main/tests/test_pyast_gen_pass.py +2 -0
- jaclang/compiler/passes/main/type_check_pass.py +4 -1
- jaclang/compiler/passes/tool/jac_formatter_pass.py +7 -0
- jaclang/compiler/passes/tool/tests/test_unparse_validate.py +16 -0
- jaclang/compiler/passes/utils/mypy_ast_build.py +93 -0
- jaclang/compiler/tests/test_importer.py +15 -0
- jaclang/core/aott.py +4 -3
- jaclang/core/construct.py +1 -1
- jaclang/core/importer.py +109 -51
- jaclang/core/llms.py +29 -0
- jaclang/core/registry.py +22 -0
- jaclang/core/utils.py +72 -0
- jaclang/plugin/default.py +118 -6
- jaclang/plugin/feature.py +29 -2
- jaclang/plugin/spec.py +25 -2
- jaclang/utils/helpers.py +7 -9
- jaclang/utils/lang_tools.py +37 -13
- jaclang/utils/test.py +1 -3
- jaclang/utils/tests/test_lang_tools.py +6 -0
- jaclang/vendor/lark/grammars/common.lark +59 -0
- jaclang/vendor/lark/grammars/lark.lark +62 -0
- jaclang/vendor/lark/grammars/python.lark +302 -0
- jaclang/vendor/lark/grammars/unicode.lark +7 -0
- {jaclang-0.5.11.dist-info → jaclang-0.5.15.dist-info}/METADATA +1 -1
- {jaclang-0.5.11.dist-info → jaclang-0.5.15.dist-info}/RECORD +40 -36
- jaclang/compiler/__jac_gen__/jac_parser.py +0 -4069
- jaclang/compiler/tests/fixtures/__jac_gen__/__init__.py +0 -0
- jaclang/compiler/tests/fixtures/__jac_gen__/hello_world.py +0 -5
- /jaclang/compiler/{__jac_gen__ → generated}/__init__.py +0 -0
- {jaclang-0.5.11.dist-info → jaclang-0.5.15.dist-info}/WHEEL +0 -0
- {jaclang-0.5.11.dist-info → jaclang-0.5.15.dist-info}/entry_points.txt +0 -0
- {jaclang-0.5.11.dist-info → jaclang-0.5.15.dist-info}/top_level.txt +0 -0
jaclang/cli/cli.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"""Command line interface tool for the Jac language."""
|
|
2
2
|
|
|
3
|
+
import ast as ast3
|
|
3
4
|
import importlib
|
|
4
5
|
import marshal
|
|
5
6
|
import os
|
|
@@ -8,10 +9,12 @@ import shutil
|
|
|
8
9
|
import types
|
|
9
10
|
from typing import Optional
|
|
10
11
|
|
|
12
|
+
import jaclang.compiler.absyntree as ast
|
|
11
13
|
from jaclang import jac_import
|
|
12
14
|
from jaclang.cli.cmdreg import CommandShell, cmd_registry
|
|
13
15
|
from jaclang.compiler.compile import jac_file_to_pass
|
|
14
16
|
from jaclang.compiler.constant import Constants
|
|
17
|
+
from jaclang.compiler.passes.main.pyast_load_pass import PyastBuildPass
|
|
15
18
|
from jaclang.compiler.passes.main.schedules import py_code_gen_typed
|
|
16
19
|
from jaclang.compiler.passes.tool.schedules import format_pass
|
|
17
20
|
from jaclang.plugin.builtin import dotgen
|
|
@@ -290,6 +293,23 @@ def graph(
|
|
|
290
293
|
print("Not a .jac file.")
|
|
291
294
|
|
|
292
295
|
|
|
296
|
+
@cmd_registry.register
|
|
297
|
+
def py_to_jac(filename: str, tree: bool = False) -> None:
|
|
298
|
+
"""Convert a Python file to Jac.
|
|
299
|
+
|
|
300
|
+
:param filename: The path to the .py file.
|
|
301
|
+
:param tree: Flag to show the AST tree.(Default-False).
|
|
302
|
+
"""
|
|
303
|
+
if filename.endswith(".py"):
|
|
304
|
+
with open(filename, "r") as f:
|
|
305
|
+
mod = PyastBuildPass(
|
|
306
|
+
input_ir=ast.PythonModuleAst(ast3.parse(f.read()), mod_path=filename),
|
|
307
|
+
).ir.unparse()
|
|
308
|
+
print(mod)
|
|
309
|
+
else:
|
|
310
|
+
print("Not a .py file.")
|
|
311
|
+
|
|
312
|
+
|
|
293
313
|
def start_cli() -> None:
|
|
294
314
|
"""
|
|
295
315
|
Start the command line interface.
|
jaclang/compiler/__init__.py
CHANGED
|
@@ -3,33 +3,48 @@
|
|
|
3
3
|
import contextlib
|
|
4
4
|
import logging
|
|
5
5
|
import os
|
|
6
|
+
import shutil
|
|
6
7
|
import sys
|
|
7
8
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
|
|
10
|
+
def generate_static_parser(force: bool = False) -> None:
|
|
11
|
+
"""Generate static parser."""
|
|
11
12
|
from jaclang.utils.helpers import auto_generate_refs
|
|
13
|
+
from jaclang.vendor.lark.tools import standalone
|
|
12
14
|
|
|
13
|
-
os.
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
"
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
15
|
+
cur_dir = os.path.dirname(__file__)
|
|
16
|
+
if force or not os.path.exists(os.path.join(cur_dir, "generated", "jac_parser.py")):
|
|
17
|
+
if os.path.exists(os.path.join(cur_dir, "generated")):
|
|
18
|
+
shutil.rmtree(os.path.join(cur_dir, "generated"))
|
|
19
|
+
os.makedirs(os.path.join(cur_dir, "generated"), exist_ok=True)
|
|
20
|
+
with open(os.path.join(cur_dir, "generated", "__init__.py"), "w"):
|
|
21
|
+
pass
|
|
22
|
+
save_argv = sys.argv
|
|
23
|
+
sys.argv = [
|
|
24
|
+
"lark",
|
|
25
|
+
os.path.join(cur_dir, "jac.lark"),
|
|
26
|
+
"-o",
|
|
27
|
+
os.path.join(cur_dir, "generated", "jac_parser.py"),
|
|
28
|
+
"-c",
|
|
29
|
+
]
|
|
30
|
+
standalone.main() # type: ignore
|
|
31
|
+
sys.argv = save_argv
|
|
32
|
+
try:
|
|
33
|
+
auto_generate_refs()
|
|
34
|
+
except Exception as e:
|
|
35
|
+
print(f"Error generating reference files: {e}")
|
|
27
36
|
|
|
28
37
|
|
|
29
|
-
|
|
38
|
+
generate_static_parser()
|
|
39
|
+
try:
|
|
40
|
+
from jaclang.compiler.generated import jac_parser as jac_lark # noqa: E402
|
|
30
41
|
|
|
42
|
+
jac_lark.logger.setLevel(logging.DEBUG)
|
|
43
|
+
except AttributeError:
|
|
44
|
+
generate_static_parser(force=True)
|
|
45
|
+
from jaclang.compiler.generated import jac_parser as jac_lark # noqa: E402
|
|
31
46
|
|
|
32
|
-
jac_lark.logger.setLevel(logging.DEBUG)
|
|
47
|
+
jac_lark.logger.setLevel(logging.DEBUG)
|
|
33
48
|
contextlib.suppress(AttributeError)
|
|
34
49
|
TOKEN_MAP = {
|
|
35
50
|
x.name: x.pattern.value
|
|
@@ -81,6 +96,7 @@ TOKEN_MAP.update(
|
|
|
81
96
|
"STAR_MUL": "*",
|
|
82
97
|
"FLOOR_DIV": "//",
|
|
83
98
|
"DIV": "/",
|
|
99
|
+
"PYNLINE": "::py::",
|
|
84
100
|
}
|
|
85
101
|
)
|
|
86
102
|
|