omlish 0.0.0.dev56__py3-none-any.whl → 0.0.0.dev58__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.
Files changed (68) hide show
  1. omlish/__about__.py +2 -2
  2. omlish/antlr/__init__.py +0 -0
  3. omlish/antlr/_runtime/BufferedTokenStream.py +305 -0
  4. omlish/antlr/_runtime/CommonTokenFactory.py +64 -0
  5. omlish/antlr/_runtime/CommonTokenStream.py +90 -0
  6. omlish/antlr/_runtime/FileStream.py +30 -0
  7. omlish/antlr/_runtime/InputStream.py +90 -0
  8. omlish/antlr/_runtime/IntervalSet.py +183 -0
  9. omlish/antlr/_runtime/LL1Analyzer.py +176 -0
  10. omlish/antlr/_runtime/Lexer.py +332 -0
  11. omlish/antlr/_runtime/ListTokenSource.py +147 -0
  12. omlish/antlr/_runtime/Parser.py +583 -0
  13. omlish/antlr/_runtime/ParserInterpreter.py +173 -0
  14. omlish/antlr/_runtime/ParserRuleContext.py +189 -0
  15. omlish/antlr/_runtime/PredictionContext.py +632 -0
  16. omlish/antlr/_runtime/Recognizer.py +150 -0
  17. omlish/antlr/_runtime/RuleContext.py +230 -0
  18. omlish/antlr/_runtime/StdinStream.py +14 -0
  19. omlish/antlr/_runtime/Token.py +158 -0
  20. omlish/antlr/_runtime/TokenStreamRewriter.py +258 -0
  21. omlish/antlr/_runtime/Utils.py +36 -0
  22. omlish/antlr/_runtime/__init__.py +24 -0
  23. omlish/antlr/_runtime/_pygrun.py +174 -0
  24. omlish/antlr/_runtime/atn/ATN.py +135 -0
  25. omlish/antlr/_runtime/atn/ATNConfig.py +162 -0
  26. omlish/antlr/_runtime/atn/ATNConfigSet.py +215 -0
  27. omlish/antlr/_runtime/atn/ATNDeserializationOptions.py +27 -0
  28. omlish/antlr/_runtime/atn/ATNDeserializer.py +449 -0
  29. omlish/antlr/_runtime/atn/ATNSimulator.py +50 -0
  30. omlish/antlr/_runtime/atn/ATNState.py +267 -0
  31. omlish/antlr/_runtime/atn/ATNType.py +20 -0
  32. omlish/antlr/_runtime/atn/LexerATNSimulator.py +573 -0
  33. omlish/antlr/_runtime/atn/LexerAction.py +301 -0
  34. omlish/antlr/_runtime/atn/LexerActionExecutor.py +146 -0
  35. omlish/antlr/_runtime/atn/ParserATNSimulator.py +1664 -0
  36. omlish/antlr/_runtime/atn/PredictionMode.py +502 -0
  37. omlish/antlr/_runtime/atn/SemanticContext.py +333 -0
  38. omlish/antlr/_runtime/atn/Transition.py +271 -0
  39. omlish/antlr/_runtime/atn/__init__.py +4 -0
  40. omlish/antlr/_runtime/dfa/DFA.py +136 -0
  41. omlish/antlr/_runtime/dfa/DFASerializer.py +76 -0
  42. omlish/antlr/_runtime/dfa/DFAState.py +129 -0
  43. omlish/antlr/_runtime/dfa/__init__.py +4 -0
  44. omlish/antlr/_runtime/error/DiagnosticErrorListener.py +110 -0
  45. omlish/antlr/_runtime/error/ErrorListener.py +75 -0
  46. omlish/antlr/_runtime/error/ErrorStrategy.py +712 -0
  47. omlish/antlr/_runtime/error/Errors.py +176 -0
  48. omlish/antlr/_runtime/error/__init__.py +4 -0
  49. omlish/antlr/_runtime/tree/Chunk.py +33 -0
  50. omlish/antlr/_runtime/tree/ParseTreeMatch.py +121 -0
  51. omlish/antlr/_runtime/tree/ParseTreePattern.py +75 -0
  52. omlish/antlr/_runtime/tree/ParseTreePatternMatcher.py +377 -0
  53. omlish/antlr/_runtime/tree/RuleTagToken.py +53 -0
  54. omlish/antlr/_runtime/tree/TokenTagToken.py +50 -0
  55. omlish/antlr/_runtime/tree/Tree.py +194 -0
  56. omlish/antlr/_runtime/tree/Trees.py +114 -0
  57. omlish/antlr/_runtime/tree/__init__.py +2 -0
  58. omlish/antlr/_runtime/xpath/XPath.py +272 -0
  59. omlish/antlr/_runtime/xpath/XPathLexer.py +98 -0
  60. omlish/antlr/_runtime/xpath/__init__.py +4 -0
  61. omlish/formats/json/cli.py +76 -7
  62. omlish/formats/props.py +6 -2
  63. {omlish-0.0.0.dev56.dist-info → omlish-0.0.0.dev58.dist-info}/METADATA +1 -1
  64. {omlish-0.0.0.dev56.dist-info → omlish-0.0.0.dev58.dist-info}/RECORD +68 -9
  65. {omlish-0.0.0.dev56.dist-info → omlish-0.0.0.dev58.dist-info}/LICENSE +0 -0
  66. {omlish-0.0.0.dev56.dist-info → omlish-0.0.0.dev58.dist-info}/WHEEL +0 -0
  67. {omlish-0.0.0.dev56.dist-info → omlish-0.0.0.dev58.dist-info}/entry_points.txt +0 -0
  68. {omlish-0.0.0.dev56.dist-info → omlish-0.0.0.dev58.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,333 @@
1
+ # type: ignore
2
+ # ruff: noqa
3
+ # flake8: noqa
4
+ #
5
+ # Copyright (c) 2012-2017 The ANTLR Project. All rights reserved.
6
+ # Use of this file is governed by the BSD 3-clause license that
7
+ # can be found in the LICENSE.txt file in the project root.
8
+ #
9
+
10
+ # A tree structure used to record the semantic context in which
11
+ # an ATN configuration is valid. It's either a single predicate,
12
+ # a conjunction {@code p1&&p2}, or a sum of products {@code p1||p2}.
13
+ #
14
+ # <p>I have scoped the {@link AND}, {@link OR}, and {@link Predicate} subclasses of
15
+ # {@link SemanticContext} within the scope of this outer class.</p>
16
+ #
17
+ from ..Recognizer import Recognizer
18
+ from ..RuleContext import RuleContext
19
+ from io import StringIO
20
+
21
+
22
+ class SemanticContext(object):
23
+ #
24
+ # The default {@link SemanticContext}, which is semantically equivalent to
25
+ # a predicate of the form {@code {true}?}.
26
+ #
27
+ NONE = None
28
+
29
+ #
30
+ # For context independent predicates, we evaluate them without a local
31
+ # context (i.e., null context). That way, we can evaluate them without
32
+ # having to create proper rule-specific context during prediction (as
33
+ # opposed to the parser, which creates them naturally). In a practical
34
+ # sense, this avoids a cast exception from RuleContext to myruleContext.
35
+ #
36
+ # <p>For context dependent predicates, we must pass in a local context so that
37
+ # references such as $arg evaluate properly as _localctx.arg. We only
38
+ # capture context dependent predicates in the context in which we begin
39
+ # prediction, so we passed in the outer context here in case of context
40
+ # dependent predicate evaluation.</p>
41
+ #
42
+ def eval(self, parser:Recognizer , outerContext:RuleContext ):
43
+ pass
44
+
45
+ #
46
+ # Evaluate the precedence predicates for the context and reduce the result.
47
+ #
48
+ # @param parser The parser instance.
49
+ # @param outerContext The current parser context object.
50
+ # @return The simplified semantic context after precedence predicates are
51
+ # evaluated, which will be one of the following values.
52
+ # <ul>
53
+ # <li>{@link #NONE}: if the predicate simplifies to {@code true} after
54
+ # precedence predicates are evaluated.</li>
55
+ # <li>{@code null}: if the predicate simplifies to {@code false} after
56
+ # precedence predicates are evaluated.</li>
57
+ # <li>{@code this}: if the semantic context is not changed as a result of
58
+ # precedence predicate evaluation.</li>
59
+ # <li>A non-{@code null} {@link SemanticContext}: the new simplified
60
+ # semantic context after precedence predicates are evaluated.</li>
61
+ # </ul>
62
+ #
63
+ def evalPrecedence(self, parser:Recognizer, outerContext:RuleContext):
64
+ return self
65
+
66
+ # need forward declaration
67
+ AND = None
68
+
69
+ def andContext(a:SemanticContext, b:SemanticContext):
70
+ if a is None or a is SemanticContext.NONE:
71
+ return b
72
+ if b is None or b is SemanticContext.NONE:
73
+ return a
74
+ result = AND(a, b)
75
+ if len(result.opnds) == 1:
76
+ return result.opnds[0]
77
+ else:
78
+ return result
79
+
80
+ # need forward declaration
81
+ OR = None
82
+
83
+ def orContext(a:SemanticContext, b:SemanticContext):
84
+ if a is None:
85
+ return b
86
+ if b is None:
87
+ return a
88
+ if a is SemanticContext.NONE or b is SemanticContext.NONE:
89
+ return SemanticContext.NONE
90
+ result = OR(a, b)
91
+ if len(result.opnds) == 1:
92
+ return result.opnds[0]
93
+ else:
94
+ return result
95
+
96
+ def filterPrecedencePredicates(collection:set):
97
+ return [context for context in collection if isinstance(context, PrecedencePredicate)]
98
+
99
+
100
+ class EmptySemanticContext(SemanticContext):
101
+ pass
102
+
103
+ class Predicate(SemanticContext):
104
+ __slots__ = ('ruleIndex', 'predIndex', 'isCtxDependent')
105
+
106
+ def __init__(self, ruleIndex:int=-1, predIndex:int=-1, isCtxDependent:bool=False):
107
+ self.ruleIndex = ruleIndex
108
+ self.predIndex = predIndex
109
+ self.isCtxDependent = isCtxDependent # e.g., $i ref in pred
110
+
111
+ def eval(self, parser:Recognizer , outerContext:RuleContext ):
112
+ localctx = outerContext if self.isCtxDependent else None
113
+ return parser.sempred(localctx, self.ruleIndex, self.predIndex)
114
+
115
+ def __hash__(self):
116
+ return hash((self.ruleIndex, self.predIndex, self.isCtxDependent))
117
+
118
+ def __eq__(self, other):
119
+ if self is other:
120
+ return True
121
+ elif not isinstance(other, Predicate):
122
+ return False
123
+ return self.ruleIndex == other.ruleIndex and \
124
+ self.predIndex == other.predIndex and \
125
+ self.isCtxDependent == other.isCtxDependent
126
+
127
+ def __str__(self):
128
+ return "{" + str(self.ruleIndex) + ":" + str(self.predIndex) + "}?"
129
+
130
+
131
+ class PrecedencePredicate(SemanticContext):
132
+
133
+ def __init__(self, precedence:int=0):
134
+ self.precedence = precedence
135
+
136
+ def eval(self, parser:Recognizer , outerContext:RuleContext ):
137
+ return parser.precpred(outerContext, self.precedence)
138
+
139
+ def evalPrecedence(self, parser:Recognizer, outerContext:RuleContext):
140
+ if parser.precpred(outerContext, self.precedence):
141
+ return SemanticContext.NONE
142
+ else:
143
+ return None
144
+
145
+ def __lt__(self, other):
146
+ return self.precedence < other.precedence
147
+
148
+ def __hash__(self):
149
+ return 31
150
+
151
+ def __eq__(self, other):
152
+ if self is other:
153
+ return True
154
+ elif not isinstance(other, PrecedencePredicate):
155
+ return False
156
+ else:
157
+ return self.precedence == other.precedence
158
+
159
+ def __str__(self):
160
+ return "{" + str(self.precedence) + ">=prec}?"
161
+
162
+
163
+ # A semantic context which is true whenever none of the contained contexts
164
+ # is false.
165
+ del AND
166
+ class AND(SemanticContext):
167
+ __slots__ = 'opnds'
168
+
169
+ def __init__(self, a:SemanticContext, b:SemanticContext):
170
+ operands = set()
171
+ if isinstance( a, AND ):
172
+ operands.update(a.opnds)
173
+ else:
174
+ operands.add(a)
175
+ if isinstance( b, AND ):
176
+ operands.update(b.opnds)
177
+ else:
178
+ operands.add(b)
179
+
180
+ precedencePredicates = filterPrecedencePredicates(operands)
181
+ if len(precedencePredicates)>0:
182
+ # interested in the transition with the lowest precedence
183
+ reduced = min(precedencePredicates)
184
+ operands.add(reduced)
185
+
186
+ self.opnds = list(operands)
187
+
188
+ def __eq__(self, other):
189
+ if self is other:
190
+ return True
191
+ elif not isinstance(other, AND):
192
+ return False
193
+ else:
194
+ return self.opnds == other.opnds
195
+
196
+ def __hash__(self):
197
+ h = 0
198
+ for o in self.opnds:
199
+ h = hash((h, o))
200
+ return hash((h, "AND"))
201
+
202
+ #
203
+ # {@inheritDoc}
204
+ #
205
+ # <p>
206
+ # The evaluation of predicates by this context is short-circuiting, but
207
+ # unordered.</p>
208
+ #
209
+ def eval(self, parser:Recognizer, outerContext:RuleContext):
210
+ return all(opnd.eval(parser, outerContext) for opnd in self.opnds)
211
+
212
+ def evalPrecedence(self, parser:Recognizer, outerContext:RuleContext):
213
+ differs = False
214
+ operands = []
215
+ for context in self.opnds:
216
+ evaluated = context.evalPrecedence(parser, outerContext)
217
+ differs |= evaluated is not context
218
+ if evaluated is None:
219
+ # The AND context is false if any element is false
220
+ return None
221
+ elif evaluated is not SemanticContext.NONE:
222
+ # Reduce the result by skipping true elements
223
+ operands.append(evaluated)
224
+
225
+ if not differs:
226
+ return self
227
+
228
+ if len(operands)==0:
229
+ # all elements were true, so the AND context is true
230
+ return SemanticContext.NONE
231
+
232
+ result = None
233
+ for o in operands:
234
+ result = o if result is None else andContext(result, o)
235
+
236
+ return result
237
+
238
+ def __str__(self):
239
+ with StringIO() as buf:
240
+ first = True
241
+ for o in self.opnds:
242
+ if not first:
243
+ buf.write("&&")
244
+ buf.write(str(o))
245
+ first = False
246
+ return buf.getvalue()
247
+
248
+ #
249
+ # A semantic context which is true whenever at least one of the contained
250
+ # contexts is true.
251
+ del OR
252
+ class OR (SemanticContext):
253
+ __slots__ = 'opnds'
254
+
255
+ def __init__(self, a:SemanticContext, b:SemanticContext):
256
+ operands = set()
257
+ if isinstance( a, OR ):
258
+ operands.update(a.opnds)
259
+ else:
260
+ operands.add(a)
261
+ if isinstance( b, OR ):
262
+ operands.update(b.opnds)
263
+ else:
264
+ operands.add(b)
265
+
266
+ precedencePredicates = filterPrecedencePredicates(operands)
267
+ if len(precedencePredicates)>0:
268
+ # interested in the transition with the highest precedence
269
+ s = sorted(precedencePredicates)
270
+ reduced = s[-1]
271
+ operands.add(reduced)
272
+
273
+ self.opnds = list(operands)
274
+
275
+ def __eq__(self, other):
276
+ if self is other:
277
+ return True
278
+ elif not isinstance(other, OR):
279
+ return False
280
+ else:
281
+ return self.opnds == other.opnds
282
+
283
+ def __hash__(self):
284
+ h = 0
285
+ for o in self.opnds:
286
+ h = hash((h, o))
287
+ return hash((h, "OR"))
288
+
289
+ # <p>
290
+ # The evaluation of predicates by this context is short-circuiting, but
291
+ # unordered.</p>
292
+ #
293
+ def eval(self, parser:Recognizer, outerContext:RuleContext):
294
+ return any(opnd.eval(parser, outerContext) for opnd in self.opnds)
295
+
296
+ def evalPrecedence(self, parser:Recognizer, outerContext:RuleContext):
297
+ differs = False
298
+ operands = []
299
+ for context in self.opnds:
300
+ evaluated = context.evalPrecedence(parser, outerContext)
301
+ differs |= evaluated is not context
302
+ if evaluated is SemanticContext.NONE:
303
+ # The OR context is true if any element is true
304
+ return SemanticContext.NONE
305
+ elif evaluated is not None:
306
+ # Reduce the result by skipping false elements
307
+ operands.append(evaluated)
308
+
309
+ if not differs:
310
+ return self
311
+
312
+ if len(operands)==0:
313
+ # all elements were false, so the OR context is false
314
+ return None
315
+
316
+ result = None
317
+ for o in operands:
318
+ result = o if result is None else orContext(result, o)
319
+
320
+ return result
321
+
322
+ def __str__(self):
323
+ with StringIO() as buf:
324
+ first = True
325
+ for o in self.opnds:
326
+ if not first:
327
+ buf.write("||")
328
+ buf.write(str(o))
329
+ first = False
330
+ return buf.getvalue()
331
+
332
+
333
+ SemanticContext.NONE = EmptySemanticContext()
@@ -0,0 +1,271 @@
1
+ # type: ignore
2
+ # ruff: noqa
3
+ # flake8: noqa
4
+ #
5
+ # Copyright (c) 2012-2017 The ANTLR Project. All rights reserved.
6
+ # Use of this file is governed by the BSD 3-clause license that
7
+ # can be found in the LICENSE.txt file in the project root.
8
+ #
9
+
10
+ # An ATN transition between any two ATN states. Subclasses define
11
+ # atom, set, epsilon, action, predicate, rule transitions.
12
+ #
13
+ # <p>This is a one way link. It emanates from a state (usually via a list of
14
+ # transitions) and has a target state.</p>
15
+ #
16
+ # <p>Since we never have to change the ATN transitions once we construct it,
17
+ # we can fix these transitions as specific classes. The DFA transitions
18
+ # on the other hand need to update the labels as it adds transitions to
19
+ # the states. We'll use the term Edge for the DFA to distinguish them from
20
+ # ATN transitions.</p>
21
+ #
22
+ from ..IntervalSet import IntervalSet
23
+ from ..Token import Token
24
+
25
+ # need forward declarations
26
+ from .SemanticContext import Predicate, PrecedencePredicate
27
+
28
+ ATNState = None
29
+ RuleStartState = None
30
+
31
+ class Transition (object):
32
+ __slots__ = ('target','isEpsilon','label')
33
+
34
+ # constants for serialization
35
+ EPSILON = 1
36
+ RANGE = 2
37
+ RULE = 3
38
+ PREDICATE = 4 # e.g., {isType(input.LT(1))}?
39
+ ATOM = 5
40
+ ACTION = 6
41
+ SET = 7 # ~(A|B) or ~atom, wildcard, which convert to next 2
42
+ NOT_SET = 8
43
+ WILDCARD = 9
44
+ PRECEDENCE = 10
45
+
46
+ serializationNames = [
47
+ "INVALID",
48
+ "EPSILON",
49
+ "RANGE",
50
+ "RULE",
51
+ "PREDICATE",
52
+ "ATOM",
53
+ "ACTION",
54
+ "SET",
55
+ "NOT_SET",
56
+ "WILDCARD",
57
+ "PRECEDENCE"
58
+ ]
59
+
60
+ serializationTypes = dict()
61
+
62
+ def __init__(self, target:ATNState):
63
+ # The target of this transition.
64
+ if target is None:
65
+ raise Exception("target cannot be null.")
66
+ self.target = target
67
+ # Are we epsilon, action, sempred?
68
+ self.isEpsilon = False
69
+ self.label = None
70
+
71
+
72
+ # TODO: make all transitions sets? no, should remove set edges
73
+ class AtomTransition(Transition):
74
+ __slots__ = ('label_', 'serializationType')
75
+
76
+ def __init__(self, target:ATNState, label:int):
77
+ super().__init__(target)
78
+ self.label_ = label # The token type or character value; or, signifies special label.
79
+ self.label = self.makeLabel()
80
+ self.serializationType = self.ATOM
81
+
82
+ def makeLabel(self):
83
+ s = IntervalSet()
84
+ s.addOne(self.label_)
85
+ return s
86
+
87
+ def matches( self, symbol:int, minVocabSymbol:int, maxVocabSymbol:int):
88
+ return self.label_ == symbol
89
+
90
+ def __str__(self):
91
+ return str(self.label_)
92
+
93
+ class RuleTransition(Transition):
94
+ __slots__ = ('ruleIndex', 'precedence', 'followState', 'serializationType')
95
+
96
+ def __init__(self, ruleStart:RuleStartState, ruleIndex:int, precedence:int, followState:ATNState):
97
+ super().__init__(ruleStart)
98
+ self.ruleIndex = ruleIndex # ptr to the rule definition object for this rule ref
99
+ self.precedence = precedence
100
+ self.followState = followState # what node to begin computations following ref to rule
101
+ self.serializationType = self.RULE
102
+ self.isEpsilon = True
103
+
104
+ def matches( self, symbol:int, minVocabSymbol:int, maxVocabSymbol:int):
105
+ return False
106
+
107
+
108
+ class EpsilonTransition(Transition):
109
+ __slots__ = ('serializationType', 'outermostPrecedenceReturn')
110
+
111
+ def __init__(self, target, outermostPrecedenceReturn=-1):
112
+ super(EpsilonTransition, self).__init__(target)
113
+ self.serializationType = self.EPSILON
114
+ self.isEpsilon = True
115
+ self.outermostPrecedenceReturn = outermostPrecedenceReturn
116
+
117
+ def matches( self, symbol:int, minVocabSymbol:int, maxVocabSymbol:int):
118
+ return False
119
+
120
+ def __str__(self):
121
+ return "epsilon"
122
+
123
+ class RangeTransition(Transition):
124
+ __slots__ = ('serializationType', 'start', 'stop')
125
+
126
+ def __init__(self, target:ATNState, start:int, stop:int):
127
+ super().__init__(target)
128
+ self.serializationType = self.RANGE
129
+ self.start = start
130
+ self.stop = stop
131
+ self.label = self.makeLabel()
132
+
133
+ def makeLabel(self):
134
+ s = IntervalSet()
135
+ s.addRange(range(self.start, self.stop + 1))
136
+ return s
137
+
138
+ def matches( self, symbol:int, minVocabSymbol:int, maxVocabSymbol:int):
139
+ return symbol >= self.start and symbol <= self.stop
140
+
141
+ def __str__(self):
142
+ return "'" + chr(self.start) + "'..'" + chr(self.stop) + "'"
143
+
144
+ class AbstractPredicateTransition(Transition):
145
+
146
+ def __init__(self, target:ATNState):
147
+ super().__init__(target)
148
+
149
+
150
+ class PredicateTransition(AbstractPredicateTransition):
151
+ __slots__ = ('serializationType', 'ruleIndex', 'predIndex', 'isCtxDependent')
152
+
153
+ def __init__(self, target:ATNState, ruleIndex:int, predIndex:int, isCtxDependent:bool):
154
+ super().__init__(target)
155
+ self.serializationType = self.PREDICATE
156
+ self.ruleIndex = ruleIndex
157
+ self.predIndex = predIndex
158
+ self.isCtxDependent = isCtxDependent # e.g., $i ref in pred
159
+ self.isEpsilon = True
160
+
161
+ def matches( self, symbol:int, minVocabSymbol:int, maxVocabSymbol:int):
162
+ return False
163
+
164
+ def getPredicate(self):
165
+ return Predicate(self.ruleIndex, self.predIndex, self.isCtxDependent)
166
+
167
+ def __str__(self):
168
+ return "pred_" + str(self.ruleIndex) + ":" + str(self.predIndex)
169
+
170
+ class ActionTransition(Transition):
171
+ __slots__ = ('serializationType', 'ruleIndex', 'actionIndex', 'isCtxDependent')
172
+
173
+ def __init__(self, target:ATNState, ruleIndex:int, actionIndex:int=-1, isCtxDependent:bool=False):
174
+ super().__init__(target)
175
+ self.serializationType = self.ACTION
176
+ self.ruleIndex = ruleIndex
177
+ self.actionIndex = actionIndex
178
+ self.isCtxDependent = isCtxDependent # e.g., $i ref in pred
179
+ self.isEpsilon = True
180
+
181
+ def matches( self, symbol:int, minVocabSymbol:int, maxVocabSymbol:int):
182
+ return False
183
+
184
+ def __str__(self):
185
+ return "action_"+self.ruleIndex+":"+self.actionIndex
186
+
187
+ # A transition containing a set of values.
188
+ class SetTransition(Transition):
189
+ __slots__ = 'serializationType'
190
+
191
+ def __init__(self, target:ATNState, set:IntervalSet):
192
+ super().__init__(target)
193
+ self.serializationType = self.SET
194
+ if set is not None:
195
+ self.label = set
196
+ else:
197
+ self.label = IntervalSet()
198
+ self.label.addRange(range(Token.INVALID_TYPE, Token.INVALID_TYPE + 1))
199
+
200
+ def matches( self, symbol:int, minVocabSymbol:int, maxVocabSymbol:int):
201
+ return symbol in self.label
202
+
203
+ def __str__(self):
204
+ return str(self.label)
205
+
206
+ class NotSetTransition(SetTransition):
207
+
208
+ def __init__(self, target:ATNState, set:IntervalSet):
209
+ super().__init__(target, set)
210
+ self.serializationType = self.NOT_SET
211
+
212
+ def matches( self, symbol:int, minVocabSymbol:int, maxVocabSymbol:int):
213
+ return symbol >= minVocabSymbol \
214
+ and symbol <= maxVocabSymbol \
215
+ and not super(type(self), self).matches(symbol, minVocabSymbol, maxVocabSymbol)
216
+
217
+ def __str__(self):
218
+ return '~' + super(type(self), self).__str__()
219
+
220
+
221
+ class WildcardTransition(Transition):
222
+ __slots__ = 'serializationType'
223
+
224
+ def __init__(self, target:ATNState):
225
+ super().__init__(target)
226
+ self.serializationType = self.WILDCARD
227
+
228
+ def matches( self, symbol:int, minVocabSymbol:int, maxVocabSymbol:int):
229
+ return symbol >= minVocabSymbol and symbol <= maxVocabSymbol
230
+
231
+ def __str__(self):
232
+ return "."
233
+
234
+
235
+ class PrecedencePredicateTransition(AbstractPredicateTransition):
236
+ __slots__ = ('serializationType', 'precedence')
237
+
238
+ def __init__(self, target:ATNState, precedence:int):
239
+ super().__init__(target)
240
+ self.serializationType = self.PRECEDENCE
241
+ self.precedence = precedence
242
+ self.isEpsilon = True
243
+
244
+ def matches( self, symbol:int, minVocabSymbol:int, maxVocabSymbol:int):
245
+ return False
246
+
247
+
248
+ def getPredicate(self):
249
+ return PrecedencePredicate(self.precedence)
250
+
251
+ def __str__(self):
252
+ return self.precedence + " >= _p"
253
+
254
+
255
+ Transition.serializationTypes = {
256
+ EpsilonTransition: Transition.EPSILON,
257
+ RangeTransition: Transition.RANGE,
258
+ RuleTransition: Transition.RULE,
259
+ PredicateTransition: Transition.PREDICATE,
260
+ AtomTransition: Transition.ATOM,
261
+ ActionTransition: Transition.ACTION,
262
+ SetTransition: Transition.SET,
263
+ NotSetTransition: Transition.NOT_SET,
264
+ WildcardTransition: Transition.WILDCARD,
265
+ PrecedencePredicateTransition: Transition.PRECEDENCE
266
+ }
267
+
268
+ del ATNState
269
+ del RuleStartState
270
+
271
+ from .ATNState import *
@@ -0,0 +1,4 @@
1
+ # type: ignore
2
+ # ruff: noqa
3
+ # flake8: noqa
4
+ __author__ = 'ericvergnaud'