jaclang 0.0.5__py3-none-any.whl → 0.0.8__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/__init__.py +2 -1
- jaclang/cli/__jac_gen__/__init__.py +0 -0
- jaclang/cli/__jac_gen__/cli.py +175 -0
- jaclang/cli/__jac_gen__/cmds.py +132 -0
- jaclang/cli/cli.jac +2 -2
- jaclang/cli/cmds.jac +8 -2
- jaclang/cli/impl/__jac_gen__/__init__.py +0 -0
- jaclang/cli/impl/__jac_gen__/cli_impl.py +16 -0
- jaclang/cli/impl/__jac_gen__/cmds_impl.py +26 -0
- jaclang/cli/impl/cli_impl.jac +25 -8
- jaclang/cli/impl/cmds_impl.jac +35 -6
- jaclang/core/__jac_gen__/__init__.py +0 -0
- jaclang/core/__jac_gen__/primitives.py +567 -0
- jaclang/core/impl/__jac_gen__/__init__.py +0 -0
- jaclang/core/impl/__jac_gen__/arch_impl.py +24 -0
- jaclang/core/impl/__jac_gen__/element_impl.py +26 -0
- jaclang/core/impl/__jac_gen__/exec_ctx_impl.py +12 -0
- jaclang/core/impl/__jac_gen__/memory_impl.py +14 -0
- jaclang/core/impl/element_impl.jac +3 -3
- jaclang/core/impl/exec_ctx_impl.jac +3 -6
- jaclang/core/primitives.jac +4 -3
- jaclang/jac/absyntree.py +555 -180
- jaclang/jac/constant.py +6 -0
- jaclang/jac/importer.py +34 -56
- jaclang/jac/langserve.py +26 -0
- jaclang/jac/lexer.py +35 -3
- jaclang/jac/parser.py +146 -115
- jaclang/jac/passes/blue/__init__.py +8 -3
- jaclang/jac/passes/blue/ast_build_pass.py +454 -305
- jaclang/jac/passes/blue/blue_pygen_pass.py +112 -74
- jaclang/jac/passes/blue/decl_def_match_pass.py +49 -277
- jaclang/jac/passes/blue/import_pass.py +1 -1
- jaclang/jac/passes/blue/pyout_pass.py +74 -0
- jaclang/jac/passes/blue/semantic_check_pass.py +37 -0
- jaclang/jac/passes/blue/sym_tab_build_pass.py +1045 -0
- jaclang/jac/passes/blue/tests/test_ast_build_pass.py +2 -2
- jaclang/jac/passes/blue/tests/test_blue_pygen_pass.py +9 -28
- jaclang/jac/passes/blue/tests/test_decl_def_match_pass.py +13 -22
- jaclang/jac/passes/blue/tests/test_sym_tab_build_pass.py +22 -0
- jaclang/jac/passes/ir_pass.py +8 -6
- jaclang/jac/passes/purple/__jac_gen__/__init__.py +0 -0
- jaclang/jac/passes/purple/__jac_gen__/analyze_pass.py +37 -0
- jaclang/jac/passes/purple/__jac_gen__/purple_pygen_pass.py +305 -0
- jaclang/jac/passes/purple/impl/__jac_gen__/__init__.py +0 -0
- jaclang/jac/passes/purple/impl/__jac_gen__/purple_pygen_pass_impl.py +23 -0
- jaclang/jac/passes/purple/impl/purple_pygen_pass_impl.jac +2 -5
- jaclang/jac/symtable.py +154 -0
- jaclang/jac/tests/fixtures/__jac_gen__/__init__.py +0 -0
- jaclang/jac/tests/fixtures/__jac_gen__/hello_world.py +16 -0
- jaclang/jac/tests/fixtures/fam.jac +7 -8
- jaclang/jac/tests/fixtures/mod_doc_test.jac +1 -0
- jaclang/jac/tests/test_parser.py +8 -0
- jaclang/jac/transform.py +41 -14
- jaclang/jac/transpiler.py +18 -9
- jaclang/utils/fstring_parser.py +2 -2
- jaclang/utils/helpers.py +41 -0
- jaclang/utils/lang_tools.py +12 -2
- jaclang/utils/test.py +41 -0
- jaclang/vendor/__init__.py +1 -0
- jaclang/vendor/pygls/__init__.py +25 -0
- jaclang/vendor/pygls/capabilities.py +502 -0
- jaclang/vendor/pygls/client.py +176 -0
- jaclang/vendor/pygls/constants.py +26 -0
- jaclang/vendor/pygls/exceptions.py +220 -0
- jaclang/vendor/pygls/feature_manager.py +241 -0
- jaclang/vendor/pygls/lsp/__init__.py +139 -0
- jaclang/vendor/pygls/lsp/client.py +2224 -0
- jaclang/vendor/pygls/lsprotocol/__init__.py +2 -0
- jaclang/vendor/pygls/lsprotocol/_hooks.py +1233 -0
- jaclang/vendor/pygls/lsprotocol/converters.py +17 -0
- jaclang/vendor/pygls/lsprotocol/types.py +12820 -0
- jaclang/vendor/pygls/lsprotocol/validators.py +47 -0
- jaclang/vendor/pygls/progress.py +79 -0
- jaclang/vendor/pygls/protocol.py +1184 -0
- jaclang/vendor/pygls/server.py +620 -0
- jaclang/vendor/pygls/uris.py +184 -0
- jaclang/vendor/pygls/workspace/__init__.py +81 -0
- jaclang/vendor/pygls/workspace/position.py +204 -0
- jaclang/vendor/pygls/workspace/text_document.py +234 -0
- jaclang/vendor/pygls/workspace/workspace.py +311 -0
- {jaclang-0.0.5.dist-info → jaclang-0.0.8.dist-info}/METADATA +1 -1
- jaclang-0.0.8.dist-info/RECORD +118 -0
- jaclang/core/jaclang.jac +0 -62
- jaclang/jac/passes/blue/tests/test_type_analyze_pass.py +0 -53
- jaclang/jac/passes/blue/type_analyze_pass.py +0 -728
- jaclang/jac/sym_table.py +0 -127
- jaclang-0.0.5.dist-info/RECORD +0 -73
- /jaclang/{utils → vendor}/sly/__init__.py +0 -0
- /jaclang/{utils → vendor}/sly/docparse.py +0 -0
- /jaclang/{utils → vendor}/sly/lex.py +0 -0
- /jaclang/{utils → vendor}/sly/yacc.py +0 -0
- {jaclang-0.0.5.dist-info → jaclang-0.0.8.dist-info}/WHEEL +0 -0
- {jaclang-0.0.5.dist-info → jaclang-0.0.8.dist-info}/entry_points.txt +0 -0
- {jaclang-0.0.5.dist-info → jaclang-0.0.8.dist-info}/top_level.txt +0 -0
jaclang/__init__.py
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"""The Jac Programming Language."""
|
|
2
|
-
from jaclang.jac.importer import
|
|
2
|
+
from jaclang.jac.importer import jac_blue_import, jac_purple_import
|
|
3
|
+
from jaclang.utils.helpers import handle_jac_error
|
|
3
4
|
|
|
4
5
|
__all__ = ["jac_blue_import", "jac_purple_import", "handle_jac_error"]
|
|
File without changes
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
"""
|
|
2
|
+
This is the implementation of the command line interface tool for the
|
|
3
|
+
Jac language. It's built with the Jac language via bootstraping and
|
|
4
|
+
represents the first such complete Jac program.
|
|
5
|
+
""" # 0 1
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
from jaclang import jac_purple_import as __jac_import__ # -1 0
|
|
8
|
+
import traceback as __jac_traceback__ # -1 0
|
|
9
|
+
from jaclang import handle_jac_error as __jac_error__ # -1 0
|
|
10
|
+
from jaclang.core import exec_ctx as _jac_exec_ctx_ # -1 0
|
|
11
|
+
from jaclang.core import Object as _jac_Object_ # -1 0
|
|
12
|
+
from jaclang.core import make_architype as _jac_make_architype_ # -1 0
|
|
13
|
+
import inspect # 0 7
|
|
14
|
+
|
|
15
|
+
import argparse # 0 8
|
|
16
|
+
|
|
17
|
+
import cmd # 0 9
|
|
18
|
+
|
|
19
|
+
__jac_import__(target='impl.cli_impl', base_path=__file__) # 0 10
|
|
20
|
+
from impl.cli_impl import * # 0 10
|
|
21
|
+
|
|
22
|
+
@_jac_make_architype_(_jac_Object_) # 0 13
|
|
23
|
+
class Command: # 0 13
|
|
24
|
+
def __init__(self, # 0 0
|
|
25
|
+
func = None, # 0 0
|
|
26
|
+
sig = None, # 0 0
|
|
27
|
+
*args, **kwargs): # 0 0
|
|
28
|
+
self.func = func # 0 0
|
|
29
|
+
self.sig = sig # 0 0
|
|
30
|
+
self.func = func # 1 4
|
|
31
|
+
self.sig = inspect.signature(func) # 1 4
|
|
32
|
+
|
|
33
|
+
def call(self,*args: list, **kwargs: dict): # 0 18
|
|
34
|
+
try: # 0 18
|
|
35
|
+
return self.func(*args, **kwargs) # 1 9
|
|
36
|
+
except Exception as e: # 0 18
|
|
37
|
+
tb = __jac_traceback__.extract_tb(e.__traceback__) # 0 18
|
|
38
|
+
__jac_tmp__ = __jac_error__(_jac_pycodestring_, e, tb) # 0 18
|
|
39
|
+
e.args = (f'{e.args[0]}\n' + __jac_tmp__,) + e.args[1:] if 'Jac error originates from...' not in str(e) else e.args # 0 18
|
|
40
|
+
raise e # 0 18 # 0 13
|
|
41
|
+
|
|
42
|
+
@_jac_make_architype_(_jac_Object_) # 0 22
|
|
43
|
+
class CommandRegistry: # 0 22
|
|
44
|
+
def __init__(self, # 0 0
|
|
45
|
+
registry = None, # 0 0
|
|
46
|
+
sub_parsers = None, # 0 0
|
|
47
|
+
parser = None, # 0 0
|
|
48
|
+
*args, **kwargs): # 0 0
|
|
49
|
+
self.registry = registry # 0 0
|
|
50
|
+
self.sub_parsers = sub_parsers # 0 0
|
|
51
|
+
self.parser = parser # 0 0
|
|
52
|
+
self.registry = {} # 1 13
|
|
53
|
+
self.parser = argparse.ArgumentParser(prog = "CLI") # 1 13
|
|
54
|
+
self.sub_parsers = self.parser.add_subparsers(title = "commands", dest = "command") # 1 13
|
|
55
|
+
|
|
56
|
+
def register(self,func: callable): # 0 28
|
|
57
|
+
try: # 0 28
|
|
58
|
+
name = func.__name__ # 1 20
|
|
59
|
+
cmd = Command(func) # 1 20
|
|
60
|
+
self.registry[name] = cmd # 1 20
|
|
61
|
+
cmd_parser = self.sub_parsers.add_parser(name) # 1 20
|
|
62
|
+
param_items = cmd.sig.parameters.items # 1 20
|
|
63
|
+
first = True # 1 20
|
|
64
|
+
for param_name,param in cmd.sig.parameters.items(): # 1 26
|
|
65
|
+
if param_name == "args": # 1 27
|
|
66
|
+
cmd_parser.add_argument('args', nargs = argparse.REMAINDER) # 1 28
|
|
67
|
+
|
|
68
|
+
elif param.default is param.empty: # 1 31
|
|
69
|
+
if first: # 1 32
|
|
70
|
+
first = False # 1 33
|
|
71
|
+
cmd_parser.add_argument(f"{param_name}", type = eval(param.annotation)) # 1 33
|
|
72
|
+
|
|
73
|
+
else: # 1 37
|
|
74
|
+
cmd_parser.add_argument(f"-{param_name[:1]}", f"--{param_name}", required = True, type = eval(param.annotation)) # 1 38
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
else: # 1 44
|
|
78
|
+
if first: # 1 45
|
|
79
|
+
first = False # 1 46
|
|
80
|
+
cmd_parser.add_argument(f"{param_name}", default = param.default, type = eval(param.annotation)) # 1 46
|
|
81
|
+
|
|
82
|
+
else: # 1 50
|
|
83
|
+
cmd_parser.add_argument(f"-{param_name[:1]}", f"--{param_name}", default = param.default, type = eval(param.annotation)) # 1 51 # 1 26
|
|
84
|
+
return func # 1 57
|
|
85
|
+
except Exception as e: # 0 28
|
|
86
|
+
tb = __jac_traceback__.extract_tb(e.__traceback__) # 0 28
|
|
87
|
+
__jac_tmp__ = __jac_error__(_jac_pycodestring_, e, tb) # 0 28
|
|
88
|
+
e.args = (f'{e.args[0]}\n' + __jac_tmp__,) + e.args[1:] if 'Jac error originates from...' not in str(e) else e.args # 0 28
|
|
89
|
+
raise e # 0 28
|
|
90
|
+
|
|
91
|
+
def get(self,name: str) -> Command: # 0 29
|
|
92
|
+
try: # 0 29
|
|
93
|
+
return self.registry.get(name) # 1 61
|
|
94
|
+
except Exception as e: # 0 29
|
|
95
|
+
tb = __jac_traceback__.extract_tb(e.__traceback__) # 0 29
|
|
96
|
+
__jac_tmp__ = __jac_error__(_jac_pycodestring_, e, tb) # 0 29
|
|
97
|
+
e.args = (f'{e.args[0]}\n' + __jac_tmp__,) + e.args[1:] if 'Jac error originates from...' not in str(e) else e.args # 0 29
|
|
98
|
+
raise e # 0 29
|
|
99
|
+
|
|
100
|
+
def items(self,) -> dict[str, Command]: # 0 30
|
|
101
|
+
try: # 0 30
|
|
102
|
+
return self.registry.items() # 1 65
|
|
103
|
+
except Exception as e: # 0 30
|
|
104
|
+
tb = __jac_traceback__.extract_tb(e.__traceback__) # 0 30
|
|
105
|
+
__jac_tmp__ = __jac_error__(_jac_pycodestring_, e, tb) # 0 30
|
|
106
|
+
e.args = (f'{e.args[0]}\n' + __jac_tmp__,) + e.args[1:] if 'Jac error originates from...' not in str(e) else e.args # 0 30
|
|
107
|
+
raise e # 0 30 # 0 22
|
|
108
|
+
|
|
109
|
+
@_jac_make_architype_(_jac_Object_) # 0 34
|
|
110
|
+
class CommandShell(cmd.Cmd): # 0 34
|
|
111
|
+
intro: str = "Welcome to the Jac CLI!" # 0 35
|
|
112
|
+
prompt: str = "jac> " # 0 35
|
|
113
|
+
|
|
114
|
+
def __init__(self, # 0 0
|
|
115
|
+
cmd_reg = None, # 0 0
|
|
116
|
+
*args, **kwargs): # 0 0
|
|
117
|
+
self.cmd_reg = cmd_reg # 0 0
|
|
118
|
+
self.cmd_reg = cmd_reg # 1 70
|
|
119
|
+
cmd.Cmd.__init__(self) # 1 70
|
|
120
|
+
|
|
121
|
+
def do_exit(self,arg: list) -> bool: # 0 40
|
|
122
|
+
try: # 0 40
|
|
123
|
+
return True # 1 75
|
|
124
|
+
except Exception as e: # 0 40
|
|
125
|
+
tb = __jac_traceback__.extract_tb(e.__traceback__) # 0 40
|
|
126
|
+
__jac_tmp__ = __jac_error__(_jac_pycodestring_, e, tb) # 0 40
|
|
127
|
+
e.args = (f'{e.args[0]}\n' + __jac_tmp__,) + e.args[1:] if 'Jac error originates from...' not in str(e) else e.args # 0 40
|
|
128
|
+
raise e # 0 40
|
|
129
|
+
|
|
130
|
+
def default(self,line: str): # 0 41
|
|
131
|
+
try: # 0 41
|
|
132
|
+
try: # 1 79
|
|
133
|
+
args = vars(self.cmd_reg.parser.parse_args(line.split())) # 1 80
|
|
134
|
+
command = self.cmd_reg.get(args["command"]) # 1 80
|
|
135
|
+
if command: # 1 82
|
|
136
|
+
args.pop("command") # 1 83
|
|
137
|
+
ret = command.call(**args) # 1 83
|
|
138
|
+
if ret: # 1 85
|
|
139
|
+
print(ret) # 1 86 # 1 79
|
|
140
|
+
except Exception as e: # 1 90
|
|
141
|
+
print(e) # 1 91 # 1 90 # 1 90 # 1 79
|
|
142
|
+
except Exception as e: # 0 41
|
|
143
|
+
tb = __jac_traceback__.extract_tb(e.__traceback__) # 0 41
|
|
144
|
+
__jac_tmp__ = __jac_error__(_jac_pycodestring_, e, tb) # 0 41
|
|
145
|
+
e.args = (f'{e.args[0]}\n' + __jac_tmp__,) + e.args[1:] if 'Jac error originates from...' not in str(e) else e.args # 0 41
|
|
146
|
+
raise e # 0 41 # 0 34
|
|
147
|
+
|
|
148
|
+
cmd_registry = CommandRegistry() # 0 45
|
|
149
|
+
|
|
150
|
+
def start_cli(): # 0 46
|
|
151
|
+
try: # 0 46
|
|
152
|
+
parser = cmd_registry.parser # 1 96
|
|
153
|
+
args = parser.parse_args() # 1 96
|
|
154
|
+
command = cmd_registry.get(args.command) # 1 96
|
|
155
|
+
if command: # 1 99
|
|
156
|
+
args = vars(args) # 1 100
|
|
157
|
+
args.pop("command") # 1 100
|
|
158
|
+
ret = command.call(**args) # 1 100
|
|
159
|
+
if ret: # 1 103
|
|
160
|
+
print(ret) # 1 104
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
else: # 1 107
|
|
164
|
+
shell = CommandShell(cmd_registry).cmdloop() # 1 108
|
|
165
|
+
|
|
166
|
+
except Exception as e: # 0 46
|
|
167
|
+
tb = __jac_traceback__.extract_tb(e.__traceback__) # 0 46
|
|
168
|
+
__jac_tmp__ = __jac_error__(_jac_pycodestring_, e, tb) # 0 46
|
|
169
|
+
e.args = (f'{e.args[0]}\n' + __jac_tmp__,) + e.args[1:] if 'Jac error originates from...' not in str(e) else e.args # 0 46
|
|
170
|
+
raise e # 0 46
|
|
171
|
+
|
|
172
|
+
r""" JAC DEBUG INFO
|
|
173
|
+
/home/ninja/jaclang/jaclang/cli/cli.jac
|
|
174
|
+
/home/ninja/jaclang/jaclang/cli/impl/cli_impl.jac
|
|
175
|
+
JAC DEBUG INFO """
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
"""
|
|
2
|
+
This is the implementation of the command line interface tool for the
|
|
3
|
+
Jac language. It's built with the Jac language via bootstraping and
|
|
4
|
+
represents the first such production Jac program.
|
|
5
|
+
""" # 2 1
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
from jaclang import jac_purple_import as __jac_import__ # -1 0
|
|
8
|
+
from jaclang.core import exec_ctx as _jac_exec_ctx_ # -1 0
|
|
9
|
+
from jaclang.core import Object as _jac_Object_ # -1 0
|
|
10
|
+
from jaclang.core import make_architype as _jac_make_architype_ # -1 0
|
|
11
|
+
import traceback as __jac_traceback__ # -1 0
|
|
12
|
+
from jaclang import handle_jac_error as __jac_error__ # -1 0
|
|
13
|
+
__jac_import__(target='cli', base_path=__file__) # 2 6
|
|
14
|
+
from cli import cmd_registry as cmd_reg # 2 6
|
|
15
|
+
|
|
16
|
+
__jac_import__(target='impl.cmds_impl', base_path=__file__) # 2 8
|
|
17
|
+
from impl.cmds_impl import * # 2 8
|
|
18
|
+
|
|
19
|
+
@cmd_reg.register # 2 10
|
|
20
|
+
def run(filename: str): # 2 11
|
|
21
|
+
try: # 2 11
|
|
22
|
+
if filename.endswith(".jac"): # 3 10
|
|
23
|
+
[base, mod] = os.path.split(filename) # 3 11
|
|
24
|
+
base = './' if not base else base # 3 11
|
|
25
|
+
mod = mod[:-4] # 3 11
|
|
26
|
+
__jac_import__(target = mod, base_path = base, override_name = "__main__") # 3 11
|
|
27
|
+
|
|
28
|
+
else: # 3 15
|
|
29
|
+
print("Not a .jac file.") # 3 16
|
|
30
|
+
|
|
31
|
+
except Exception as e: # 2 11
|
|
32
|
+
tb = __jac_traceback__.extract_tb(e.__traceback__) # 2 11
|
|
33
|
+
__jac_tmp__ = __jac_error__(_jac_pycodestring_, e, tb) # 2 11
|
|
34
|
+
e.args = (f'{e.args[0]}\n' + __jac_tmp__,) + e.args[1:] if 'Jac error originates from...' not in str(e) else e.args # 2 11
|
|
35
|
+
raise e # 2 11
|
|
36
|
+
|
|
37
|
+
@cmd_reg.register # 2 13
|
|
38
|
+
def enter(filename: str, entrypoint: str, args: list): # 2 14
|
|
39
|
+
try: # 2 14
|
|
40
|
+
if filename.endswith(".jac"): # 3 23
|
|
41
|
+
[base, mod] = os.path.split(filename) # 3 24
|
|
42
|
+
base = './' if not base else base # 3 24
|
|
43
|
+
mod = mod[:-4] # 3 24
|
|
44
|
+
mod = __jac_import__(target = mod, base_path = base) # 3 24
|
|
45
|
+
if not mod: # 3 28
|
|
46
|
+
print('Errors occured while importing the module.') # 3 29
|
|
47
|
+
return # 3 30
|
|
48
|
+
|
|
49
|
+
else: # 3 32
|
|
50
|
+
(getattr(mod, entrypoint))() # 3 33
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
else: # 3 35
|
|
54
|
+
print("Not a .jac file.") # 3 36
|
|
55
|
+
|
|
56
|
+
except Exception as e: # 2 14
|
|
57
|
+
tb = __jac_traceback__.extract_tb(e.__traceback__) # 2 14
|
|
58
|
+
__jac_tmp__ = __jac_error__(_jac_pycodestring_, e, tb) # 2 14
|
|
59
|
+
e.args = (f'{e.args[0]}\n' + __jac_tmp__,) + e.args[1:] if 'Jac error originates from...' not in str(e) else e.args # 2 14
|
|
60
|
+
raise e # 2 14
|
|
61
|
+
|
|
62
|
+
@cmd_reg.register # 2 16
|
|
63
|
+
def test(filename: str): # 2 17
|
|
64
|
+
try: # 2 17
|
|
65
|
+
if filename.endswith(".jac"): # 3 43
|
|
66
|
+
[base, mod] = os.path.split(filename) # 3 44
|
|
67
|
+
base = './' if not base else base # 3 44
|
|
68
|
+
mod = mod[:-4] # 3 44
|
|
69
|
+
mod = __jac_import__(target = mod, base_path = base) # 3 44
|
|
70
|
+
unittest.TextTestRunner().run(mod.__jac_suite__) # 3 44
|
|
71
|
+
|
|
72
|
+
else: # 3 49
|
|
73
|
+
print("Not a .jac file.") # 3 50
|
|
74
|
+
|
|
75
|
+
except Exception as e: # 2 17
|
|
76
|
+
tb = __jac_traceback__.extract_tb(e.__traceback__) # 2 17
|
|
77
|
+
__jac_tmp__ = __jac_error__(_jac_pycodestring_, e, tb) # 2 17
|
|
78
|
+
e.args = (f'{e.args[0]}\n' + __jac_tmp__,) + e.args[1:] if 'Jac error originates from...' not in str(e) else e.args # 2 17
|
|
79
|
+
raise e # 2 17
|
|
80
|
+
|
|
81
|
+
@cmd_reg.register # 2 19
|
|
82
|
+
def ast_tool(tool: str): # 2 20
|
|
83
|
+
try: # 2 20
|
|
84
|
+
from jaclang.utils.lang_tools import AstTool # 3 56
|
|
85
|
+
if (hasattr(AstTool, tool)): # 3 57
|
|
86
|
+
print(getattr(AstTool(), tool)()) # 3 58
|
|
87
|
+
|
|
88
|
+
else: # 3 59
|
|
89
|
+
print(f"Ast tool {tool} not found.") # 3 60
|
|
90
|
+
|
|
91
|
+
except Exception as e: # 2 20
|
|
92
|
+
tb = __jac_traceback__.extract_tb(e.__traceback__) # 2 20
|
|
93
|
+
__jac_tmp__ = __jac_error__(_jac_pycodestring_, e, tb) # 2 20
|
|
94
|
+
e.args = (f'{e.args[0]}\n' + __jac_tmp__,) + e.args[1:] if 'Jac error originates from...' not in str(e) else e.args # 2 20
|
|
95
|
+
raise e # 2 20
|
|
96
|
+
|
|
97
|
+
@cmd_reg.register # 2 22
|
|
98
|
+
def lsp(): # 2 23
|
|
99
|
+
try: # 2 23
|
|
100
|
+
from jaclang.jac.langserve import server # 3 66
|
|
101
|
+
print("Starting server...") # 3 66
|
|
102
|
+
server.start_io() # 3 66
|
|
103
|
+
except Exception as e: # 2 23
|
|
104
|
+
tb = __jac_traceback__.extract_tb(e.__traceback__) # 2 23
|
|
105
|
+
__jac_tmp__ = __jac_error__(_jac_pycodestring_, e, tb) # 2 23
|
|
106
|
+
e.args = (f'{e.args[0]}\n' + __jac_tmp__,) + e.args[1:] if 'Jac error originates from...' not in str(e) else e.args # 2 23
|
|
107
|
+
raise e # 2 23
|
|
108
|
+
|
|
109
|
+
@cmd_reg.register # 2 25
|
|
110
|
+
def clean(): # 2 26
|
|
111
|
+
try: # 2 26
|
|
112
|
+
current_dir = os.getcwd() # 3 73
|
|
113
|
+
py_cache = "__pycache__" # 3 73
|
|
114
|
+
for root,dirs,files in os.walk(current_dir, topdown = True): # 3 75
|
|
115
|
+
for folder_name in dirs[:]: # 3 76
|
|
116
|
+
if folder_name == C.JAC_GEN_DIR or folder_name == py_cache: # 3 77
|
|
117
|
+
folder_to_remove = os.path.join(root, folder_name) # 3 78
|
|
118
|
+
shutil.rmtree(folder_to_remove) # 3 78
|
|
119
|
+
print(f"Removed folder: {folder_to_remove}") # 3 78 # 3 76 # 3 75
|
|
120
|
+
print("Done cleaning.") # 3 73
|
|
121
|
+
except Exception as e: # 2 26
|
|
122
|
+
tb = __jac_traceback__.extract_tb(e.__traceback__) # 2 26
|
|
123
|
+
__jac_tmp__ = __jac_error__(_jac_pycodestring_, e, tb) # 2 26
|
|
124
|
+
e.args = (f'{e.args[0]}\n' + __jac_tmp__,) + e.args[1:] if 'Jac error originates from...' not in str(e) else e.args # 2 26
|
|
125
|
+
raise e # 2 26
|
|
126
|
+
|
|
127
|
+
r""" JAC DEBUG INFO
|
|
128
|
+
/home/ninja/jaclang/jaclang/cli/cli.jac
|
|
129
|
+
/home/ninja/jaclang/jaclang/cli/impl/cli_impl.jac
|
|
130
|
+
/home/ninja/jaclang/jaclang/cli/cmds.jac
|
|
131
|
+
/home/ninja/jaclang/jaclang/cli/impl/cmds_impl.jac
|
|
132
|
+
JAC DEBUG INFO """
|
jaclang/cli/cli.jac
CHANGED
|
@@ -14,7 +14,7 @@ object Command {
|
|
|
14
14
|
has func: callable,
|
|
15
15
|
sig: inspect.Signature;
|
|
16
16
|
|
|
17
|
-
can:private <init
|
|
17
|
+
can:private <init>;
|
|
18
18
|
can call(*args: list, **kwargs: dict);
|
|
19
19
|
}
|
|
20
20
|
|
|
@@ -36,7 +36,7 @@ object CommandShell:cmd.Cmd {
|
|
|
36
36
|
prompt: str = "jac> ";
|
|
37
37
|
has cmd_reg: CommandRegistry;
|
|
38
38
|
|
|
39
|
-
can <init
|
|
39
|
+
can <init>;
|
|
40
40
|
can do_exit(arg: list) -> bool;
|
|
41
41
|
can default(line: str);
|
|
42
42
|
}
|
jaclang/cli/cmds.jac
CHANGED
|
@@ -8,13 +8,19 @@ import:jac from cli, cmd_registry as cmd_reg;
|
|
|
8
8
|
include:jac impl.cmds_impl;
|
|
9
9
|
|
|
10
10
|
@cmd_reg.register
|
|
11
|
-
can
|
|
11
|
+
can run(filename: str);
|
|
12
12
|
|
|
13
13
|
@cmd_reg.register
|
|
14
|
-
can
|
|
14
|
+
can enter(filename: str, entrypoint: str, args: list);
|
|
15
|
+
|
|
16
|
+
@cmd_reg.register
|
|
17
|
+
can <>test(filename: str);
|
|
15
18
|
|
|
16
19
|
@cmd_reg.register
|
|
17
20
|
can ast_tool(tool: str);
|
|
18
21
|
|
|
22
|
+
@cmd_reg.register
|
|
23
|
+
can lsp;
|
|
24
|
+
|
|
19
25
|
@cmd_reg.register
|
|
20
26
|
can clean;
|
|
File without changes
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"""Implemenation for Jac's command line interface.""" # 1 1
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
r""" JAC DEBUG INFO
|
|
14
|
+
/home/ninja/jaclang/jaclang/cli/cli.jac
|
|
15
|
+
/home/ninja/jaclang/jaclang/cli/impl/cli_impl.jac
|
|
16
|
+
JAC DEBUG INFO """
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"""Implementations for the jac command line interface.""" # 3 1
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
from jaclang import jac_purple_import as __jac_import__ # -1 0
|
|
4
|
+
from jaclang.core import exec_ctx as _jac_exec_ctx_ # -1 0
|
|
5
|
+
from jaclang.core import Object as _jac_Object_ # -1 0
|
|
6
|
+
from jaclang.core import make_architype as _jac_make_architype_ # -1 0
|
|
7
|
+
import os # 3 2
|
|
8
|
+
|
|
9
|
+
import shutil # 3 3
|
|
10
|
+
|
|
11
|
+
import unittest # 3 4
|
|
12
|
+
|
|
13
|
+
from jaclang.jac.constant import Constants as C # 3 5
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
r""" JAC DEBUG INFO
|
|
22
|
+
/home/ninja/jaclang/jaclang/cli/cli.jac
|
|
23
|
+
/home/ninja/jaclang/jaclang/cli/impl/cli_impl.jac
|
|
24
|
+
/home/ninja/jaclang/jaclang/cli/cmds.jac
|
|
25
|
+
/home/ninja/jaclang/jaclang/cli/impl/cmds_impl.jac
|
|
26
|
+
JAC DEBUG INFO """
|
jaclang/cli/impl/cli_impl.jac
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"""Implemenation for Jac's command line interface."""
|
|
2
2
|
|
|
3
|
-
:o:Command:a:<init>
|
|
3
|
+
:o:Command:a:<init> {
|
|
4
4
|
<s>.func = func;
|
|
5
5
|
<s>.sig = func |> inspect.signature;
|
|
6
6
|
}
|
|
@@ -21,20 +21,37 @@
|
|
|
21
21
|
cmd = func |> Command;
|
|
22
22
|
<s>.registry[name] = cmd;
|
|
23
23
|
cmd_parser = name |> <s>.sub_parsers.add_parser;
|
|
24
|
+
param_items = cmd.sig.parameters.items;
|
|
25
|
+
first = True;
|
|
24
26
|
for param_name, param in |> cmd.sig.parameters.items {
|
|
25
27
|
if param_name == "args" {
|
|
26
28
|
('args', nargs=argparse.REMAINDER)
|
|
27
29
|
|> cmd_parser.add_argument;
|
|
28
30
|
}
|
|
29
31
|
elif param.default is param.empty {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
32
|
+
if first {
|
|
33
|
+
first = False;
|
|
34
|
+
(f"{param_name}", type=param.annotation|>eval)
|
|
35
|
+
|> cmd_parser.add_argument;
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
(f"-{param_name[:1]}", f"--{param_name}",
|
|
39
|
+
required=True, type=param.annotation|>eval)
|
|
40
|
+
|> cmd_parser.add_argument;
|
|
41
|
+
}
|
|
42
|
+
|
|
33
43
|
}
|
|
34
44
|
else {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
45
|
+
if first {
|
|
46
|
+
first = False;
|
|
47
|
+
(f"{param_name}", default=param.default, type=param.annotation|>eval)
|
|
48
|
+
|> cmd_parser.add_argument;
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
(f"-{param_name[:1]}", f"--{param_name}",
|
|
52
|
+
default=param.default, type=param.annotation|>eval)
|
|
53
|
+
|> cmd_parser.add_argument;
|
|
54
|
+
}
|
|
38
55
|
}
|
|
39
56
|
}
|
|
40
57
|
return func;
|
|
@@ -49,7 +66,7 @@
|
|
|
49
66
|
}
|
|
50
67
|
|
|
51
68
|
|
|
52
|
-
:o:CommandShell:a:<init>
|
|
69
|
+
:o:CommandShell:a:<init> {
|
|
53
70
|
<s>.cmd_reg = cmd_reg;
|
|
54
71
|
<s> |> cmd.Cmd.<init>;
|
|
55
72
|
}
|
jaclang/cli/impl/cmds_impl.jac
CHANGED
|
@@ -1,29 +1,51 @@
|
|
|
1
1
|
"""Implementations for the jac command line interface."""
|
|
2
2
|
import:py os;
|
|
3
3
|
import:py shutil;
|
|
4
|
+
import:py unittest;
|
|
5
|
+
import:py from jaclang.jac.constant, Constants as C;
|
|
4
6
|
|
|
5
7
|
"""Load a .jac file and return the entrypoint function."""
|
|
6
|
-
:a:
|
|
8
|
+
:a:run
|
|
7
9
|
(filename: str) {
|
|
8
10
|
if filename.endswith(".jac"){
|
|
9
11
|
[base, mod] = os.path.split(filename);
|
|
10
12
|
base = './' if not base else base;
|
|
11
13
|
mod=mod[:-4];
|
|
12
|
-
__jac_import__(target=mod, base_path=base);
|
|
14
|
+
__jac_import__(target=mod, base_path=base, override_name="__main__");
|
|
13
15
|
} else {
|
|
14
16
|
"Not a .jac file." :> print;
|
|
15
17
|
}
|
|
16
18
|
}
|
|
17
19
|
|
|
18
20
|
"""Run the entrypoint of the given .jac file."""
|
|
19
|
-
:a:
|
|
21
|
+
:a:enter
|
|
20
22
|
(filename: str, entrypoint: str, args: list) {
|
|
23
|
+
if filename.endswith(".jac") {
|
|
24
|
+
[base, mod] = os.path.split(filename);
|
|
25
|
+
base = './' if not base else base;
|
|
26
|
+
mod=mod[:-4];
|
|
27
|
+
mod = __jac_import__(target=mod, base_path=base);
|
|
28
|
+
if not mod {
|
|
29
|
+
print('Errors occured while importing the module.');
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
:> ((mod, entrypoint) :> getattr );
|
|
34
|
+
}
|
|
35
|
+
} else {
|
|
36
|
+
"Not a .jac file." :> print;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
"""Load a .jac file and return the entrypoint function."""
|
|
41
|
+
:a:<>test
|
|
42
|
+
(filename: str) {
|
|
21
43
|
if filename.endswith(".jac"){
|
|
22
44
|
[base, mod] = os.path.split(filename);
|
|
23
45
|
base = './' if not base else base;
|
|
24
46
|
mod=mod[:-4];
|
|
25
47
|
mod = __jac_import__(target=mod, base_path=base);
|
|
26
|
-
|
|
48
|
+
unittest.TextTestRunner().run(mod.__jac_suite__);
|
|
27
49
|
} else {
|
|
28
50
|
"Not a .jac file." :> print;
|
|
29
51
|
}
|
|
@@ -39,14 +61,20 @@ import:py shutil;
|
|
|
39
61
|
}
|
|
40
62
|
}
|
|
41
63
|
|
|
64
|
+
"""Run language server for Jac."""
|
|
65
|
+
:a:lsp {
|
|
66
|
+
import:py from jaclang.jac.langserve, server;
|
|
67
|
+
print("Starting server...");
|
|
68
|
+
server.start_io();
|
|
69
|
+
}
|
|
70
|
+
|
|
42
71
|
"""Remove the __jac_gen__ , __pycache__ folders from the current directory recursevely."""
|
|
43
72
|
:a:clean {
|
|
44
73
|
current_dir = os.getcwd();
|
|
45
|
-
jac_gen = "__jac_gen__";
|
|
46
74
|
py_cache = "__pycache__";
|
|
47
75
|
for root, dirs, files in os.walk(current_dir, topdown=True) {
|
|
48
76
|
for folder_name in dirs[:] {
|
|
49
|
-
if folder_name ==
|
|
77
|
+
if folder_name == C.JAC_GEN_DIR or folder_name == py_cache {
|
|
50
78
|
folder_to_remove = os.path.join(root, folder_name);
|
|
51
79
|
shutil.rmtree(folder_to_remove);
|
|
52
80
|
print(f"Removed folder: {folder_to_remove}");
|
|
@@ -55,3 +83,4 @@ import:py shutil;
|
|
|
55
83
|
}
|
|
56
84
|
print("Done cleaning.");
|
|
57
85
|
}
|
|
86
|
+
|
|
File without changes
|