jaclang 0.0.5__tar.gz → 0.0.8__tar.gz

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 (131) hide show
  1. {jaclang-0.0.5 → jaclang-0.0.8}/PKG-INFO +1 -1
  2. jaclang-0.0.8/README.md +197 -0
  3. jaclang-0.0.8/jaclang/__init__.py +5 -0
  4. jaclang-0.0.8/jaclang/cli/__jac_gen__/__init__.py +0 -0
  5. jaclang-0.0.8/jaclang/cli/__jac_gen__/cli.py +175 -0
  6. jaclang-0.0.8/jaclang/cli/__jac_gen__/cmds.py +132 -0
  7. {jaclang-0.0.5 → jaclang-0.0.8}/jaclang/cli/cli.jac +2 -2
  8. {jaclang-0.0.5 → jaclang-0.0.8}/jaclang/cli/cmds.jac +8 -2
  9. jaclang-0.0.8/jaclang/cli/impl/__jac_gen__/__init__.py +0 -0
  10. jaclang-0.0.8/jaclang/cli/impl/__jac_gen__/cli_impl.py +16 -0
  11. jaclang-0.0.8/jaclang/cli/impl/__jac_gen__/cmds_impl.py +26 -0
  12. {jaclang-0.0.5 → jaclang-0.0.8}/jaclang/cli/impl/cli_impl.jac +25 -8
  13. {jaclang-0.0.5 → jaclang-0.0.8}/jaclang/cli/impl/cmds_impl.jac +35 -6
  14. jaclang-0.0.8/jaclang/core/__jac_gen__/__init__.py +0 -0
  15. jaclang-0.0.8/jaclang/core/__jac_gen__/primitives.py +567 -0
  16. jaclang-0.0.8/jaclang/core/impl/__jac_gen__/__init__.py +0 -0
  17. jaclang-0.0.8/jaclang/core/impl/__jac_gen__/arch_impl.py +24 -0
  18. jaclang-0.0.8/jaclang/core/impl/__jac_gen__/element_impl.py +26 -0
  19. jaclang-0.0.8/jaclang/core/impl/__jac_gen__/exec_ctx_impl.py +12 -0
  20. jaclang-0.0.8/jaclang/core/impl/__jac_gen__/memory_impl.py +14 -0
  21. {jaclang-0.0.5 → jaclang-0.0.8}/jaclang/core/impl/element_impl.jac +3 -3
  22. {jaclang-0.0.5 → jaclang-0.0.8}/jaclang/core/impl/exec_ctx_impl.jac +3 -6
  23. {jaclang-0.0.5 → jaclang-0.0.8}/jaclang/core/primitives.jac +4 -3
  24. {jaclang-0.0.5 → jaclang-0.0.8}/jaclang/jac/absyntree.py +555 -180
  25. {jaclang-0.0.5 → jaclang-0.0.8}/jaclang/jac/constant.py +6 -0
  26. jaclang-0.0.8/jaclang/jac/importer.py +108 -0
  27. jaclang-0.0.8/jaclang/jac/langserve.py +26 -0
  28. {jaclang-0.0.5 → jaclang-0.0.8}/jaclang/jac/lexer.py +35 -3
  29. {jaclang-0.0.5 → jaclang-0.0.8}/jaclang/jac/parser.py +146 -115
  30. {jaclang-0.0.5 → jaclang-0.0.8}/jaclang/jac/passes/blue/__init__.py +8 -3
  31. {jaclang-0.0.5 → jaclang-0.0.8}/jaclang/jac/passes/blue/ast_build_pass.py +454 -305
  32. {jaclang-0.0.5 → jaclang-0.0.8}/jaclang/jac/passes/blue/blue_pygen_pass.py +112 -74
  33. jaclang-0.0.8/jaclang/jac/passes/blue/decl_def_match_pass.py +63 -0
  34. {jaclang-0.0.5 → jaclang-0.0.8}/jaclang/jac/passes/blue/import_pass.py +1 -1
  35. jaclang-0.0.8/jaclang/jac/passes/blue/pyout_pass.py +74 -0
  36. jaclang-0.0.8/jaclang/jac/passes/blue/semantic_check_pass.py +37 -0
  37. jaclang-0.0.8/jaclang/jac/passes/blue/sym_tab_build_pass.py +1045 -0
  38. {jaclang-0.0.5 → jaclang-0.0.8}/jaclang/jac/passes/blue/tests/test_ast_build_pass.py +2 -2
  39. {jaclang-0.0.5 → jaclang-0.0.8}/jaclang/jac/passes/blue/tests/test_blue_pygen_pass.py +9 -28
  40. jaclang-0.0.8/jaclang/jac/passes/blue/tests/test_decl_def_match_pass.py +45 -0
  41. jaclang-0.0.8/jaclang/jac/passes/blue/tests/test_sym_tab_build_pass.py +22 -0
  42. {jaclang-0.0.5 → jaclang-0.0.8}/jaclang/jac/passes/ir_pass.py +8 -6
  43. jaclang-0.0.8/jaclang/jac/passes/purple/__jac_gen__/__init__.py +0 -0
  44. jaclang-0.0.8/jaclang/jac/passes/purple/__jac_gen__/analyze_pass.py +37 -0
  45. jaclang-0.0.8/jaclang/jac/passes/purple/__jac_gen__/purple_pygen_pass.py +305 -0
  46. jaclang-0.0.8/jaclang/jac/passes/purple/impl/__jac_gen__/__init__.py +0 -0
  47. jaclang-0.0.8/jaclang/jac/passes/purple/impl/__jac_gen__/purple_pygen_pass_impl.py +23 -0
  48. {jaclang-0.0.5 → jaclang-0.0.8}/jaclang/jac/passes/purple/impl/purple_pygen_pass_impl.jac +2 -5
  49. jaclang-0.0.8/jaclang/jac/symtable.py +154 -0
  50. jaclang-0.0.8/jaclang/jac/tests/fixtures/__jac_gen__/__init__.py +0 -0
  51. jaclang-0.0.8/jaclang/jac/tests/fixtures/__jac_gen__/hello_world.py +16 -0
  52. {jaclang-0.0.5 → jaclang-0.0.8}/jaclang/jac/tests/fixtures/fam.jac +7 -8
  53. jaclang-0.0.8/jaclang/jac/tests/fixtures/mod_doc_test.jac +1 -0
  54. {jaclang-0.0.5 → jaclang-0.0.8}/jaclang/jac/tests/test_parser.py +8 -0
  55. {jaclang-0.0.5 → jaclang-0.0.8}/jaclang/jac/transform.py +41 -14
  56. {jaclang-0.0.5 → jaclang-0.0.8}/jaclang/jac/transpiler.py +18 -9
  57. {jaclang-0.0.5 → jaclang-0.0.8}/jaclang/utils/fstring_parser.py +2 -2
  58. {jaclang-0.0.5 → jaclang-0.0.8}/jaclang/utils/helpers.py +41 -0
  59. {jaclang-0.0.5 → jaclang-0.0.8}/jaclang/utils/lang_tools.py +12 -2
  60. {jaclang-0.0.5 → jaclang-0.0.8}/jaclang/utils/test.py +41 -0
  61. jaclang-0.0.8/jaclang/vendor/__init__.py +1 -0
  62. jaclang-0.0.8/jaclang/vendor/pygls/__init__.py +25 -0
  63. jaclang-0.0.8/jaclang/vendor/pygls/capabilities.py +502 -0
  64. jaclang-0.0.8/jaclang/vendor/pygls/client.py +176 -0
  65. jaclang-0.0.8/jaclang/vendor/pygls/constants.py +26 -0
  66. jaclang-0.0.8/jaclang/vendor/pygls/exceptions.py +220 -0
  67. jaclang-0.0.8/jaclang/vendor/pygls/feature_manager.py +241 -0
  68. jaclang-0.0.8/jaclang/vendor/pygls/lsp/__init__.py +139 -0
  69. jaclang-0.0.8/jaclang/vendor/pygls/lsp/client.py +2224 -0
  70. jaclang-0.0.8/jaclang/vendor/pygls/lsprotocol/__init__.py +2 -0
  71. jaclang-0.0.8/jaclang/vendor/pygls/lsprotocol/_hooks.py +1233 -0
  72. jaclang-0.0.8/jaclang/vendor/pygls/lsprotocol/converters.py +17 -0
  73. jaclang-0.0.8/jaclang/vendor/pygls/lsprotocol/types.py +12820 -0
  74. jaclang-0.0.8/jaclang/vendor/pygls/lsprotocol/validators.py +47 -0
  75. jaclang-0.0.8/jaclang/vendor/pygls/progress.py +79 -0
  76. jaclang-0.0.8/jaclang/vendor/pygls/protocol.py +1184 -0
  77. jaclang-0.0.8/jaclang/vendor/pygls/server.py +620 -0
  78. jaclang-0.0.8/jaclang/vendor/pygls/uris.py +184 -0
  79. jaclang-0.0.8/jaclang/vendor/pygls/workspace/__init__.py +81 -0
  80. jaclang-0.0.8/jaclang/vendor/pygls/workspace/position.py +204 -0
  81. jaclang-0.0.8/jaclang/vendor/pygls/workspace/text_document.py +234 -0
  82. jaclang-0.0.8/jaclang/vendor/pygls/workspace/workspace.py +311 -0
  83. {jaclang-0.0.5 → jaclang-0.0.8}/jaclang.egg-info/PKG-INFO +1 -1
  84. {jaclang-0.0.5 → jaclang-0.0.8}/jaclang.egg-info/SOURCES.txt +54 -9
  85. {jaclang-0.0.5 → jaclang-0.0.8}/setup.py +1 -1
  86. jaclang-0.0.5/README.md +0 -16
  87. jaclang-0.0.5/jaclang/__init__.py +0 -4
  88. jaclang-0.0.5/jaclang/core/jaclang.jac +0 -62
  89. jaclang-0.0.5/jaclang/jac/importer.py +0 -130
  90. jaclang-0.0.5/jaclang/jac/passes/blue/decl_def_match_pass.py +0 -291
  91. jaclang-0.0.5/jaclang/jac/passes/blue/tests/test_decl_def_match_pass.py +0 -54
  92. jaclang-0.0.5/jaclang/jac/passes/blue/tests/test_type_analyze_pass.py +0 -53
  93. jaclang-0.0.5/jaclang/jac/passes/blue/type_analyze_pass.py +0 -728
  94. jaclang-0.0.5/jaclang/jac/sym_table.py +0 -127
  95. {jaclang-0.0.5 → jaclang-0.0.8}/jaclang/cli/__init__.py +0 -0
  96. {jaclang-0.0.5 → jaclang-0.0.8}/jaclang/cli/impl/__init__.py +0 -0
  97. {jaclang-0.0.5 → jaclang-0.0.8}/jaclang/core/__init__.py +0 -0
  98. {jaclang-0.0.5 → jaclang-0.0.8}/jaclang/core/impl/__init__.py +0 -0
  99. {jaclang-0.0.5 → jaclang-0.0.8}/jaclang/core/impl/arch_impl.jac +0 -0
  100. {jaclang-0.0.5 → jaclang-0.0.8}/jaclang/core/impl/memory_impl.jac +0 -0
  101. {jaclang-0.0.5 → jaclang-0.0.8}/jaclang/jac/__init__.py +0 -0
  102. {jaclang-0.0.5 → jaclang-0.0.8}/jaclang/jac/passes/__init__.py +0 -0
  103. {jaclang-0.0.5 → jaclang-0.0.8}/jaclang/jac/passes/blue/sub_node_tab_pass.py +0 -0
  104. {jaclang-0.0.5 → jaclang-0.0.8}/jaclang/jac/passes/blue/tests/__init__.py +0 -0
  105. {jaclang-0.0.5 → jaclang-0.0.8}/jaclang/jac/passes/blue/tests/test_import_pass.py +0 -0
  106. {jaclang-0.0.5 → jaclang-0.0.8}/jaclang/jac/passes/blue/tests/test_sub_node_pass.py +0 -0
  107. {jaclang-0.0.5 → jaclang-0.0.8}/jaclang/jac/passes/purple/__init__.py +0 -0
  108. {jaclang-0.0.5 → jaclang-0.0.8}/jaclang/jac/passes/purple/analyze_pass.jac +0 -0
  109. {jaclang-0.0.5 → jaclang-0.0.8}/jaclang/jac/passes/purple/impl/__init__.py +0 -0
  110. {jaclang-0.0.5 → jaclang-0.0.8}/jaclang/jac/passes/purple/purple_pygen_pass.jac +0 -0
  111. {jaclang-0.0.5 → jaclang-0.0.8}/jaclang/jac/tests/__init__.py +0 -0
  112. {jaclang-0.0.5 → jaclang-0.0.8}/jaclang/jac/tests/fixtures/__init__.py +0 -0
  113. {jaclang-0.0.5 → jaclang-0.0.8}/jaclang/jac/tests/fixtures/activity.py +0 -0
  114. {jaclang-0.0.5 → jaclang-0.0.8}/jaclang/jac/tests/fixtures/hello_world.jac +0 -0
  115. {jaclang-0.0.5 → jaclang-0.0.8}/jaclang/jac/tests/fixtures/kwesc.jac +0 -0
  116. {jaclang-0.0.5 → jaclang-0.0.8}/jaclang/jac/tests/fixtures/lexer_fam.jac +0 -0
  117. {jaclang-0.0.5 → jaclang-0.0.8}/jaclang/jac/tests/fixtures/stuff.jac +0 -0
  118. {jaclang-0.0.5 → jaclang-0.0.8}/jaclang/jac/tests/test_importer.py +0 -0
  119. {jaclang-0.0.5 → jaclang-0.0.8}/jaclang/jac/tests/test_lexer.py +0 -0
  120. {jaclang-0.0.5 → jaclang-0.0.8}/jaclang/utils/__init__.py +0 -0
  121. {jaclang-0.0.5 → jaclang-0.0.8}/jaclang/utils/log.py +0 -0
  122. {jaclang-0.0.5 → jaclang-0.0.8}/jaclang/utils/tests/__init__.py +0 -0
  123. {jaclang-0.0.5 → jaclang-0.0.8}/jaclang/utils/tests/test_fstring_parser.py +0 -0
  124. {jaclang-0.0.5/jaclang/utils → jaclang-0.0.8/jaclang/vendor}/sly/__init__.py +0 -0
  125. {jaclang-0.0.5/jaclang/utils → jaclang-0.0.8/jaclang/vendor}/sly/docparse.py +0 -0
  126. {jaclang-0.0.5/jaclang/utils → jaclang-0.0.8/jaclang/vendor}/sly/lex.py +0 -0
  127. {jaclang-0.0.5/jaclang/utils → jaclang-0.0.8/jaclang/vendor}/sly/yacc.py +0 -0
  128. {jaclang-0.0.5 → jaclang-0.0.8}/jaclang.egg-info/dependency_links.txt +0 -0
  129. {jaclang-0.0.5 → jaclang-0.0.8}/jaclang.egg-info/entry_points.txt +0 -0
  130. {jaclang-0.0.5 → jaclang-0.0.8}/jaclang.egg-info/top_level.txt +0 -0
  131. {jaclang-0.0.5 → jaclang-0.0.8}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: jaclang
