jaclang 0.7.2__py3-none-any.whl → 0.7.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/cli/cli.py +2 -2
- jaclang/compiler/__init__.py +11 -12
- jaclang/compiler/absyntree.py +499 -294
- jaclang/compiler/codeloc.py +2 -2
- jaclang/compiler/constant.py +100 -2
- jaclang/compiler/jac.lark +27 -19
- jaclang/compiler/parser.py +119 -92
- jaclang/compiler/passes/main/access_modifier_pass.py +20 -12
- jaclang/compiler/passes/main/def_impl_match_pass.py +28 -14
- jaclang/compiler/passes/main/def_use_pass.py +59 -40
- jaclang/compiler/passes/main/fuse_typeinfo_pass.py +65 -43
- jaclang/compiler/passes/main/import_pass.py +8 -6
- jaclang/compiler/passes/main/pyast_gen_pass.py +97 -42
- jaclang/compiler/passes/main/pyast_load_pass.py +47 -12
- jaclang/compiler/passes/main/pyjac_ast_link_pass.py +19 -10
- jaclang/compiler/passes/main/registry_pass.py +6 -6
- jaclang/compiler/passes/main/sub_node_tab_pass.py +0 -5
- jaclang/compiler/passes/main/sym_tab_build_pass.py +43 -235
- jaclang/compiler/passes/main/tests/test_decl_def_match_pass.py +21 -4
- jaclang/compiler/passes/main/tests/test_def_use_pass.py +5 -10
- jaclang/compiler/passes/main/type_check_pass.py +2 -1
- jaclang/compiler/passes/tool/jac_formatter_pass.py +30 -9
- jaclang/compiler/passes/tool/tests/fixtures/corelib.jac +16 -0
- jaclang/compiler/passes/tool/tests/fixtures/corelib_fmt.jac +16 -0
- jaclang/compiler/passes/tool/tests/fixtures/genai/essay_review.jac +1 -1
- jaclang/compiler/passes/tool/tests/fixtures/genai/expert_answer.jac +1 -1
- jaclang/compiler/passes/tool/tests/fixtures/genai/joke_gen.jac +1 -1
- jaclang/compiler/passes/tool/tests/fixtures/genai/odd_word_out.jac +1 -1
- jaclang/compiler/passes/tool/tests/fixtures/genai/personality_finder.jac +1 -1
- jaclang/compiler/passes/tool/tests/fixtures/genai/text_to_type.jac +1 -1
- jaclang/compiler/passes/tool/tests/fixtures/genai/translator.jac +1 -1
- jaclang/compiler/passes/tool/tests/fixtures/genai/wikipedia.jac +1 -1
- jaclang/compiler/passes/transform.py +2 -4
- jaclang/compiler/passes/utils/mypy_ast_build.py +1 -8
- jaclang/{core/registry.py → compiler/semtable.py} +1 -3
- jaclang/compiler/symtable.py +142 -101
- jaclang/compiler/tests/test_parser.py +2 -2
- jaclang/core/{construct.py → architype.py} +25 -240
- jaclang/core/constructs.py +44 -0
- jaclang/core/context.py +157 -0
- jaclang/core/importer.py +18 -9
- jaclang/core/memory.py +99 -0
- jaclang/core/test.py +90 -0
- jaclang/core/utils.py +2 -2
- jaclang/langserve/engine.py +127 -50
- jaclang/langserve/server.py +34 -61
- jaclang/langserve/tests/fixtures/base_module_structure.jac +28 -0
- jaclang/langserve/tests/fixtures/circle.jac +16 -12
- jaclang/langserve/tests/fixtures/circle_err.jac +3 -3
- jaclang/langserve/tests/fixtures/circle_pure.test.jac +15 -0
- jaclang/langserve/tests/fixtures/import_include_statements.jac +6 -0
- jaclang/langserve/tests/fixtures/py_import.py +26 -0
- jaclang/langserve/tests/test_server.py +93 -18
- jaclang/langserve/utils.py +124 -10
- jaclang/plugin/builtin.py +1 -1
- jaclang/plugin/default.py +25 -77
- jaclang/plugin/feature.py +25 -7
- jaclang/plugin/spec.py +18 -20
- jaclang/settings.py +3 -0
- jaclang/tests/fixtures/abc.jac +16 -12
- jaclang/tests/fixtures/aott_raise.jac +1 -1
- jaclang/tests/fixtures/byllmissue.jac +9 -0
- jaclang/tests/fixtures/edgetypeissue.jac +10 -0
- jaclang/tests/fixtures/hello.jac +1 -1
- jaclang/tests/fixtures/impl_match_confused.impl.jac +1 -0
- jaclang/tests/fixtures/impl_match_confused.jac +5 -0
- jaclang/tests/fixtures/maxfail_run_test.jac +17 -5
- jaclang/tests/fixtures/run_test.jac +17 -5
- jaclang/tests/test_bugs.py +19 -0
- jaclang/tests/test_cli.py +1 -1
- jaclang/tests/test_language.py +65 -100
- jaclang/tests/test_reference.py +1 -1
- jaclang/utils/lang_tools.py +5 -4
- jaclang/utils/test.py +2 -1
- jaclang/utils/treeprinter.py +22 -8
- {jaclang-0.7.2.dist-info → jaclang-0.7.8.dist-info}/METADATA +1 -1
- {jaclang-0.7.2.dist-info → jaclang-0.7.8.dist-info}/RECORD +79 -83
- jaclang/core/aott.py +0 -310
- jaclang/core/llms/__init__.py +0 -20
- jaclang/core/llms/anthropic.py +0 -90
- jaclang/core/llms/base.py +0 -206
- jaclang/core/llms/groq.py +0 -70
- jaclang/core/llms/huggingface.py +0 -76
- jaclang/core/llms/ollama.py +0 -81
- jaclang/core/llms/openai.py +0 -65
- jaclang/core/llms/togetherai.py +0 -63
- jaclang/core/llms/utils.py +0 -9
- jaclang/tests/fixtures/math_question.jpg +0 -0
- jaclang/tests/fixtures/with_llm_function.jac +0 -33
- jaclang/tests/fixtures/with_llm_lower.jac +0 -45
- jaclang/tests/fixtures/with_llm_method.jac +0 -51
- jaclang/tests/fixtures/with_llm_type.jac +0 -52
- jaclang/tests/fixtures/with_llm_vision.jac +0 -25
- {jaclang-0.7.2.dist-info → jaclang-0.7.8.dist-info}/WHEEL +0 -0
- {jaclang-0.7.2.dist-info → jaclang-0.7.8.dist-info}/entry_points.txt +0 -0
jaclang/compiler/codeloc.py
CHANGED
|
@@ -55,7 +55,7 @@ class CodeLocInfo:
|
|
|
55
55
|
@property
|
|
56
56
|
def last_line(self) -> int:
|
|
57
57
|
"""Get line number."""
|
|
58
|
-
return self.last_tok.
|
|
58
|
+
return self.last_tok.end_line
|
|
59
59
|
|
|
60
60
|
@property
|
|
61
61
|
def col_start(self) -> int:
|
|
@@ -107,4 +107,4 @@ class CodeLocInfo:
|
|
|
107
107
|
|
|
108
108
|
def __str__(self) -> str:
|
|
109
109
|
"""Stringify."""
|
|
110
|
-
return f"{self.
|
|
110
|
+
return f"{self.first_line}:{self.col_start} - {self.last_line}:{self.col_end}"
|
jaclang/compiler/constant.py
CHANGED
|
@@ -1,9 +1,93 @@
|
|
|
1
1
|
"""Constants across the project."""
|
|
2
2
|
|
|
3
|
-
from enum import Enum
|
|
3
|
+
from enum import Enum, IntEnum, IntFlag, StrEnum
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
class
|
|
6
|
+
class SymbolType(Enum):
|
|
7
|
+
"""Symbol types."""
|
|
8
|
+
|
|
9
|
+
MODULE = "module" # LSP: Module
|
|
10
|
+
MOD_VAR = "mod_var" # LSP: Variable
|
|
11
|
+
VAR = "variable" # LSP: Variable
|
|
12
|
+
IMM_VAR = "immutable" # LSP: Constant
|
|
13
|
+
ABILITY = "ability" # LSP: Function
|
|
14
|
+
OBJECT_ARCH = "object" # LSP: Class
|
|
15
|
+
NODE_ARCH = "node" # LSP: Class
|
|
16
|
+
EDGE_ARCH = "edge" # LSP: Class
|
|
17
|
+
WALKER_ARCH = "walker" # LSP: Class
|
|
18
|
+
ENUM_ARCH = "enum" # LSP: Enum
|
|
19
|
+
TEST = "test" # LSP: Function
|
|
20
|
+
TYPE = "type" # LSP: TypeParameter
|
|
21
|
+
IMPL = "impl" # LSP: Interface or Property
|
|
22
|
+
HAS_VAR = "field" # LSP: Field
|
|
23
|
+
METHOD = "method" # LSP: Method
|
|
24
|
+
CONSTRUCTOR = "constructor" # LSP: Constructor
|
|
25
|
+
ENUM_MEMBER = "enum_member" # LSP: EnumMember
|
|
26
|
+
NUMBER = "number" # LSP: Number
|
|
27
|
+
STRING = "string" # LSP: String
|
|
28
|
+
BOOL = "bool" # LSP: Boolean
|
|
29
|
+
SEQUENCE = "sequence" # LSP: Array
|
|
30
|
+
NULL = "null" # LSP: Null
|
|
31
|
+
UNKNOWN = "unknown" # LSP: Unknown
|
|
32
|
+
|
|
33
|
+
def __str__(self) -> str:
|
|
34
|
+
"""Stringify."""
|
|
35
|
+
return self.value
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class JacSemTokenType(IntEnum):
|
|
39
|
+
"""LSP Token types for Jac."""
|
|
40
|
+
|
|
41
|
+
NAMESPACE = 0
|
|
42
|
+
TYPE = 1
|
|
43
|
+
CLASS = 2
|
|
44
|
+
ENUM = 3
|
|
45
|
+
INTERFACE = 4
|
|
46
|
+
STRUCT = 5
|
|
47
|
+
TYPE_PARAMETER = 6
|
|
48
|
+
PARAMETER = 7
|
|
49
|
+
VARIABLE = 8
|
|
50
|
+
PROPERTY = 9
|
|
51
|
+
ENUM_MEMBER = 10
|
|
52
|
+
EVENT = 11
|
|
53
|
+
FUNCTION = 12
|
|
54
|
+
METHOD = 13
|
|
55
|
+
MACRO = 14
|
|
56
|
+
KEYWORD = 15
|
|
57
|
+
MODIFIER = 16
|
|
58
|
+
COMMENT = 17
|
|
59
|
+
STRING = 18
|
|
60
|
+
NUMBER = 19
|
|
61
|
+
REGEXP = 20
|
|
62
|
+
OPERATOR = 21
|
|
63
|
+
|
|
64
|
+
@staticmethod
|
|
65
|
+
def as_str_list() -> list[str]:
|
|
66
|
+
"""Return the string representation of the token."""
|
|
67
|
+
return [i.name.lower() for i in JacSemTokenType]
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
class JacSemTokenModifier(IntFlag):
|
|
71
|
+
"""LSP Token modifiers for Jac."""
|
|
72
|
+
|
|
73
|
+
DECLARATION = 1 << 0
|
|
74
|
+
DEFINITION = 1 << 1
|
|
75
|
+
READONLY = 1 << 2
|
|
76
|
+
STATIC = 1 << 3
|
|
77
|
+
DEPRECATED = 1 << 4
|
|
78
|
+
ABSTRACT = 1 << 5
|
|
79
|
+
ASYNC = 1 << 6
|
|
80
|
+
MODIFICATION = 1 << 7
|
|
81
|
+
DOCUMENTATION = 1 << 8
|
|
82
|
+
DEFAULT_LIBRARY = 1 << 9
|
|
83
|
+
|
|
84
|
+
@staticmethod
|
|
85
|
+
def as_str_list() -> list[str]:
|
|
86
|
+
"""Return the string representation of the token."""
|
|
87
|
+
return [i.name.lower() for i in JacSemTokenModifier if i.name]
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
class Constants(StrEnum):
|
|
7
91
|
"""Token constants for Jac."""
|
|
8
92
|
|
|
9
93
|
JAC_LANG_IMP = "jac"
|
|
@@ -28,6 +112,7 @@ class Constants(str, Enum):
|
|
|
28
112
|
|
|
29
113
|
PYNLINE = "::py::"
|
|
30
114
|
JAC_GEN_DIR = "__jac_gen__"
|
|
115
|
+
JAC_MYPY_CACHE = ".jac_mypy_cache"
|
|
31
116
|
|
|
32
117
|
def __str__(self) -> str:
|
|
33
118
|
"""Return the string representation of the token."""
|
|
@@ -48,6 +133,18 @@ class Values(int, Enum):
|
|
|
48
133
|
JAC_ERROR_LINE_RANGE = 3
|
|
49
134
|
|
|
50
135
|
|
|
136
|
+
class SymbolAccess(Enum):
|
|
137
|
+
"""Symbol types."""
|
|
138
|
+
|
|
139
|
+
PRIVATE = "private"
|
|
140
|
+
PUBLIC = "public"
|
|
141
|
+
PROTECTED = "protected"
|
|
142
|
+
|
|
143
|
+
def __str__(self) -> str:
|
|
144
|
+
"""Stringify."""
|
|
145
|
+
return self.value
|
|
146
|
+
|
|
147
|
+
|
|
51
148
|
# Done like this for type checker
|
|
52
149
|
# validated synced with test
|
|
53
150
|
class Tokens(str, Enum):
|
|
@@ -99,6 +196,7 @@ class Tokens(str, Enum):
|
|
|
99
196
|
KW_AWAIT = "KW_AWAIT"
|
|
100
197
|
KW_TEST = "KW_TEST"
|
|
101
198
|
KW_ASSERT = "KW_ASSERT"
|
|
199
|
+
KW_CHECK = "KW_CHECK"
|
|
102
200
|
COLON = "COLON"
|
|
103
201
|
PIPE_FWD = "PIPE_FWD"
|
|
104
202
|
PIPE_BKWD = "PIPE_BKWD"
|
jaclang/compiler/jac.lark
CHANGED
|
@@ -30,7 +30,10 @@ sub_name: COLON NAME
|
|
|
30
30
|
include_stmt: KW_INCLUDE sub_name import_path SEMI
|
|
31
31
|
|
|
32
32
|
// Architypes
|
|
33
|
-
architype: decorators?
|
|
33
|
+
architype: decorators? architype_decl
|
|
34
|
+
| architype_def
|
|
35
|
+
| enum
|
|
36
|
+
|
|
34
37
|
architype_decl: arch_type access_tag? STRING? NAME inherited_archs? (member_block | SEMI)
|
|
35
38
|
architype_def: abil_to_arch_chain member_block
|
|
36
39
|
decorators: (DECOR_OP atomic_chain)+
|
|
@@ -54,8 +57,8 @@ typed_has_clause: named_ref (COLON STRING)? type_tag (EQ expression | KW_BY KW_P
|
|
|
54
57
|
type_tag: COLON expression
|
|
55
58
|
|
|
56
59
|
// Enumerations
|
|
57
|
-
enum:
|
|
58
|
-
|
|
|
60
|
+
enum: decorators? enum_decl
|
|
61
|
+
| enum_def
|
|
59
62
|
|
|
60
63
|
enum_decl: KW_ENUM access_tag? STRING? NAME inherited_archs? (enum_block | SEMI)
|
|
61
64
|
enum_def: arch_to_enum_chain enum_block
|
|
@@ -64,16 +67,19 @@ enum_block: LBRACE ((enum_stmt COMMA)* enum_stmt)? RBRACE
|
|
|
64
67
|
enum_stmt: NAME (COLON STRING)? EQ expression
|
|
65
68
|
| NAME (COLON STRING)?
|
|
66
69
|
| py_code_block
|
|
70
|
+
| free_code
|
|
71
|
+
| abstract_ability
|
|
72
|
+
| ability
|
|
67
73
|
|
|
68
74
|
// Abilities
|
|
69
|
-
ability: decorators?
|
|
70
|
-
| decorators? KW_ASYNC? ability_decl
|
|
75
|
+
ability: decorators? KW_ASYNC? ability_decl
|
|
71
76
|
| decorators? genai_ability
|
|
77
|
+
| ability_def
|
|
72
78
|
|
|
73
|
-
ability_decl: KW_OVERRIDE? KW_STATIC? KW_CAN access_tag? STRING?
|
|
79
|
+
ability_decl: KW_OVERRIDE? KW_STATIC? KW_CAN access_tag? STRING? named_ref (func_decl | event_clause) (code_block | SEMI)
|
|
74
80
|
ability_def: arch_to_abil_chain (func_decl | event_clause) code_block
|
|
75
|
-
abstract_ability: KW_OVERRIDE? KW_STATIC? KW_CAN access_tag? STRING?
|
|
76
|
-
genai_ability: KW_OVERRIDE? KW_STATIC? KW_CAN access_tag? STRING?
|
|
81
|
+
abstract_ability: KW_OVERRIDE? KW_STATIC? KW_CAN access_tag? STRING? named_ref (func_decl | event_clause) KW_ABSTRACT SEMI
|
|
82
|
+
genai_ability: KW_OVERRIDE? KW_STATIC? KW_CAN access_tag? STRING? named_ref (func_decl) KW_BY atomic_call SEMI
|
|
77
83
|
event_clause: KW_WITH expression? (KW_EXIT | KW_ENTRY) (STRING? RETURN_HINT expression)?
|
|
78
84
|
func_decl: (LPAREN func_decl_params? RPAREN)? (RETURN_HINT (STRING COLON)? expression)?
|
|
79
85
|
func_decl_params: (param_var COMMA)* param_var
|
|
@@ -128,9 +134,10 @@ statement: import_stmt
|
|
|
128
134
|
| nonlocal_ref SEMI
|
|
129
135
|
| typed_ctx_block
|
|
130
136
|
| return_stmt SEMI
|
|
131
|
-
| yield_expr SEMI
|
|
137
|
+
| (yield_expr | KW_YIELD) SEMI
|
|
132
138
|
| raise_stmt SEMI
|
|
133
139
|
| assert_stmt SEMI
|
|
140
|
+
| check_stmt SEMI
|
|
134
141
|
| assignment SEMI
|
|
135
142
|
| delete_stmt SEMI
|
|
136
143
|
| report_stmt SEMI
|
|
@@ -219,7 +226,6 @@ return_stmt: KW_RETURN expression?
|
|
|
219
226
|
|
|
220
227
|
// Yield statements
|
|
221
228
|
yield_expr: KW_YIELD KW_FROM? expression
|
|
222
|
-
| KW_YIELD
|
|
223
229
|
|
|
224
230
|
// Raise statements
|
|
225
231
|
raise_stmt: KW_RAISE (expression (KW_FROM expression)?)?
|
|
@@ -227,6 +233,9 @@ raise_stmt: KW_RAISE (expression (KW_FROM expression)?)?
|
|
|
227
233
|
// Assert statements
|
|
228
234
|
assert_stmt: KW_ASSERT expression (COMMA expression)?
|
|
229
235
|
|
|
236
|
+
// Check statements
|
|
237
|
+
check_stmt: KW_CHECK expression
|
|
238
|
+
|
|
230
239
|
// Delete statements
|
|
231
240
|
delete_stmt: KW_DELETE expression
|
|
232
241
|
|
|
@@ -279,7 +288,7 @@ expression: walrus_assign (KW_IF expression KW_ELSE expression)?
|
|
|
279
288
|
| lambda_expr
|
|
280
289
|
|
|
281
290
|
// Walrus assignments
|
|
282
|
-
walrus_assign: (
|
|
291
|
+
walrus_assign: (named_ref WALRUS_EQ)? pipe
|
|
283
292
|
|
|
284
293
|
// Lambda expressions
|
|
285
294
|
lambda_expr: KW_WITH func_decl_params? (RETURN_HINT expression)? KW_CAN expression
|
|
@@ -345,7 +354,7 @@ pipe_call: (PIPE_FWD | A_PIPE_FWD | KW_SPAWN | KW_AWAIT)? atomic_chain
|
|
|
345
354
|
|
|
346
355
|
// Subscripted and dotted expressions
|
|
347
356
|
atomic_chain: atomic_chain NULL_OK? (filter_compr | assign_compr | index_slice)
|
|
348
|
-
| atomic_chain NULL_OK? (DOT_BKWD | DOT_FWD | DOT)
|
|
357
|
+
| atomic_chain NULL_OK? (DOT_BKWD | DOT_FWD | DOT) named_ref
|
|
349
358
|
| (atomic_call | atom | edge_ref_chain)
|
|
350
359
|
|
|
351
360
|
index_slice: LSQUARE expression? COLON expression? (COLON expression?)? RSQUARE
|
|
@@ -359,10 +368,11 @@ param_list: expr_list COMMA kw_expr_list
|
|
|
359
368
|
| expr_list
|
|
360
369
|
|
|
361
370
|
// Atom
|
|
362
|
-
atom:
|
|
371
|
+
atom: named_ref
|
|
363
372
|
| LPAREN (expression | yield_expr) RPAREN
|
|
364
373
|
| atom_collection
|
|
365
374
|
| atom_literal
|
|
375
|
+
| type_ref
|
|
366
376
|
|
|
367
377
|
atom_literal: builtin_type
|
|
368
378
|
| NULL
|
|
@@ -375,6 +385,8 @@ atom_literal: builtin_type
|
|
|
375
385
|
| HEX
|
|
376
386
|
| INT
|
|
377
387
|
|
|
388
|
+
type_ref: TYPE_OP (named_ref | builtin_type)
|
|
389
|
+
|
|
378
390
|
multistring: (fstring | STRING | DOC_STRING)+
|
|
379
391
|
|
|
380
392
|
fstring: FSTR_START fstr_parts FSTR_END
|
|
@@ -415,7 +427,7 @@ tuple_list: expression COMMA expr_list COMMA kw_expr_list
|
|
|
415
427
|
| kw_expr_list
|
|
416
428
|
|
|
417
429
|
kw_expr_list: (kw_expr_list COMMA)? kw_expr
|
|
418
|
-
kw_expr:
|
|
430
|
+
kw_expr: named_ref EQ expression | STAR_POW expression
|
|
419
431
|
|
|
420
432
|
// Data Spatial References
|
|
421
433
|
edge_ref_chain: (EDGE_OP|NODE_OP)? LSQUARE expression? (edge_op_ref (filter_compr | expression)?)+ RSQUARE
|
|
@@ -438,15 +450,10 @@ typed_filter_compare_list: expression (COLON filter_compare_list)?
|
|
|
438
450
|
filter_compare_item: named_ref cmp_op expression
|
|
439
451
|
|
|
440
452
|
// Names and references
|
|
441
|
-
any_ref: named_ref
|
|
442
|
-
| type_ref
|
|
443
|
-
|
|
444
453
|
named_ref: special_ref
|
|
445
454
|
| KWESC_NAME
|
|
446
455
|
| NAME
|
|
447
456
|
|
|
448
|
-
type_ref: TYPE_OP (named_ref | builtin_type)
|
|
449
|
-
|
|
450
457
|
special_ref: KW_INIT
|
|
451
458
|
| KW_POST_INIT
|
|
452
459
|
| KW_ROOT
|
|
@@ -502,6 +509,7 @@ KW_ASYNC: "async"
|
|
|
502
509
|
KW_AWAIT: "await"
|
|
503
510
|
KW_TEST: "test"
|
|
504
511
|
KW_ASSERT: "assert"
|
|
512
|
+
KW_CHECK: "check"
|
|
505
513
|
KW_IF: "if"
|
|
506
514
|
KW_ELIF: "elif"
|
|
507
515
|
KW_ELSE: "else"
|