omlish 0.0.0.dev57__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 (66) 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-0.0.0.dev57.dist-info → omlish-0.0.0.dev58.dist-info}/METADATA +1 -1
  62. {omlish-0.0.0.dev57.dist-info → omlish-0.0.0.dev58.dist-info}/RECORD +66 -7
  63. {omlish-0.0.0.dev57.dist-info → omlish-0.0.0.dev58.dist-info}/LICENSE +0 -0
  64. {omlish-0.0.0.dev57.dist-info → omlish-0.0.0.dev58.dist-info}/WHEEL +0 -0
  65. {omlish-0.0.0.dev57.dist-info → omlish-0.0.0.dev58.dist-info}/entry_points.txt +0 -0
  66. {omlish-0.0.0.dev57.dist-info → omlish-0.0.0.dev58.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,162 @@
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 tuple: (ATN state, predicted alt, syntactic, semantic context).
11
+ # The syntactic context is a graph-structured stack node whose
12
+ # path(s) to the root is the rule invocation(s)
13
+ # chain used to arrive at the state. The semantic context is
14
+ # the tree of semantic predicates encountered before reaching
15
+ # an ATN state.
16
+ #/
17
+ from io import StringIO
18
+ from ..PredictionContext import PredictionContext
19
+ from .ATNState import ATNState, DecisionState
20
+ from .LexerActionExecutor import LexerActionExecutor
21
+ from .SemanticContext import SemanticContext
22
+
23
+ # need a forward declaration
24
+ ATNConfig = None
25
+
26
+ class ATNConfig(object):
27
+ __slots__ = (
28
+ 'state', 'alt', 'context', 'semanticContext', 'reachesIntoOuterContext',
29
+ 'precedenceFilterSuppressed'
30
+ )
31
+
32
+ def __init__(self, state:ATNState=None, alt:int=None, context:PredictionContext=None, semantic:SemanticContext=None, config:ATNConfig=None):
33
+ if config is not None:
34
+ if state is None:
35
+ state = config.state
36
+ if alt is None:
37
+ alt = config.alt
38
+ if context is None:
39
+ context = config.context
40
+ if semantic is None:
41
+ semantic = config.semanticContext
42
+ if semantic is None:
43
+ semantic = SemanticContext.NONE
44
+ # The ATN state associated with this configuration#/
45
+ self.state = state
46
+ # What alt (or lexer rule) is predicted by this configuration#/
47
+ self.alt = alt
48
+ # The stack of invoking states leading to the rule/states associated
49
+ # with this config. We track only those contexts pushed during
50
+ # execution of the ATN simulator.
51
+ self.context = context
52
+ self.semanticContext = semantic
53
+ # We cannot execute predicates dependent upon local context unless
54
+ # we know for sure we are in the correct context. Because there is
55
+ # no way to do this efficiently, we simply cannot evaluate
56
+ # dependent predicates unless we are in the rule that initially
57
+ # invokes the ATN simulator.
58
+ #
59
+ # closure() tracks the depth of how far we dip into the
60
+ # outer context: depth > 0. Note that it may not be totally
61
+ # accurate depth since I don't ever decrement. TODO: make it a boolean then
62
+ self.reachesIntoOuterContext = 0 if config is None else config.reachesIntoOuterContext
63
+ self.precedenceFilterSuppressed = False if config is None else config.precedenceFilterSuppressed
64
+
65
+ # An ATN configuration is equal to another if both have
66
+ # the same state, they predict the same alternative, and
67
+ # syntactic/semantic contexts are the same.
68
+ #/
69
+ def __eq__(self, other):
70
+ if self is other:
71
+ return True
72
+ elif not isinstance(other, ATNConfig):
73
+ return False
74
+ else:
75
+ return self.state.stateNumber==other.state.stateNumber \
76
+ and self.alt==other.alt \
77
+ and ((self.context is other.context) or (self.context==other.context)) \
78
+ and self.semanticContext==other.semanticContext \
79
+ and self.precedenceFilterSuppressed==other.precedenceFilterSuppressed
80
+
81
+ def __hash__(self):
82
+ return hash((self.state.stateNumber, self.alt, self.context, self.semanticContext))
83
+
84
+ def hashCodeForConfigSet(self):
85
+ return hash((self.state.stateNumber, self.alt, hash(self.semanticContext)))
86
+
87
+ def equalsForConfigSet(self, other):
88
+ if self is other:
89
+ return True
90
+ elif not isinstance(other, ATNConfig):
91
+ return False
92
+ else:
93
+ return self.state.stateNumber==other.state.stateNumber \
94
+ and self.alt==other.alt \
95
+ and self.semanticContext==other.semanticContext
96
+
97
+ def __str__(self):
98
+ with StringIO() as buf:
99
+ buf.write('(')
100
+ buf.write(str(self.state))
101
+ buf.write(",")
102
+ buf.write(str(self.alt))
103
+ if self.context is not None:
104
+ buf.write(",[")
105
+ buf.write(str(self.context))
106
+ buf.write("]")
107
+ if self.semanticContext is not None and self.semanticContext is not SemanticContext.NONE:
108
+ buf.write(",")
109
+ buf.write(str(self.semanticContext))
110
+ if self.reachesIntoOuterContext>0:
111
+ buf.write(",up=")
112
+ buf.write(str(self.reachesIntoOuterContext))
113
+ buf.write(')')
114
+ return buf.getvalue()
115
+
116
+ # need a forward declaration
117
+ LexerATNConfig = None
118
+
119
+ class LexerATNConfig(ATNConfig):
120
+ __slots__ = ('lexerActionExecutor', 'passedThroughNonGreedyDecision')
121
+
122
+ def __init__(self, state:ATNState, alt:int=None, context:PredictionContext=None, semantic:SemanticContext=SemanticContext.NONE,
123
+ lexerActionExecutor:LexerActionExecutor=None, config:LexerATNConfig=None):
124
+ super().__init__(state=state, alt=alt, context=context, semantic=semantic, config=config)
125
+ if config is not None:
126
+ if lexerActionExecutor is None:
127
+ lexerActionExecutor = config.lexerActionExecutor
128
+ # This is the backing field for {@link #getLexerActionExecutor}.
129
+ self.lexerActionExecutor = lexerActionExecutor
130
+ self.passedThroughNonGreedyDecision = False if config is None else self.checkNonGreedyDecision(config, state)
131
+
132
+ def __hash__(self):
133
+ return hash((self.state.stateNumber, self.alt, self.context,
134
+ self.semanticContext, self.passedThroughNonGreedyDecision,
135
+ self.lexerActionExecutor))
136
+
137
+ def __eq__(self, other):
138
+ if self is other:
139
+ return True
140
+ elif not isinstance(other, LexerATNConfig):
141
+ return False
142
+ if self.passedThroughNonGreedyDecision != other.passedThroughNonGreedyDecision:
143
+ return False
144
+ if not(self.lexerActionExecutor == other.lexerActionExecutor):
145
+ return False
146
+ return super().__eq__(other)
147
+
148
+
149
+
150
+ def hashCodeForConfigSet(self):
151
+ return hash(self)
152
+
153
+
154
+
155
+ def equalsForConfigSet(self, other):
156
+ return self==other
157
+
158
+
159
+
160
+ def checkNonGreedyDecision(self, source:LexerATNConfig, target:ATNState):
161
+ return source.passedThroughNonGreedyDecision \
162
+ or isinstance(target, DecisionState) and target.nonGreedy
@@ -0,0 +1,215 @@
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
+ from ..PredictionContext import merge
10
+ from ..Utils import str_list
11
+ from .ATN import ATN
12
+ from .ATNConfig import ATNConfig
13
+ from .SemanticContext import SemanticContext
14
+ from ..error.Errors import UnsupportedOperationException, IllegalStateException
15
+ from functools import reduce
16
+ #
17
+ # Specialized {@link Set}{@code <}{@link ATNConfig}{@code >} that can track
18
+ # info about the set, with support for combining similar configurations using a
19
+ # graph-structured stack.
20
+ # /
21
+ from io import StringIO
22
+
23
+ ATNSimulator = None
24
+
25
+ class ATNConfigSet(object):
26
+ __slots__ = (
27
+ 'configLookup', 'fullCtx', 'readonly', 'configs', 'uniqueAlt',
28
+ 'conflictingAlts', 'hasSemanticContext', 'dipsIntoOuterContext',
29
+ 'cachedHashCode'
30
+ )
31
+
32
+ #
33
+ # The reason that we need this is because we don't want the hash map to use
34
+ # the standard hash code and equals. We need all configurations with the same
35
+ # {@code (s,i,_,semctx)} to be equal. Unfortunately, this key effectively doubles
36
+ # the number of objects associated with ATNConfigs. The other solution is to
37
+ # use a hash table that lets us specify the equals/hashcode operation.
38
+
39
+ def __init__(self, fullCtx:bool=True):
40
+ # All configs but hashed by (s, i, _, pi) not including context. Wiped out
41
+ # when we go readonly as this set becomes a DFA state.
42
+ self.configLookup = dict()
43
+ # Indicates that this configuration set is part of a full context
44
+ # LL prediction. It will be used to determine how to merge $. With SLL
45
+ # it's a wildcard whereas it is not for LL context merge.
46
+ self.fullCtx = fullCtx
47
+ # Indicates that the set of configurations is read-only. Do not
48
+ # allow any code to manipulate the set; DFA states will point at
49
+ # the sets and they must not change. This does not protect the other
50
+ # fields; in particular, conflictingAlts is set after
51
+ # we've made this readonly.
52
+ self.readonly = False
53
+ # Track the elements as they are added to the set; supports get(i)#/
54
+ self.configs = []
55
+
56
+ # TODO: these fields make me pretty uncomfortable but nice to pack up info together, saves recomputation
57
+ # TODO: can we track conflicts as they are added to save scanning configs later?
58
+ self.uniqueAlt = 0
59
+ self.conflictingAlts = None
60
+
61
+ # Used in parser and lexer. In lexer, it indicates we hit a pred
62
+ # while computing a closure operation. Don't make a DFA state from this.
63
+ self.hasSemanticContext = False
64
+ self.dipsIntoOuterContext = False
65
+
66
+ self.cachedHashCode = -1
67
+
68
+ def __iter__(self):
69
+ return self.configs.__iter__()
70
+
71
+ # Adding a new config means merging contexts with existing configs for
72
+ # {@code (s, i, pi, _)}, where {@code s} is the
73
+ # {@link ATNConfig#state}, {@code i} is the {@link ATNConfig#alt}, and
74
+ # {@code pi} is the {@link ATNConfig#semanticContext}. We use
75
+ # {@code (s,i,pi)} as key.
76
+ #
77
+ # <p>This method updates {@link #dipsIntoOuterContext} and
78
+ # {@link #hasSemanticContext} when necessary.</p>
79
+ #/
80
+ def add(self, config:ATNConfig, mergeCache=None):
81
+ if self.readonly:
82
+ raise Exception("This set is readonly")
83
+ if config.semanticContext is not SemanticContext.NONE:
84
+ self.hasSemanticContext = True
85
+ if config.reachesIntoOuterContext > 0:
86
+ self.dipsIntoOuterContext = True
87
+ existing = self.getOrAdd(config)
88
+ if existing is config:
89
+ self.cachedHashCode = -1
90
+ self.configs.append(config) # track order here
91
+ return True
92
+ # a previous (s,i,pi,_), merge with it and save result
93
+ rootIsWildcard = not self.fullCtx
94
+ merged = merge(existing.context, config.context, rootIsWildcard, mergeCache)
95
+ # no need to check for existing.context, config.context in cache
96
+ # since only way to create new graphs is "call rule" and here.
97
+ # We cache at both places.
98
+ existing.reachesIntoOuterContext = max(existing.reachesIntoOuterContext, config.reachesIntoOuterContext)
99
+ # make sure to preserve the precedence filter suppression during the merge
100
+ if config.precedenceFilterSuppressed:
101
+ existing.precedenceFilterSuppressed = True
102
+ existing.context = merged # replace context; no need to alt mapping
103
+ return True
104
+
105
+ def getOrAdd(self, config:ATNConfig):
106
+ h = config.hashCodeForConfigSet()
107
+ l = self.configLookup.get(h, None)
108
+ if l is not None:
109
+ r = next((cfg for cfg in l if config.equalsForConfigSet(cfg)), None)
110
+ if r is not None:
111
+ return r
112
+ if l is None:
113
+ l = [config]
114
+ self.configLookup[h] = l
115
+ else:
116
+ l.append(config)
117
+ return config
118
+
119
+ def getStates(self):
120
+ return set(c.state for c in self.configs)
121
+
122
+ def getPredicates(self):
123
+ return list(cfg.semanticContext for cfg in self.configs if cfg.semanticContext!=SemanticContext.NONE)
124
+
125
+ def get(self, i:int):
126
+ return self.configs[i]
127
+
128
+ def optimizeConfigs(self, interpreter:ATNSimulator):
129
+ if self.readonly:
130
+ raise IllegalStateException("This set is readonly")
131
+ if len(self.configs)==0:
132
+ return
133
+ for config in self.configs:
134
+ config.context = interpreter.getCachedContext(config.context)
135
+
136
+ def addAll(self, coll:list):
137
+ for c in coll:
138
+ self.add(c)
139
+ return False
140
+
141
+ def __eq__(self, other):
142
+ if self is other:
143
+ return True
144
+ elif not isinstance(other, ATNConfigSet):
145
+ return False
146
+
147
+ same = self.configs is not None and \
148
+ self.configs==other.configs and \
149
+ self.fullCtx == other.fullCtx and \
150
+ self.uniqueAlt == other.uniqueAlt and \
151
+ self.conflictingAlts == other.conflictingAlts and \
152
+ self.hasSemanticContext == other.hasSemanticContext and \
153
+ self.dipsIntoOuterContext == other.dipsIntoOuterContext
154
+
155
+ return same
156
+
157
+ def __hash__(self):
158
+ if self.readonly:
159
+ if self.cachedHashCode == -1:
160
+ self.cachedHashCode = self.hashConfigs()
161
+ return self.cachedHashCode
162
+ return self.hashConfigs()
163
+
164
+ def hashConfigs(self):
165
+ return reduce(lambda h, cfg: hash((h, cfg)), self.configs, 0)
166
+
167
+ def __len__(self):
168
+ return len(self.configs)
169
+
170
+ def isEmpty(self):
171
+ return len(self.configs)==0
172
+
173
+ def __contains__(self, config):
174
+ if self.configLookup is None:
175
+ raise UnsupportedOperationException("This method is not implemented for readonly sets.")
176
+ h = config.hashCodeForConfigSet()
177
+ l = self.configLookup.get(h, None)
178
+ if l is not None:
179
+ for c in l:
180
+ if config.equalsForConfigSet(c):
181
+ return True
182
+ return False
183
+
184
+ def clear(self):
185
+ if self.readonly:
186
+ raise IllegalStateException("This set is readonly")
187
+ self.configs.clear()
188
+ self.cachedHashCode = -1
189
+ self.configLookup.clear()
190
+
191
+ def setReadonly(self, readonly:bool):
192
+ self.readonly = readonly
193
+ self.configLookup = None # can't mod, no need for lookup cache
194
+
195
+ def __str__(self):
196
+ with StringIO() as buf:
197
+ buf.write(str_list(self.configs))
198
+ if self.hasSemanticContext:
199
+ buf.write(",hasSemanticContext=")
200
+ buf.write(str(self.hasSemanticContext).lower()) # lower() to conform to java output
201
+ if self.uniqueAlt!=ATN.INVALID_ALT_NUMBER:
202
+ buf.write(",uniqueAlt=")
203
+ buf.write(str(self.uniqueAlt))
204
+ if self.conflictingAlts is not None:
205
+ buf.write(",conflictingAlts=")
206
+ buf.write(str(self.conflictingAlts))
207
+ if self.dipsIntoOuterContext:
208
+ buf.write(",dipsIntoOuterContext")
209
+ return buf.getvalue()
210
+
211
+
212
+ class OrderedATNConfigSet(ATNConfigSet):
213
+
214
+ def __init__(self):
215
+ super().__init__()
@@ -0,0 +1,27 @@
1
+ # type: ignore
2
+ # ruff: noqa
3
+ # flake8: noqa
4
+ # Copyright (c) 2012-2017 The ANTLR Project. All rights reserved.
5
+ # Use of this file is governed by the BSD 3-clause license that
6
+ # can be found in the LICENSE.txt file in the project root.
7
+
8
+ # need a forward declaration
9
+ ATNDeserializationOptions = None
10
+
11
+ class ATNDeserializationOptions(object):
12
+ __slots__ = ('readonly', 'verifyATN', 'generateRuleBypassTransitions')
13
+
14
+ defaultOptions = None
15
+
16
+ def __init__(self, copyFrom:ATNDeserializationOptions = None):
17
+ self.readonly = False
18
+ self.verifyATN = True if copyFrom is None else copyFrom.verifyATN
19
+ self.generateRuleBypassTransitions = False if copyFrom is None else copyFrom.generateRuleBypassTransitions
20
+
21
+ def __setattr__(self, key, value):
22
+ if key!="readonly" and self.readonly:
23
+ raise Exception("The object is read only.")
24
+ super(type(self), self).__setattr__(key,value)
25
+
26
+ ATNDeserializationOptions.defaultOptions = ATNDeserializationOptions()
27
+ ATNDeserializationOptions.defaultOptions.readonly = True