3
- Version: 0.0.5
3
+ Version: 0.0.8
4
4
  Home-page: https://github.com/Jaseci-Labs/jaclang
5
5
  Author: Jason Mars
6
6
  Author-email: jason@jaseci.org
@@ -0,0 +1,197 @@
1
+ # Getting Started with the Jac Programming Language
2
+
3
+ Welcome to JacLang, a unique and powerful programming language that runs on top of Python. To get you started, this guide will walk you through the process of installation, running Jac files, and importing Jac into existing Python modules.
4
+
5
+ ## Installation
6
+
7
+ Firstly, you'll need to install JacLang. You can do this easily through Python's package manager, pip. Run the following command:
8
+
9
+ ```bash
10
+ pip install jaclang
11
+ ```
12
+
13
+ And from source simply use,
14
+
15
+ ```bash
16
+ pip install -e .
17
+ ```
18
+
19
+ Upon successful installation, you'll have a script named `jac` at your disposal. This script is used to load and run `.jac` files.
20
+
21
+ ## Running Jac Files
22
+
23
+ Here's how you can use `jac`:
24
+
25
+ - To simply load a sample Jac module and exit, run:
26
+ ```bash
27
+ jac load -f sample.jac
28
+ ```
29
+
30
+ - To load a sample Jac module and execute a particular function (considered the entrypoint for execution in Jac), run:
31
+ ```bash
32
+ jac run -f sample.jac -e my_func
33
+ ```
34
+
35
+ Now Try it with this example jac program with both load and calling `test_run`
36
+
37
+ ```jac
38
+ """Example of simple walker walking nodes."""
39
+
40
+ node item {
41
+ has value: int;
42
+ }
43
+
44
+ walker Creator {
45
+ has count: int = 0;
46
+ can create with <root>|:n:item entry {
47
+ <here> ++> spawn :n:item;
48
+ <self>.count += 1;
49
+ if <self>.count < 10 {
50
+ visit -->;
51
+ }
52
+ }
53
+ }
54
+
55
+ walker Walk {
56
+ has count: int = 0;
57
+ can skip_root with <root> entry { visit -->; }
58
+ can step with :n:item entry {
59
+ <here>.value = <self>.count;
60
+ <self>.count += 1;
61
+ visit --> else {
62
+ f"Final Value: {<here>.value-1}" |> print;
63
+ "Done walking." |> print;
64
+ disengage;
65
+ }
66
+ f"Value: {<here>.value-1}" |> print;
67
+ }
68
+ }
69
+
70
+ can test_run {
71
+ spawn :w:Creator |> <root>;
72
+ spawn :w:Walk |> <root>;
73
+ }
74
+
75
+ with entry {
76
+ |> test_run;
77
+ }
78
+ ```
79
+
80
+ ## Integrating Jac into Python Modules
81
+
82
+ JacLang also provides a seamless way to import Jac into existing Python modules through library functions. Here's an example:
83
+
84
+ ```python
85
+ """CLI for jaclang."""
86
+ from jaclang import jac_purple_import as jac_import
87
+
88
+ cli = jac_import("cli")
89
+ cmds = jac_import("cmds")
90
+
91
+ cli.cmd_registry = cmds.cmd_reg # type: ignore
92
+ ```
93
+
94
+ In the above code snippet, `cli` and `cmds` are modules that are imported similar to how you'd typically import modules in Python, i.e., `import cli` or `import cmds`.
95
+
96
+ Below is a sample `cli.jac` file to provide some insight into how Jac code looks:
97
+
98
+ ```jac
99
+ """
100
+ This is the implementation of the command line interface tool for the
101
+ Jac language. It's built with the Jac language via bootstraping and
102
+ represents the first such complete Jac program.
103
+ """
104
+
105
+ import:py inspect;
106
+ import:py argparse;
107
+ import:py cmd;
108
+ include:jac impl.cli_impl;
109
+
110
+ object Command {
111
+ has func: callable,
112
+ sig: inspect.Signature;
113
+
114
+ can:private init(func: callable);
115
+ can call(*args: list, **kwargs: dict);
116
+ }
117
+
118
+
119
+ object CommandRegistry {
120
+ has:private registry: dict[str, Command],
121
+ sub_parsers: argparse._SubParsersActionp;
122
+ has:public parser: argparse.ArgumentParser;
123
+
124
+ can init;
125
+ can register(func: callable);
126
+ can get(name: str) -> Command;
127
+ can items -> dict[str, Command];
128
+ }
129
+
130
+
131
+ object CommandShell:cmd.Cmd {
132
+ static has intro: str = "Welcome to the Jac CLI!",
133
+ prompt: str = "jac> ";
134
+ has cmd_reg: CommandRegistry;
135
+
136
+ can init (cmd_reg: CommandRegistry);
137
+ can do_exit(arg: list) -> bool;
138
+ can default(line: str);
139
+ }
140
+
141
+ global cmd_registry = |> CommandRegistry;
142
+ can start_cli;
143
+ ```
144
+
145
+ That's all you need to get started with JacLang. As you delve into this new language, you'll discover how it beautifully combines the power of Python with a modern and intuitive syntax. Happy coding!
146
+
147
+ ## Installing JacLang Extension in Visual Studio Code (VSCode)
148
+
149
+ In addition to setting up JacLang itself, you may also want to take advantage of the JacLang language extension for Visual Studio Code (VSCode). This will give you enhanced code highlighting, autocomplete, and other useful language features within your VSCode environment.
150
+
151
+ Here's a step-by-step guide on how to package and install the JacLang VSCode extension.
152
+
153
+ ### Setting Up VSCE
154
+
155
+ To create the VSIX file for the extension, you'll need `vsce`, a command-line tool for packaging VSCode extensions. If you don't have it installed already, follow these steps:
156
+
157
+ 1. Ensure that you have Node.js (>= 0.10.x) and npm installed on your machine.
158
+
159
+ 2. Open a terminal (or command prompt) and install `vsce` globally by running the following command:
160
+
161
+ ```bash
162
+ npm install -g vsce
163
+ ```
164
+
165
+ ### Packaging the Extension
166
+
167
+ Once you have `vsce` set up, navigate to the JacLang extension directory in your local JacLang repository by running:
168
+
169
+ ```bash
170
+ cd /path/to/repo/jaclang/support/vscode_ext/jac
171
+ ```
172
+
173
+ In the `jac` directory, package the extension into a VSIX file by running:
174
+
175
+ ```bash
176
+ vsce package
177
+ ```
178
+
179
+ This will create a `.vsix` file, which is the packaged extension.
180
+
181
+ ### Installing the VSIX File in VSCode
182
+
183
+ To install the packaged JacLang extension in VSCode:
184
+
185
+ 1. Open Visual Studio Code.
186
+
187
+ 2. Click on the Extensions view icon on the Sidebar (or press `Ctrl+Shift+X`).
188
+
189
+ 3. Click on the three-dot menu (`...`) in the top-right corner of the Extensions view.
190
+
191
+ 4. Select `Install from VSIX...` from the dropdown menu.
192
+
193
+ 5. In the file picker, find and select the `.vsix` file you created earlier and click `Open`.
194
+
195
+ 6. After a brief moment, the extension will be installed. You might have to reload VSCode for the changes to take effect.
196
+
197
+ Now, you're all set to use the JacLang language extension in your VSCode editor! Enjoy your enhanced JacLang development experience.
@@ -0,0 +1,5 @@
1
+ """The Jac Programming Language."""
2
+ from jaclang.jac.importer import jac_blue_import, jac_purple_import
3
+ from jaclang.utils.helpers import handle_jac_error
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 """
@@ -14,7 +14,7 @@ object Command {
14
14
  has func: callable,
15
15
  sig: inspect.Signature;
16
16
 
17
- can:private <init>(func: callable);
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>(cmd_reg: CommandRegistry);
39
+ can <init>;
40
40
  can do_exit(arg: list) -> bool;
41
41
  can default(line: str);
42
42
  }
@@ -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 load(filename: str);
11
+ can run(filename: str);
12
12
 
13
13
  @cmd_reg.register
14
- can run(filename: str, entrypoint: str, args: list);
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 """
@@ -1,6 +1,6 @@
1
1
  """Implemenation for Jac's command line interface."""
2
2
 
3
- :o:Command:a:<init>(func: callable) {
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
- (f"-{param_name[:1]}", f"--{param_name}",
31
- required=True, type=param.annotation|>eval)
32
- |> cmd_parser.add_argument;
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
- (f"-{param_name[:1]}", f"--{param_name}",
36
- default=param.default, type=param.annotation|>eval)
37
- |> cmd_parser.add_argument;
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>(cmd_reg: CommandRegistry) {
69
+ :o:CommandShell:a:<init> {
53
70
  <s>.cmd_reg = cmd_reg;
54
71
  <s> |> cmd.Cmd.<init>;
55
72
  }