jaclang 0.5.5__py3-none-any.whl → 0.5.6__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/cli.py +4 -2
- jaclang/cli/cmdreg.py +3 -0
- jaclang/compiler/__jac_gen__/jac_parser.py +2 -2
- jaclang/compiler/absyntree.py +3 -3
- jaclang/compiler/parser.py +78 -114
- jaclang/compiler/passes/main/pyast_gen_pass.py +67 -44
- jaclang/compiler/passes/tool/jac_formatter_pass.py +0 -4
- jaclang/core/construct.py +0 -6
- jaclang/plugin/default.py +14 -14
- jaclang/plugin/feature.py +11 -5
- jaclang/plugin/spec.py +10 -2
- {jaclang-0.5.5.dist-info → jaclang-0.5.6.dist-info}/METADATA +1 -1
- {jaclang-0.5.5.dist-info → jaclang-0.5.6.dist-info}/RECORD +17 -17
- {jaclang-0.5.5.dist-info → jaclang-0.5.6.dist-info}/WHEEL +0 -0
- {jaclang-0.5.5.dist-info → jaclang-0.5.6.dist-info}/entry_points.txt +0 -0
- {jaclang-0.5.5.dist-info → jaclang-0.5.6.dist-info}/top_level.txt +0 -0
jaclang/compiler/absyntree.py
CHANGED
|
@@ -1779,13 +1779,11 @@ class EdgeOpRef(WalkerStmtOnlyNode, AtomExpr):
|
|
|
1779
1779
|
|
|
1780
1780
|
def __init__(
|
|
1781
1781
|
self,
|
|
1782
|
-
filter_type: Optional[Expr],
|
|
1783
1782
|
filter_cond: Optional[FilterCompr],
|
|
1784
1783
|
edge_dir: EdgeDir,
|
|
1785
1784
|
kid: Sequence[AstNode],
|
|
1786
1785
|
) -> None:
|
|
1787
1786
|
"""Initialize edge op reference expression node."""
|
|
1788
|
-
self.filter_type = filter_type
|
|
1789
1787
|
self.filter_cond = filter_cond
|
|
1790
1788
|
self.edge_dir = edge_dir
|
|
1791
1789
|
AstNode.__init__(self, kid=kid)
|
|
@@ -1834,10 +1832,12 @@ class FilterCompr(AtomExpr):
|
|
|
1834
1832
|
|
|
1835
1833
|
def __init__(
|
|
1836
1834
|
self,
|
|
1837
|
-
|
|
1835
|
+
f_type: Optional[Expr],
|
|
1836
|
+
compares: Optional[SubNodeList[CompareExpr]],
|
|
1838
1837
|
kid: Sequence[AstNode],
|
|
1839
1838
|
) -> None:
|
|
1840
1839
|
"""Initialize filter_cond context expression node."""
|
|
1840
|
+
self.f_type = f_type
|
|
1841
1841
|
self.compares = compares
|
|
1842
1842
|
AstNode.__init__(self, kid=kid)
|
|
1843
1843
|
AstSymbolNode.__init__(
|
jaclang/compiler/parser.py
CHANGED
|
@@ -5,7 +5,7 @@ from __future__ import annotations
|
|
|
5
5
|
|
|
6
6
|
import logging
|
|
7
7
|
import os
|
|
8
|
-
from typing import Callable, TypeAlias
|
|
8
|
+
from typing import Callable, TypeAlias
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
import jaclang.compiler.absyntree as ast
|
|
@@ -2256,76 +2256,51 @@ class JacParser(Pass):
|
|
|
2256
2256
|
else:
|
|
2257
2257
|
raise self.ice()
|
|
2258
2258
|
|
|
2259
|
-
def index_slice(self, kid: list[ast.AstNode]) -> ast.IndexSlice
|
|
2259
|
+
def index_slice(self, kid: list[ast.AstNode]) -> ast.IndexSlice:
|
|
2260
2260
|
"""Grammar rule.
|
|
2261
2261
|
|
|
2262
2262
|
index_slice: LSQUARE expression? COLON expression? (COLON expression?)? RSQUARE
|
|
2263
|
-
|
|
2264
|
-
"""
|
|
2265
|
-
if len(kid) == 1
|
|
2266
|
-
|
|
2267
|
-
if
|
|
2268
|
-
|
|
2269
|
-
|
|
2270
|
-
|
|
2263
|
+
| list_val
|
|
2264
|
+
"""
|
|
2265
|
+
if len(kid) == 1:
|
|
2266
|
+
index = kid[0]
|
|
2267
|
+
if isinstance(index, ast.ListVal):
|
|
2268
|
+
expr = index.values.items[0] if index.values else None
|
|
2269
|
+
return self.nu(
|
|
2270
|
+
ast.IndexSlice(
|
|
2271
|
+
start=expr,
|
|
2272
|
+
stop=None,
|
|
2273
|
+
step=None,
|
|
2274
|
+
is_range=False,
|
|
2275
|
+
kid=kid[0].kid,
|
|
2276
|
+
)
|
|
2277
|
+
)
|
|
2271
2278
|
else:
|
|
2272
|
-
vals = cast("ast.SubNodeList[ast.Expr|ast.KWPair]", kid[0].values)
|
|
2273
|
-
expr = ast.TupleVal(values=vals, kid=kid[0].kid)
|
|
2274
|
-
if expr is None:
|
|
2275
2279
|
raise self.ice()
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
chomp = chomp[1:]
|
|
2283
|
-
expr1 = chomp[0] if isinstance(chomp[0], ast.Expr) else None
|
|
2284
|
-
expr2 = (
|
|
2285
|
-
chomp[1]
|
|
2286
|
-
if isinstance(chomp[0], ast.Token)
|
|
2287
|
-
and chomp[0].name == Tok.COLON
|
|
2288
|
-
and isinstance(chomp[1], ast.Expr)
|
|
2289
|
-
else None
|
|
2290
|
-
)
|
|
2291
|
-
chomp = chomp[1:]
|
|
2292
|
-
expr2 = (
|
|
2293
|
-
chomp[1]
|
|
2294
|
-
if isinstance(chomp[0], ast.Token)
|
|
2295
|
-
and chomp[0].name == Tok.COLON
|
|
2296
|
-
and len(chomp) > 1
|
|
2297
|
-
and isinstance(chomp[1], ast.Expr)
|
|
2298
|
-
else expr2
|
|
2299
|
-
)
|
|
2300
|
-
expr3 = None
|
|
2301
|
-
if len(chomp) > 1:
|
|
2280
|
+
else:
|
|
2281
|
+
expr1 = expr2 = expr3 = None
|
|
2282
|
+
chomp = kid[1:]
|
|
2283
|
+
if isinstance(chomp[0], ast.Expr):
|
|
2284
|
+
expr1 = chomp[0]
|
|
2285
|
+
chomp = chomp[1:]
|
|
2302
2286
|
chomp = chomp[1:]
|
|
2303
|
-
|
|
2304
|
-
chomp[
|
|
2305
|
-
if isinstance(chomp[0], ast.Token)
|
|
2306
|
-
and chomp[0].name == Tok.COLON
|
|
2307
|
-
and isinstance(chomp[1], ast.Expr)
|
|
2308
|
-
else None
|
|
2309
|
-
)
|
|
2310
|
-
if len(chomp) > 1:
|
|
2287
|
+
if isinstance(chomp[0], ast.Expr):
|
|
2288
|
+
expr2 = chomp[0]
|
|
2311
2289
|
chomp = chomp[1:]
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
|
|
2318
|
-
|
|
2290
|
+
if isinstance(chomp[0], ast.Token) and chomp[0].name == Tok.COLON:
|
|
2291
|
+
chomp = chomp[1:]
|
|
2292
|
+
if isinstance(chomp[0], ast.Expr):
|
|
2293
|
+
expr3 = chomp[0]
|
|
2294
|
+
chomp = chomp[1:]
|
|
2295
|
+
return self.nu(
|
|
2296
|
+
ast.IndexSlice(
|
|
2297
|
+
start=expr1,
|
|
2298
|
+
stop=expr2,
|
|
2299
|
+
step=expr3,
|
|
2300
|
+
is_range=True,
|
|
2301
|
+
kid=kid,
|
|
2319
2302
|
)
|
|
2320
|
-
return self.nu(
|
|
2321
|
-
ast.IndexSlice(
|
|
2322
|
-
start=expr1,
|
|
2323
|
-
stop=expr2,
|
|
2324
|
-
step=expr3,
|
|
2325
|
-
is_range=True,
|
|
2326
|
-
kid=kid,
|
|
2327
2303
|
)
|
|
2328
|
-
)
|
|
2329
2304
|
|
|
2330
2305
|
def atom(self, kid: list[ast.AstNode]) -> ast.Expr:
|
|
2331
2306
|
"""Grammar rule.
|
|
@@ -3160,24 +3135,13 @@ class JacParser(Pass):
|
|
|
3160
3135
|
def edge_to(self, kid: list[ast.AstNode]) -> ast.EdgeOpRef:
|
|
3161
3136
|
"""Grammar rule.
|
|
3162
3137
|
|
|
3163
|
-
edge_to: ARROW_R_P1
|
|
3138
|
+
edge_to: ARROW_R_P1 typed_filter_compare_list ARROW_R_P2
|
|
3164
3139
|
| ARROW_R
|
|
3165
3140
|
"""
|
|
3166
|
-
|
|
3167
|
-
|
|
3168
|
-
if (isinstance(ftype, ast.Expr) or ftype is None) and (
|
|
3169
|
-
isinstance(fcond, ast.SubNodeList) or fcond is None
|
|
3170
|
-
):
|
|
3171
|
-
fcond = ast.FilterCompr(compares=fcond, kid=[fcond]) if fcond else None
|
|
3172
|
-
if fcond:
|
|
3173
|
-
kid[3] = fcond
|
|
3141
|
+
fcond = kid[1] if len(kid) > 1 else None
|
|
3142
|
+
if isinstance(fcond, ast.FilterCompr) or fcond is None:
|
|
3174
3143
|
return self.nu(
|
|
3175
|
-
ast.EdgeOpRef(
|
|
3176
|
-
filter_type=ftype,
|
|
3177
|
-
filter_cond=fcond,
|
|
3178
|
-
edge_dir=EdgeDir.OUT,
|
|
3179
|
-
kid=kid,
|
|
3180
|
-
)
|
|
3144
|
+
ast.EdgeOpRef(filter_cond=fcond, edge_dir=EdgeDir.OUT, kid=kid)
|
|
3181
3145
|
)
|
|
3182
3146
|
else:
|
|
3183
3147
|
raise self.ice()
|
|
@@ -3185,24 +3149,13 @@ class JacParser(Pass):
|
|
|
3185
3149
|
def edge_from(self, kid: list[ast.AstNode]) -> ast.EdgeOpRef:
|
|
3186
3150
|
"""Grammar rule.
|
|
3187
3151
|
|
|
3188
|
-
edge_from: ARROW_L_P1
|
|
3152
|
+
edge_from: ARROW_L_P1 typed_filter_compare_list ARROW_L_P2
|
|
3189
3153
|
| ARROW_L
|
|
3190
3154
|
"""
|
|
3191
|
-
|
|
3192
|
-
|
|
3193
|
-
if (isinstance(ftype, ast.Expr) or ftype is None) and (
|
|
3194
|
-
isinstance(fcond, ast.SubNodeList) or fcond is None
|
|
3195
|
-
):
|
|
3196
|
-
fcond = ast.FilterCompr(compares=fcond, kid=[fcond]) if fcond else None
|
|
3197
|
-
if fcond:
|
|
3198
|
-
kid[3] = fcond
|
|
3155
|
+
fcond = kid[1] if len(kid) > 1 else None
|
|
3156
|
+
if isinstance(fcond, ast.FilterCompr) or fcond is None:
|
|
3199
3157
|
return self.nu(
|
|
3200
|
-
ast.EdgeOpRef(
|
|
3201
|
-
filter_type=ftype,
|
|
3202
|
-
filter_cond=fcond,
|
|
3203
|
-
edge_dir=EdgeDir.IN,
|
|
3204
|
-
kid=kid,
|
|
3205
|
-
)
|
|
3158
|
+
ast.EdgeOpRef(filter_cond=fcond, edge_dir=EdgeDir.IN, kid=kid)
|
|
3206
3159
|
)
|
|
3207
3160
|
else:
|
|
3208
3161
|
raise self.ice()
|
|
@@ -3210,24 +3163,13 @@ class JacParser(Pass):
|
|
|
3210
3163
|
def edge_any(self, kid: list[ast.AstNode]) -> ast.EdgeOpRef:
|
|
3211
3164
|
"""Grammar rule.
|
|
3212
3165
|
|
|
3213
|
-
edge_any: ARROW_L_P1
|
|
3166
|
+
edge_any: ARROW_L_P1 typed_filter_compare_list ARROW_R_P2
|
|
3214
3167
|
| ARROW_BI
|
|
3215
3168
|
"""
|
|
3216
|
-
|
|
3217
|
-
|
|
3218
|
-
if (isinstance(ftype, ast.Expr) or ftype is None) and (
|
|
3219
|
-
isinstance(fcond, ast.SubNodeList) or fcond is None
|
|
3220
|
-
):
|
|
3221
|
-
fcond = ast.FilterCompr(compares=fcond, kid=[fcond]) if fcond else None
|
|
3222
|
-
if fcond:
|
|
3223
|
-
kid[3] = fcond
|
|
3169
|
+
fcond = kid[1] if len(kid) > 1 else None
|
|
3170
|
+
if isinstance(fcond, ast.FilterCompr) or fcond is None:
|
|
3224
3171
|
return self.nu(
|
|
3225
|
-
ast.EdgeOpRef(
|
|
3226
|
-
filter_type=ftype,
|
|
3227
|
-
filter_cond=fcond,
|
|
3228
|
-
edge_dir=EdgeDir.ANY,
|
|
3229
|
-
kid=kid,
|
|
3230
|
-
)
|
|
3172
|
+
ast.EdgeOpRef(filter_cond=fcond, edge_dir=EdgeDir.ANY, kid=kid)
|
|
3231
3173
|
)
|
|
3232
3174
|
else:
|
|
3233
3175
|
raise self.ice()
|
|
@@ -3346,15 +3288,15 @@ class JacParser(Pass):
|
|
|
3346
3288
|
def filter_compr(self, kid: list[ast.AstNode]) -> ast.FilterCompr:
|
|
3347
3289
|
"""Grammar rule.
|
|
3348
3290
|
|
|
3349
|
-
filter_compr: LPAREN
|
|
3291
|
+
filter_compr: LPAREN NULL_OK filter_compare_list RPAREN
|
|
3292
|
+
| LPAREN TYPE_OP NULL_OK typed_filter_compare_list RPAREN
|
|
3350
3293
|
"""
|
|
3351
3294
|
if isinstance(kid[2], ast.SubNodeList):
|
|
3352
|
-
return self.nu(
|
|
3353
|
-
|
|
3354
|
-
|
|
3355
|
-
|
|
3356
|
-
|
|
3357
|
-
)
|
|
3295
|
+
return self.nu(ast.FilterCompr(compares=kid[2], f_type=None, kid=kid))
|
|
3296
|
+
elif isinstance(kid[3], ast.FilterCompr):
|
|
3297
|
+
kid[3].add_kids_left(kid[:3])
|
|
3298
|
+
kid[3].add_kids_right(kid[4:])
|
|
3299
|
+
return self.nu(kid[3])
|
|
3358
3300
|
else:
|
|
3359
3301
|
raise self.ice()
|
|
3360
3302
|
|
|
@@ -3384,6 +3326,28 @@ class JacParser(Pass):
|
|
|
3384
3326
|
)
|
|
3385
3327
|
)
|
|
3386
3328
|
|
|
3329
|
+
def typed_filter_compare_list(self, kid: list[ast.AstNode]) -> ast.FilterCompr:
|
|
3330
|
+
"""Grammar rule.
|
|
3331
|
+
|
|
3332
|
+
typed_filter_compare_list: expression (COLON filter_compare_list)?
|
|
3333
|
+
"""
|
|
3334
|
+
chomp = [*kid]
|
|
3335
|
+
expr = chomp[0]
|
|
3336
|
+
chomp = chomp[1:]
|
|
3337
|
+
compares = (
|
|
3338
|
+
chomp[1]
|
|
3339
|
+
if len(chomp)
|
|
3340
|
+
and isinstance(chomp[0], ast.Token)
|
|
3341
|
+
and chomp[0].name == Tok.COLON
|
|
3342
|
+
else None
|
|
3343
|
+
)
|
|
3344
|
+
if isinstance(expr, ast.Expr) and (
|
|
3345
|
+
(isinstance(compares, ast.SubNodeList)) or compares is None
|
|
3346
|
+
):
|
|
3347
|
+
return self.nu(ast.FilterCompr(compares=compares, f_type=expr, kid=kid))
|
|
3348
|
+
else:
|
|
3349
|
+
raise self.ice()
|
|
3350
|
+
|
|
3387
3351
|
def filter_compare_item(self, kid: list[ast.AstNode]) -> ast.CompareExpr:
|
|
3388
3352
|
"""Grammar rule.
|
|
3389
3353
|
|
|
@@ -1788,11 +1788,6 @@ class PyastGenPass(Pass):
|
|
|
1788
1788
|
self.sync(
|
|
1789
1789
|
ast3.Constant(value=node.op.edge_spec.edge_dir.name)
|
|
1790
1790
|
),
|
|
1791
|
-
(
|
|
1792
|
-
node.op.edge_spec.filter_type.gen.py_ast[0]
|
|
1793
|
-
if node.op.edge_spec.filter_type is not None
|
|
1794
|
-
else self.sync(ast3.Constant(value=None))
|
|
1795
|
-
),
|
|
1796
1791
|
(
|
|
1797
1792
|
node.op.edge_spec.filter_cond.gen.py_ast[0]
|
|
1798
1793
|
if node.op.edge_spec.filter_cond is not None
|
|
@@ -2420,9 +2415,9 @@ class PyastGenPass(Pass):
|
|
|
2420
2415
|
node.gen.py_ast = [
|
|
2421
2416
|
self.sync(
|
|
2422
2417
|
ast3.Slice(
|
|
2423
|
-
lower=node.start.gen.py_ast if node.start else None,
|
|
2424
|
-
upper=node.stop.gen.py_ast if node.stop else None,
|
|
2425
|
-
step=node.step.gen.py_ast if node.step else None,
|
|
2418
|
+
lower=node.start.gen.py_ast[0] if node.start else None,
|
|
2419
|
+
upper=node.stop.gen.py_ast[0] if node.stop else None,
|
|
2420
|
+
step=node.step.gen.py_ast[0] if node.step else None,
|
|
2426
2421
|
)
|
|
2427
2422
|
)
|
|
2428
2423
|
]
|
|
@@ -2550,16 +2545,6 @@ class PyastGenPass(Pass):
|
|
|
2550
2545
|
),
|
|
2551
2546
|
)
|
|
2552
2547
|
),
|
|
2553
|
-
self.sync(
|
|
2554
|
-
ast3.keyword(
|
|
2555
|
-
arg="filter_type",
|
|
2556
|
-
value=self.sync(
|
|
2557
|
-
node.filter_type.gen.py_ast[0]
|
|
2558
|
-
if node.filter_type
|
|
2559
|
-
else self.sync(ast3.Constant(value=None))
|
|
2560
|
-
),
|
|
2561
|
-
)
|
|
2562
|
-
),
|
|
2563
2548
|
self.sync(
|
|
2564
2549
|
ast3.keyword(
|
|
2565
2550
|
arg="filter_func",
|
|
@@ -2670,38 +2655,76 @@ class PyastGenPass(Pass):
|
|
|
2670
2655
|
iter=self.sync(
|
|
2671
2656
|
ast3.Name(id="x", ctx=ast3.Load())
|
|
2672
2657
|
),
|
|
2673
|
-
ifs=
|
|
2674
|
-
|
|
2675
|
-
|
|
2676
|
-
|
|
2677
|
-
ast3.
|
|
2678
|
-
|
|
2658
|
+
ifs=(
|
|
2659
|
+
(
|
|
2660
|
+
[
|
|
2661
|
+
self.sync(
|
|
2662
|
+
ast3.Call(
|
|
2663
|
+
func=self.sync(
|
|
2679
2664
|
ast3.Name(
|
|
2680
|
-
id="
|
|
2665
|
+
id="isinstance",
|
|
2681
2666
|
ctx=ast3.Load(),
|
|
2667
|
+
)
|
|
2668
|
+
),
|
|
2669
|
+
args=[
|
|
2670
|
+
self.sync(
|
|
2671
|
+
ast3.Name(
|
|
2672
|
+
id="i",
|
|
2673
|
+
ctx=ast3.Load(),
|
|
2674
|
+
)
|
|
2675
|
+
),
|
|
2676
|
+
self.sync(
|
|
2677
|
+
node.f_type.gen.py_ast[
|
|
2678
|
+
0
|
|
2679
|
+
]
|
|
2682
2680
|
),
|
|
2683
|
-
|
|
2681
|
+
],
|
|
2682
|
+
keywords=[],
|
|
2683
|
+
)
|
|
2684
|
+
)
|
|
2685
|
+
]
|
|
2686
|
+
if node.f_type
|
|
2687
|
+
else []
|
|
2688
|
+
)
|
|
2689
|
+
+ [
|
|
2690
|
+
self.sync(
|
|
2691
|
+
ast3.Compare(
|
|
2692
|
+
left=self.sync(
|
|
2693
|
+
ast3.Attribute(
|
|
2694
|
+
value=self.sync(
|
|
2695
|
+
ast3.Name(
|
|
2696
|
+
id="i",
|
|
2697
|
+
ctx=ast3.Load(),
|
|
2698
|
+
),
|
|
2699
|
+
jac_node=x,
|
|
2700
|
+
),
|
|
2701
|
+
attr=x.gen.py_ast[
|
|
2702
|
+
0
|
|
2703
|
+
].left.id,
|
|
2704
|
+
ctx=ast3.Load(),
|
|
2684
2705
|
),
|
|
2685
|
-
|
|
2686
|
-
0
|
|
2687
|
-
].left.id,
|
|
2688
|
-
ctx=ast3.Load(),
|
|
2706
|
+
jac_node=x,
|
|
2689
2707
|
),
|
|
2690
|
-
|
|
2708
|
+
ops=x.gen.py_ast[0].ops,
|
|
2709
|
+
comparators=x.gen.py_ast[
|
|
2710
|
+
0
|
|
2711
|
+
].comparators,
|
|
2691
2712
|
),
|
|
2692
|
-
|
|
2693
|
-
|
|
2694
|
-
|
|
2695
|
-
|
|
2696
|
-
|
|
2697
|
-
|
|
2698
|
-
|
|
2699
|
-
|
|
2700
|
-
|
|
2701
|
-
|
|
2702
|
-
|
|
2703
|
-
|
|
2704
|
-
|
|
2713
|
+
jac_node=x,
|
|
2714
|
+
)
|
|
2715
|
+
for x in (
|
|
2716
|
+
node.compares.items
|
|
2717
|
+
if node.compares
|
|
2718
|
+
else []
|
|
2719
|
+
)
|
|
2720
|
+
if isinstance(
|
|
2721
|
+
x.gen.py_ast[0], ast3.Compare
|
|
2722
|
+
)
|
|
2723
|
+
and isinstance(
|
|
2724
|
+
x.gen.py_ast[0].left, ast3.Name
|
|
2725
|
+
)
|
|
2726
|
+
]
|
|
2727
|
+
),
|
|
2705
2728
|
is_async=0,
|
|
2706
2729
|
)
|
|
2707
2730
|
)
|
|
@@ -1433,11 +1433,7 @@ class JacFormatPass(Pass):
|
|
|
1433
1433
|
stop: Optional[ExprType],
|
|
1434
1434
|
"""
|
|
1435
1435
|
for i in node.kid:
|
|
1436
|
-
if not i.gen.jac.startswith("["):
|
|
1437
|
-
self.emit(node, "[")
|
|
1438
1436
|
self.emit(node, i.gen.jac)
|
|
1439
|
-
if not i.gen.jac.endswith("]"):
|
|
1440
|
-
self.emit(node, "]")
|
|
1441
1437
|
|
|
1442
1438
|
def exit_list_val(self, node: ast.ListVal) -> None:
|
|
1443
1439
|
"""Sub objects.
|
jaclang/core/construct.py
CHANGED
|
@@ -44,15 +44,12 @@ class NodeAnchor(ObjectAnchor):
|
|
|
44
44
|
def get_edges(
|
|
45
45
|
self,
|
|
46
46
|
dir: EdgeDir,
|
|
47
|
-
filter_type: Optional[type],
|
|
48
47
|
filter_func: Optional[Callable[[list[EdgeArchitype]], list[EdgeArchitype]]],
|
|
49
48
|
target_obj: Optional[list[NodeArchitype]],
|
|
50
49
|
) -> list[EdgeArchitype]:
|
|
51
50
|
"""Get edges connected to this node."""
|
|
52
51
|
edge_list: list[EdgeArchitype] = [*self.edges]
|
|
53
52
|
ret_edges: list[EdgeArchitype] = []
|
|
54
|
-
if filter_type:
|
|
55
|
-
edge_list = [e for e in edge_list if isinstance(e, filter_type)]
|
|
56
53
|
edge_list = filter_func(edge_list) if filter_func else edge_list
|
|
57
54
|
for e in edge_list:
|
|
58
55
|
if (
|
|
@@ -75,15 +72,12 @@ class NodeAnchor(ObjectAnchor):
|
|
|
75
72
|
def edges_to_nodes(
|
|
76
73
|
self,
|
|
77
74
|
dir: EdgeDir,
|
|
78
|
-
filter_type: Optional[type],
|
|
79
75
|
filter_func: Optional[Callable[[list[EdgeArchitype]], list[EdgeArchitype]]],
|
|
80
76
|
target_obj: Optional[list[NodeArchitype]],
|
|
81
77
|
) -> list[NodeArchitype]:
|
|
82
78
|
"""Get set of nodes connected to this node."""
|
|
83
79
|
edge_list: list[EdgeArchitype] = [*self.edges]
|
|
84
80
|
node_list: list[NodeArchitype] = []
|
|
85
|
-
if filter_type:
|
|
86
|
-
edge_list = [e for e in edge_list if isinstance(e, filter_type)]
|
|
87
81
|
edge_list = filter_func(edge_list) if filter_func else edge_list
|
|
88
82
|
for e in edge_list:
|
|
89
83
|
if e._jac_.target and e._jac_.source:
|
jaclang/plugin/default.py
CHANGED
|
@@ -262,7 +262,6 @@ class JacFeatureDefaults:
|
|
|
262
262
|
node_obj: NodeArchitype | list[NodeArchitype],
|
|
263
263
|
target_obj: Optional[NodeArchitype | list[NodeArchitype]],
|
|
264
264
|
dir: EdgeDir,
|
|
265
|
-
filter_type: Optional[type],
|
|
266
265
|
filter_func: Optional[Callable[[list[EdgeArchitype]], list[EdgeArchitype]]],
|
|
267
266
|
edges_only: bool,
|
|
268
267
|
) -> list[NodeArchitype] | list[EdgeArchitype]:
|
|
@@ -278,16 +277,14 @@ class JacFeatureDefaults:
|
|
|
278
277
|
connected_edges: list[EdgeArchitype] = []
|
|
279
278
|
for node in node_obj:
|
|
280
279
|
connected_edges += node._jac_.get_edges(
|
|
281
|
-
dir,
|
|
280
|
+
dir, filter_func, target_obj=targ_obj_set
|
|
282
281
|
)
|
|
283
282
|
return list(set(connected_edges))
|
|
284
283
|
else:
|
|
285
284
|
connected_nodes: list[NodeArchitype] = []
|
|
286
285
|
for node in node_obj:
|
|
287
286
|
connected_nodes.extend(
|
|
288
|
-
node._jac_.edges_to_nodes(
|
|
289
|
-
dir, filter_type, filter_func, target_obj=targ_obj_set
|
|
290
|
-
)
|
|
287
|
+
node._jac_.edges_to_nodes(dir, filter_func, target_obj=targ_obj_set)
|
|
291
288
|
)
|
|
292
289
|
return list(set(connected_nodes))
|
|
293
290
|
|
|
@@ -319,7 +316,6 @@ class JacFeatureDefaults:
|
|
|
319
316
|
left: NodeArchitype | list[NodeArchitype],
|
|
320
317
|
right: NodeArchitype | list[NodeArchitype],
|
|
321
318
|
dir: EdgeDir,
|
|
322
|
-
filter_type: Optional[type],
|
|
323
319
|
filter_func: Optional[Callable[[list[EdgeArchitype]], list[EdgeArchitype]]],
|
|
324
320
|
) -> bool: # noqa: ANN401
|
|
325
321
|
"""Jac's disconnect operator feature."""
|
|
@@ -329,17 +325,11 @@ class JacFeatureDefaults:
|
|
|
329
325
|
for i in left:
|
|
330
326
|
for j in right:
|
|
331
327
|
edge_list: list[EdgeArchitype] = [*i._jac_.edges]
|
|
332
|
-
if filter_type:
|
|
333
|
-
edge_list = [e for e in edge_list if isinstance(e, filter_type)]
|
|
334
328
|
edge_list = filter_func(edge_list) if filter_func else edge_list
|
|
335
329
|
for e in edge_list:
|
|
336
|
-
if
|
|
337
|
-
e._jac_.target
|
|
338
|
-
and e._jac_.source
|
|
339
|
-
and (not filter_type or isinstance(e, filter_type))
|
|
340
|
-
):
|
|
330
|
+
if e._jac_.target and e._jac_.source:
|
|
341
331
|
if (
|
|
342
|
-
dir in ["OUT", "ANY"]
|
|
332
|
+
dir in ["OUT", "ANY"] # TODO: Not ideal
|
|
343
333
|
and i._jac_.obj == e._jac_.source
|
|
344
334
|
and e._jac_.target == j._jac_.obj
|
|
345
335
|
):
|
|
@@ -404,3 +394,13 @@ class JacBuiltin:
|
|
|
404
394
|
def dotgen(node: NodeArchitype, radius: int = 0) -> str:
|
|
405
395
|
"""Print the dot graph."""
|
|
406
396
|
return dotgen(node, radius)
|
|
397
|
+
|
|
398
|
+
|
|
399
|
+
class JacCmdDefaults:
|
|
400
|
+
"""Jac CLI command."""
|
|
401
|
+
|
|
402
|
+
@staticmethod
|
|
403
|
+
@hookimpl
|
|
404
|
+
def create_cmd() -> None:
|
|
405
|
+
"""Create Jac CLI cmds."""
|
|
406
|
+
pass
|
jaclang/plugin/feature.py
CHANGED
|
@@ -13,12 +13,13 @@ from jaclang.core.construct import (
|
|
|
13
13
|
Root,
|
|
14
14
|
WalkerArchitype,
|
|
15
15
|
)
|
|
16
|
-
from jaclang.plugin.spec import JacFeatureSpec, T
|
|
16
|
+
from jaclang.plugin.spec import JacCmdSpec, JacFeatureSpec, T
|
|
17
17
|
|
|
18
18
|
import pluggy
|
|
19
19
|
|
|
20
20
|
pm = pluggy.PluginManager("jac")
|
|
21
21
|
pm.add_hookspecs(JacFeatureSpec)
|
|
22
|
+
pm.add_hookspecs(JacCmdSpec)
|
|
22
23
|
|
|
23
24
|
|
|
24
25
|
class JacFeature:
|
|
@@ -143,7 +144,6 @@ class JacFeature:
|
|
|
143
144
|
node_obj: NodeArchitype | list[NodeArchitype],
|
|
144
145
|
target_obj: Optional[NodeArchitype | list[NodeArchitype]],
|
|
145
146
|
dir: EdgeDir,
|
|
146
|
-
filter_type: Optional[type],
|
|
147
147
|
filter_func: Optional[Callable[[list[EdgeArchitype]], list[EdgeArchitype]]],
|
|
148
148
|
edges_only: bool = False,
|
|
149
149
|
) -> list[NodeArchitype] | list[EdgeArchitype]:
|
|
@@ -152,7 +152,6 @@ class JacFeature:
|
|
|
152
152
|
node_obj=node_obj,
|
|
153
153
|
target_obj=target_obj,
|
|
154
154
|
dir=dir,
|
|
155
|
-
filter_type=filter_type,
|
|
156
155
|
filter_func=filter_func,
|
|
157
156
|
edges_only=edges_only,
|
|
158
157
|
)
|
|
@@ -177,7 +176,6 @@ class JacFeature:
|
|
|
177
176
|
left: NodeArchitype | list[NodeArchitype],
|
|
178
177
|
right: NodeArchitype | list[NodeArchitype],
|
|
179
178
|
dir: EdgeDir,
|
|
180
|
-
filter_type: Optional[type],
|
|
181
179
|
filter_func: Optional[Callable[[list[EdgeArchitype]], list[EdgeArchitype]]],
|
|
182
180
|
) -> bool:
|
|
183
181
|
"""Jac's disconnect operator feature."""
|
|
@@ -185,7 +183,6 @@ class JacFeature:
|
|
|
185
183
|
left=left,
|
|
186
184
|
right=right,
|
|
187
185
|
dir=dir,
|
|
188
|
-
filter_type=filter_type,
|
|
189
186
|
filter_func=filter_func,
|
|
190
187
|
)
|
|
191
188
|
|
|
@@ -220,3 +217,12 @@ class JacBuiltin:
|
|
|
220
217
|
def dotgen(node: NodeArchitype, radius: int = 0) -> str:
|
|
221
218
|
"""Print the dot graph."""
|
|
222
219
|
return pm.hook.dotgen(node=node, radius=radius)
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
class JacCmd:
|
|
223
|
+
"""Jac CLI command."""
|
|
224
|
+
|
|
225
|
+
@staticmethod
|
|
226
|
+
def create_cmd() -> None:
|
|
227
|
+
"""Create Jac CLI cmds."""
|
|
228
|
+
return pm.hook.create_cmd()
|
jaclang/plugin/spec.py
CHANGED
|
@@ -149,7 +149,6 @@ class JacFeatureSpec:
|
|
|
149
149
|
node_obj: NodeArchitype | list[NodeArchitype],
|
|
150
150
|
target_obj: Optional[NodeArchitype | list[NodeArchitype]],
|
|
151
151
|
dir: EdgeDir,
|
|
152
|
-
filter_type: Optional[type],
|
|
153
152
|
filter_func: Optional[Callable[[list[EdgeArchitype]], list[EdgeArchitype]]],
|
|
154
153
|
edges_only: bool,
|
|
155
154
|
) -> list[NodeArchitype] | list[EdgeArchitype]:
|
|
@@ -176,7 +175,6 @@ class JacFeatureSpec:
|
|
|
176
175
|
left: NodeArchitype | list[NodeArchitype],
|
|
177
176
|
right: NodeArchitype | list[NodeArchitype],
|
|
178
177
|
dir: EdgeDir,
|
|
179
|
-
filter_type: Optional[type],
|
|
180
178
|
filter_func: Optional[Callable[[list[EdgeArchitype]], list[EdgeArchitype]]],
|
|
181
179
|
) -> bool: # noqa: ANN401
|
|
182
180
|
"""Jac's disconnect operator feature."""
|
|
@@ -215,3 +213,13 @@ class JacBuiltin:
|
|
|
215
213
|
def dotgen(node: NodeArchitype, radius: int = 0) -> str:
|
|
216
214
|
"""Print the dot graph."""
|
|
217
215
|
raise NotImplementedError
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
class JacCmdSpec:
|
|
219
|
+
"""Jac CLI command."""
|
|
220
|
+
|
|
221
|
+
@staticmethod
|
|
222
|
+
@hookspec
|
|
223
|
+
def create_cmd() -> None:
|
|
224
|
+
"""Create Jac CLI cmds."""
|
|
225
|
+
raise NotImplementedError
|