omextra 0.0.0.dev496__py3-none-any.whl → 0.0.0.dev498__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.
@@ -1,62 +1,59 @@
1
- import itertools
2
1
  import textwrap
3
2
  import typing as ta
4
3
 
5
4
  from omlish import check
6
5
 
7
- from .base import Grammar
8
- from .base import Match
6
+ from .grammars import Channel
7
+ from .grammars import Grammar
8
+ from .matches import Match
9
+ from .matches import filter_matches
9
10
  from .ops import RuleRef
10
11
 
11
12
 
12
13
  ##
13
14
 
14
15
 
15
- def strip_insignificant_match_rules(m: Match, g: Grammar) -> Match:
16
- def rec(c: Match) -> Match:
17
- return c.flat_map_children(
18
- lambda x: (
19
- (rec(x),) if not (
20
- isinstance((xp := x.op), RuleRef) and
21
- check.not_none(g.rule(xp.name)).insignificant
22
- ) else ()
23
- ),
24
- )
25
- return rec(m)
16
+ def filter_match_channels(
17
+ m: Match,
18
+ g: Grammar,
19
+ *,
20
+ keep: ta.Container[Channel] | None = None,
21
+ remove: ta.Container[Channel] | None = None,
22
+ keep_children: bool = False,
23
+ ) -> Match:
24
+ if keep is None and remove is None:
25
+ return m
26
26
 
27
+ def fn(x: Match) -> bool:
28
+ if not isinstance((rr := x.op), RuleRef):
29
+ return False
27
30
 
28
- def only_match_rules(m: Match) -> Match:
29
- def rec(c: Match) -> ta.Iterable[Match]:
30
- if isinstance(c.op, RuleRef):
31
- return (c.flat_map_children(rec),)
32
- else:
33
- return itertools.chain.from_iterable(map(rec, c.children))
34
- return m.flat_map_children(rec)
31
+ r = check.not_none(g.rule(rr.name))
32
+
33
+ if keep is not None and r.channel not in keep:
34
+ return False
35
+
36
+ if remove is not None and r.channel in remove:
37
+ return False
38
+
39
+ return True
40
+
41
+ return filter_matches(
42
+ fn,
43
+ m,
44
+ keep_children=keep_children,
45
+ )
35
46
 
36
47
 
37
48
  #
38
49
 
39
50
 
40
- def parse_rules(
41
- grammar: Grammar,
42
- source: str,
43
- root: str | None = None,
44
- *,
45
- start: int = 0,
46
- **kwargs: ta.Any,
47
- ) -> Match | None:
48
- if (match := grammar.parse(
49
- source,
50
- root,
51
- start=start,
52
- **kwargs,
53
- )) is None:
54
- return None
55
-
56
- match = only_match_rules(match)
57
- match = strip_insignificant_match_rules(match, grammar)
58
-
59
- return match
51
+ def only_match_rules(m: Match) -> Match:
52
+ return filter_matches(
53
+ lambda x: isinstance(x.op, RuleRef),
54
+ m,
55
+ keep_children=True,
56
+ )
60
57
 
61
58
 
62
59
  ##
@@ -5,8 +5,8 @@ from omlish import collections as col
5
5
  from omlish import dispatch
6
6
  from omlish import lang
7
7
 
8
- from .base import Match
9
8
  from .base import Op
9
+ from .matches import Match
10
10
  from .ops import RuleRef
11
11
 
12
12
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: omextra
3
- Version: 0.0.0.dev496
3
+ Version: 0.0.0.dev498
4
4
  Summary: omextra
5
5
  Author: wrmsr
6
6
  License-Expression: BSD-3-Clause
@@ -14,7 +14,7 @@ Classifier: Programming Language :: Python :: 3.13
14
14
  Requires-Python: >=3.13
15
15
  Description-Content-Type: text/markdown
16
16
  License-File: LICENSE
17
- Requires-Dist: omlish==0.0.0.dev496
17
+ Requires-Dist: omlish==0.0.0.dev498
18
18
  Dynamic: license-file
19
19
 
20
20
  # Overview
@@ -65,17 +65,20 @@ omextra/sql/parsing/_antlr/MinisqlVisitor.py,sha256=UPs2qA2VlNRP_LMwF0DpMxMir9tI
65
65
  omextra/sql/parsing/_antlr/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
66
66
  omextra/text/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
67
67
  omextra/text/abnf/LICENSE,sha256=UJzrhSePw9TVm0VfkVmx9NRHkPS1n6jx2UgajTb14ts,1054
68
- omextra/text/abnf/__init__.py,sha256=nDwr8A5pU8HajHvmAyT8Kr_d_nAUx3tO-ioZXifHob4,1298
69
- omextra/text/abnf/_dataclasses.py,sha256=YBZeWEvEkYZ8LqJo0MrV5kpKaUWoyLAP7hCT4ziOEh4,18787
70
- omextra/text/abnf/base.py,sha256=fhZwnsghININSgE7O5NWHBK196LKf_g_xyXwugvR_Vo,7134
71
- omextra/text/abnf/core.py,sha256=H5U5d-QOI66YSacrLXEcvMQipkabvP8EWo6d9QaxWoU,2283
68
+ omextra/text/abnf/__init__.py,sha256=qCV4I7sMWw2k3B4LnHrURwic2m1ewYdaOteu2n2lx0E,2662
69
+ omextra/text/abnf/_dataclasses.py,sha256=G7fqKpNvWZ-HtdlkwQ_O3IE-eD7-i0Fdq470l2ujM38,29545
70
+ omextra/text/abnf/base.py,sha256=GaNDZxC7rFkbQDTLVFwprtbk_288p7F40zgGkeLiwzY,969
71
+ omextra/text/abnf/core.py,sha256=CO62fK2Ez7XqVkESp_yNfX4iDY8tgph5b9fgmCMam0I,2728
72
72
  omextra/text/abnf/errors.py,sha256=uj1oQvRVRlWkMG8mpmcRUg25kICeIJx5EWAVij3pmXc,142
