jaclang 0.5.11__py3-none-any.whl → 0.5.16__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.

Files changed (41) hide show
  1. jaclang/cli/cli.py +20 -0
  2. jaclang/compiler/__init__.py +35 -19
  3. jaclang/compiler/absyntree.py +106 -97
  4. jaclang/compiler/generated/jac_parser.py +4069 -0
  5. jaclang/compiler/jac.lark +655 -0
  6. jaclang/compiler/parser.py +44 -31
  7. jaclang/compiler/passes/main/fuse_typeinfo_pass.py +92 -37
  8. jaclang/compiler/passes/main/import_pass.py +8 -5
  9. jaclang/compiler/passes/main/pyast_gen_pass.py +512 -352
  10. jaclang/compiler/passes/main/pyast_load_pass.py +271 -64
  11. jaclang/compiler/passes/main/registry_pass.py +3 -7
  12. jaclang/compiler/passes/main/tests/test_pyast_gen_pass.py +2 -0
  13. jaclang/compiler/passes/main/type_check_pass.py +4 -1
  14. jaclang/compiler/passes/tool/jac_formatter_pass.py +7 -0
  15. jaclang/compiler/passes/tool/tests/test_unparse_validate.py +16 -0
  16. jaclang/compiler/passes/utils/mypy_ast_build.py +93 -0
  17. jaclang/compiler/tests/test_importer.py +15 -0
  18. jaclang/core/aott.py +4 -3
  19. jaclang/core/construct.py +1 -1
  20. jaclang/core/importer.py +109 -51
  21. jaclang/core/llms.py +29 -0
  22. jaclang/core/registry.py +22 -0
  23. jaclang/core/utils.py +72 -0
  24. jaclang/plugin/default.py +127 -8
  25. jaclang/plugin/feature.py +29 -2
  26. jaclang/plugin/spec.py +25 -2
  27. jaclang/utils/helpers.py +7 -9
  28. jaclang/utils/lang_tools.py +37 -13
  29. jaclang/utils/test.py +1 -3
  30. jaclang/utils/tests/test_lang_tools.py +6 -0
  31. jaclang/vendor/lark/grammars/common.lark +59 -0
  32. jaclang/vendor/lark/grammars/lark.lark +62 -0
  33. jaclang/vendor/lark/grammars/python.lark +302 -0
  34. jaclang/vendor/lark/grammars/unicode.lark +7 -0
  35. {jaclang-0.5.11.dist-info → jaclang-0.5.16.dist-info}/METADATA +1 -1
  36. {jaclang-0.5.11.dist-info → jaclang-0.5.16.dist-info}/RECORD +40 -34
  37. jaclang/compiler/__jac_gen__/jac_parser.py +0 -4069
  38. /jaclang/compiler/{__jac_gen__ → generated}/__init__.py +0 -0
  39. {jaclang-0.5.11.dist-info → jaclang-0.5.16.dist-info}/WHEEL +0 -0
  40. {jaclang-0.5.11.dist-info → jaclang-0.5.16.dist-info}/entry_points.txt +0 -0
  41. {jaclang-0.5.11.dist-info → jaclang-0.5.16.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.
@@ -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
- cur_dir = os.path.dirname(__file__)
9
- if not os.path.exists(os.path.join(cur_dir, "__jac_gen__", "jac_parser.py")):
10
- from jaclang.vendor.lark.tools import standalone
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.makedirs(os.path.join(cur_dir, "__jac_gen__"), exist_ok=True)
14
- with open(os.path.join(cur_dir, "__jac_gen__", "__init__.py"), "w"):
15
- pass
16
- save_argv = sys.argv
17
- sys.argv = [
18
- "lark",
19
- os.path.join(cur_dir, "jac.lark"),
20
- "-o",
21
- os.path.join(cur_dir, "__jac_gen__", "jac_parser.py"),
22
- "-c",
23
- ]
24
- standalone.main() # type: ignore
25
- sys.argv = save_argv
26
- auto_generate_refs()
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
- from .__jac_gen__ import jac_parser as jac_lark # noqa: E402
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