73
- omextra/text/abnf/internal.py,sha256=PzHIzEEv3H5oLI_hwSmkuOwwzh_BZpvXBjGKYqmPvzs,493
74
- omextra/text/abnf/meta.py,sha256=IvWdyo8739fCmBwVLzz7VrkScc5DM9uVOKUpEb6-lfM,14504
75
- omextra/text/abnf/ops.py,sha256=LHF1_NfczSypGb3XhNJIT0zWkIx57lzoZSgSELxUE2E,6063
76
- omextra/text/abnf/parsing.py,sha256=lDMBPCC-3Rs9XwnW_18E7NMjTSz_gz896u21mv15rvs,6676
77
- omextra/text/abnf/utils.py,sha256=cpPTGeiVFf1AN4K3KgodsOcarEhFxdEcgxtpRx9xB84,1460
78
- omextra/text/abnf/visitors.py,sha256=S7ZJ2TmQR_RHJ70xWWt3w6UGRD20uE7Nd5UqFYU593k,1266
73
+ omextra/text/abnf/grammars.py,sha256=PZn7jjzz6p2FGNSjO4OAqmyrAEc8_im17mtsoq3QMa8,5814
74
+ omextra/text/abnf/internal.py,sha256=BltBOKj1uXDxtPgpajt_a6va3Nj7x2SEFRSvevjkIzY,501
75
+ omextra/text/abnf/matches.py,sha256=YsGooPUnrxQsfBgvJoZPkPXKgHNq_HpVsxfzjG6wu-Y,3546
76
+ omextra/text/abnf/meta.py,sha256=7O0WgPKUk6dqQHVGKpVdCX6EAbphj7Gv7GAtkFKcoAY,15151
77
+ omextra/text/abnf/ops.py,sha256=gwN9kxsFmXh3CPN8bTXzDVP775d8hnYFiay4mRijfxc,8068
78
+ omextra/text/abnf/opto.py,sha256=4S97lkk_n4DWjvHqFvapKyMqWbI1voBS4Fhm7bdn3ks,6743
79
+ omextra/text/abnf/parsing.py,sha256=6WGn21gzFJlmVwOzJDD30YkpwXSVuLZlJNk7sGbZOik,9760
80
+ omextra/text/abnf/utils.py,sha256=EXyG5lZ561keeH5XFEePaH4UGa2wW-Aw2t9lE6aCJCc,1261
81
+ omextra/text/abnf/visitors.py,sha256=5Or7Tht5JqNAfoICLmeAXJEZV-nWyMIybvvYcSpNHEc,1269
79
82
  omextra/text/abnf/docs/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
80
83
  omextra/text/abnf/docs/rfc5234.txt,sha256=I478qv82TBjP29ZpQT-D6_pb3rHOU6wiwN2ZMGiXLLU,26352
81
84
  omextra/text/abnf/docs/rfc7405.txt,sha256=Bwt1VISu7eBvlPox9a0iuVD_uCF39teXrEMUQAuuvqU,6661
@@ -152,9 +155,9 @@ omextra/text/antlr/cli/__main__.py,sha256=ckYkj0drxabBVwWYewH2SS36TTeAxllZtS4xEl
152
155
  omextra/text/antlr/cli/cli.py,sha256=LW8pJNmySBOV3g8QxquPjUgxFv7YblzEyi555hHH3_M,1234
153
156
  omextra/text/antlr/cli/consts.py,sha256=HUYJP9j4RfeuuQv6HFd2oFMS0piWJ9Sq1tbeAs4OlBc,290
154
157
  omextra/text/antlr/cli/gen.py,sha256=HYleVptrpynwcl6GspX6O9_oMRSxwdYAQGuUFfDYse8,5236
155
- omextra-0.0.0.dev496.dist-info/licenses/LICENSE,sha256=B_hVtavaA8zCYDW99DYdcpDLKz1n3BBRjZrcbv8uG8c,1451
156
- omextra-0.0.0.dev496.dist-info/METADATA,sha256=6sf1j4HqLxz1VaR6VxOC4dVNrH97Z0YP0YZZNVgudXc,1409
157
- omextra-0.0.0.dev496.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
158
- omextra-0.0.0.dev496.dist-info/entry_points.txt,sha256=-MFAMks5HgZ60Ore0Wl5lKVKk8z4kf1Ls3WY9E_OlCU,37
159
- omextra-0.0.0.dev496.dist-info/top_level.txt,sha256=o1nCNRejLMcayDngLuWMWwaeOucz33BXbpuoVvvzjPc,8
160
- omextra-0.0.0.dev496.dist-info/RECORD,,
158
+ omextra-0.0.0.dev498.dist-info/licenses/LICENSE,sha256=B_hVtavaA8zCYDW99DYdcpDLKz1n3BBRjZrcbv8uG8c,1451
159
+ omextra-0.0.0.dev498.dist-info/METADATA,sha256=7xPp8WGYYfw-EBkMVoR8c3-1VlMOkQKAOZK3ZJtGgJ0,1409
160
+ omextra-0.0.0.dev498.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
161
+ omextra-0.0.0.dev498.dist-info/entry_points.txt,sha256=-MFAMks5HgZ60Ore0Wl5lKVKk8z4kf1Ls3WY9E_OlCU,37
162
+ omextra-0.0.0.dev498.dist-info/top_level.txt,sha256=o1nCNRejLMcayDngLuWMWwaeOucz33BXbpuoVvvzjPc,8
163
+ omextra-0.0.0.dev498.dist-info/RECORD,,