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,173 @@
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 parser simulator that mimics what ANTLR's generated
11
+ # parser code does. A ParserATNSimulator is used to make
12
+ # predictions via adaptivePredict but this class moves a pointer through the
13
+ # ATN to simulate parsing. ParserATNSimulator just
14
+ # makes us efficient rather than having to backtrack, for example.
15
+ #
16
+ # This properly creates parse trees even for left recursive rules.
17
+ #
18
+ # We rely on the left recursive rule invocation and special predicate
19
+ # transitions to make left recursive rules work.
20
+ #
21
+ # See TestParserInterpreter for examples.
22
+ #
23
+ from .dfa.DFA import DFA
24
+ from .BufferedTokenStream import TokenStream
25
+ from .Lexer import Lexer
26
+ from .Parser import Parser
27
+ from .ParserRuleContext import InterpreterRuleContext, ParserRuleContext
28
+ from .Token import Token
29
+ from .atn.ATN import ATN
30
+ from .atn.ATNState import StarLoopEntryState, ATNState, LoopEndState
31
+ from .atn.ParserATNSimulator import ParserATNSimulator
32
+ from .PredictionContext import PredictionContextCache
33
+ from .atn.Transition import Transition
34
+ from .error.Errors import RecognitionException, UnsupportedOperationException, FailedPredicateException
35
+
36
+
37
+ class ParserInterpreter(Parser):
38
+ __slots__ = (
39
+ 'grammarFileName', 'atn', 'tokenNames', 'ruleNames', 'decisionToDFA',
40
+ 'sharedContextCache', '_parentContextStack',
41
+ 'pushRecursionContextStates'
42
+ )
43
+
44
+ def __init__(self, grammarFileName:str, tokenNames:list, ruleNames:list, atn:ATN, input:TokenStream):
45
+ super().__init__(input)
46
+ self.grammarFileName = grammarFileName
47
+ self.atn = atn
48
+ self.tokenNames = tokenNames
49
+ self.ruleNames = ruleNames
50
+ self.decisionToDFA = [ DFA(state) for state in atn.decisionToState ]
51
+ self.sharedContextCache = PredictionContextCache()
52
+ self._parentContextStack = list()
53
+ # identify the ATN states where pushNewRecursionContext must be called
54
+ self.pushRecursionContextStates = set()
55
+ for state in atn.states:
56
+ if not isinstance(state, StarLoopEntryState):
57
+ continue
58
+ if state.isPrecedenceDecision:
59
+ self.pushRecursionContextStates.add(state.stateNumber)
60
+ # get atn simulator that knows how to do predictions
61
+ self._interp = ParserATNSimulator(self, atn, self.decisionToDFA, self.sharedContextCache)
62
+
63
+ # Begin parsing at startRuleIndex#
64
+ def parse(self, startRuleIndex:int):
65
+ startRuleStartState = self.atn.ruleToStartState[startRuleIndex]
66
+ rootContext = InterpreterRuleContext(None, ATNState.INVALID_STATE_NUMBER, startRuleIndex)
67
+ if startRuleStartState.isPrecedenceRule:
68
+ self.enterRecursionRule(rootContext, startRuleStartState.stateNumber, startRuleIndex, 0)
69
+ else:
70
+ self.enterRule(rootContext, startRuleStartState.stateNumber, startRuleIndex)
71
+ while True:
72
+ p = self.getATNState()
73
+ if p.stateType==ATNState.RULE_STOP :
74
+ # pop; return from rule
75
+ if len(self._ctx)==0:
76
+ if startRuleStartState.isPrecedenceRule:
77
+ result = self._ctx
78
+ parentContext = self._parentContextStack.pop()
79
+ self.unrollRecursionContexts(parentContext.a)
80
+ return result
81
+ else:
82
+ self.exitRule()
83
+ return rootContext
84
+ self.visitRuleStopState(p)
85
+
86
+ else:
87
+ try:
88
+ self.visitState(p)
89
+ except RecognitionException as e:
90
+ self.state = self.atn.ruleToStopState[p.ruleIndex].stateNumber
91
+ self._ctx.exception = e
92
+ self._errHandler.reportError(self, e)
93
+ self._errHandler.recover(self, e)
94
+
95
+ def enterRecursionRule(self, localctx:ParserRuleContext, state:int, ruleIndex:int, precedence:int):
96
+ self._parentContextStack.append((self._ctx, localctx.invokingState))
97
+ super().enterRecursionRule(localctx, state, ruleIndex, precedence)
98
+
99
+ def getATNState(self):
100
+ return self.atn.states[self.state]
101
+
102
+ def visitState(self, p:ATNState):
103
+ edge = 0
104
+ if len(p.transitions) > 1:
105
+ self._errHandler.sync(self)
106
+ edge = self._interp.adaptivePredict(self._input, p.decision, self._ctx)
107
+ else:
108
+ edge = 1
109
+
110
+ transition = p.transitions[edge - 1]
111
+ tt = transition.serializationType
112
+ if tt==Transition.EPSILON:
113
+
114
+ if self.pushRecursionContextStates[p.stateNumber] and not isinstance(transition.target, LoopEndState):
115
+ t = self._parentContextStack[-1]
116
+ ctx = InterpreterRuleContext(t[0], t[1], self._ctx.ruleIndex)
117
+ self.pushNewRecursionContext(ctx, self.atn.ruleToStartState[p.ruleIndex].stateNumber, self._ctx.ruleIndex)
118
+
119
+ elif tt==Transition.ATOM:
120
+
121
+ self.match(transition.label)
122
+
123
+ elif tt in [ Transition.RANGE, Transition.SET, Transition.NOT_SET]:
124
+
125
+ if not transition.matches(self._input.LA(1), Token.MIN_USER_TOKEN_TYPE, Lexer.MAX_CHAR_VALUE):
126
+ self._errHandler.recoverInline(self)
127
+ self.matchWildcard()
128
+
129
+ elif tt==Transition.WILDCARD:
130
+
131
+ self.matchWildcard()
132
+
133
+ elif tt==Transition.RULE:
134
+
135
+ ruleStartState = transition.target
136
+ ruleIndex = ruleStartState.ruleIndex
137
+ ctx = InterpreterRuleContext(self._ctx, p.stateNumber, ruleIndex)
138
+ if ruleStartState.isPrecedenceRule:
139
+ self.enterRecursionRule(ctx, ruleStartState.stateNumber, ruleIndex, transition.precedence)
140
+ else:
141
+ self.enterRule(ctx, transition.target.stateNumber, ruleIndex)
142
+
143
+ elif tt==Transition.PREDICATE:
144
+
145
+ if not self.sempred(self._ctx, transition.ruleIndex, transition.predIndex):
146
+ raise FailedPredicateException(self)
147
+
148
+ elif tt==Transition.ACTION:
149
+
150
+ self.action(self._ctx, transition.ruleIndex, transition.actionIndex)
151
+
152
+ elif tt==Transition.PRECEDENCE:
153
+
154
+ if not self.precpred(self._ctx, transition.precedence):
155
+ msg = "precpred(_ctx, " + str(transition.precedence) + ")"
156
+ raise FailedPredicateException(self, msg)
157
+
158
+ else:
159
+ raise UnsupportedOperationException("Unrecognized ATN transition type.")
160
+
161
+ self.state = transition.target.stateNumber
162
+
163
+ def visitRuleStopState(self, p:ATNState):
164
+ ruleStartState = self.atn.ruleToStartState[p.ruleIndex]
165
+ if ruleStartState.isPrecedenceRule:
166
+ parentContext = self._parentContextStack.pop()
167
+ self.unrollRecursionContexts(parentContext.a)
168
+ self.state = parentContext[1]
169
+ else:
170
+ self.exitRule()
171
+
172
+ ruleTransition = self.atn.states[self.state].transitions[0]
173
+ self.state = ruleTransition.followState.stateNumber
@@ -0,0 +1,189 @@
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
+ #* A rule invocation record for parsing.
9
+ #
10
+ # Contains all of the information about the current rule not stored in the
11
+ # RuleContext. It handles parse tree children list, Any ATN state
12
+ # tracing, and the default values available for rule indications:
13
+ # start, stop, rule index, current alt number, current
14
+ # ATN state.
15
+ #
16
+ # Subclasses made for each rule and grammar track the parameters,
17
+ # return values, locals, and labels specific to that rule. These
18
+ # are the objects that are returned from rules.
19
+ #
20
+ # Note text is not an actual field of a rule return value; it is computed
21
+ # from start and stop using the input stream's toString() method. I
22
+ # could add a ctor to this so that we can pass in and store the input
23
+ # stream, but I'm not sure we want to do that. It would seem to be undefined
24
+ # to get the .text property anyway if the rule matches tokens from multiple
25
+ # input streams.
26
+ #
27
+ # I do not use getters for fields of objects that are used simply to
28
+ # group values such as this aggregate. The getters/setters are there to
29
+ # satisfy the superclass interface.
30
+
31
+ from .RuleContext import RuleContext
32
+ from .Token import Token
33
+ from .tree.Tree import ParseTreeListener, ParseTree, TerminalNodeImpl, ErrorNodeImpl, TerminalNode, \
34
+ INVALID_INTERVAL
35
+
36
+ # need forward declaration
37
+ ParserRuleContext = None
38
+
39
+ class ParserRuleContext(RuleContext):
40
+ __slots__ = ('children', 'start', 'stop', 'exception')
41
+ def __init__(self, parent:ParserRuleContext = None, invokingStateNumber:int = None ):
42
+ super().__init__(parent, invokingStateNumber)
43
+ #* If we are debugging or building a parse tree for a visitor,
44
+ # we need to track all of the tokens and rule invocations associated
45
+ # with this rule's context. This is empty for parsing w/o tree constr.
46
+ # operation because we don't the need to track the details about
47
+ # how we parse this rule.
48
+ #/
49
+ self.children = None
50
+ self.start = None
51
+ self.stop = None
52
+ # The exception that forced this rule to return. If the rule successfully
53
+ # completed, this is {@code null}.
54
+ self.exception = None
55
+
56
+ #* COPY a ctx (I'm deliberately not using copy constructor)#/
57
+ #
58
+ # This is used in the generated parser code to flip a generic XContext
59
+ # node for rule X to a YContext for alt label Y. In that sense, it is
60
+ # not really a generic copy function.
61
+ #
62
+ # If we do an error sync() at start of a rule, we might add error nodes
63
+ # to the generic XContext so this function must copy those nodes to
64
+ # the YContext as well else they are lost!
65
+ #/
66
+ def copyFrom(self, ctx:ParserRuleContext):
67
+ # from RuleContext
68
+ self.parentCtx = ctx.parentCtx
69
+ self.invokingState = ctx.invokingState
70
+ self.children = None
71
+ self.start = ctx.start
72
+ self.stop = ctx.stop
73
+
74
+ # copy any error nodes to alt label node
75
+ if ctx.children is not None:
76
+ self.children = []
77
+ # reset parent pointer for any error nodes
78
+ for child in ctx.children:
79
+ if isinstance(child, ErrorNodeImpl):
80
+ self.children.append(child)
81
+ child.parentCtx = self
82
+
83
+ # Double dispatch methods for listeners
84
+ def enterRule(self, listener:ParseTreeListener):
85
+ pass
86
+
87
+ def exitRule(self, listener:ParseTreeListener):
88
+ pass
89
+
90
+ #* Does not set parent link; other add methods do that#/
91
+ def addChild(self, child:ParseTree):
92
+ if self.children is None:
93
+ self.children = []
94
+ self.children.append(child)
95
+ return child
96
+
97
+ #* Used by enterOuterAlt to toss out a RuleContext previously added as
98
+ # we entered a rule. If we have # label, we will need to remove
99
+ # generic ruleContext object.
100
+ #/
101
+ def removeLastChild(self):
102
+ if self.children is not None:
103
+ del self.children[len(self.children)-1]
104
+
105
+ def addTokenNode(self, token:Token):
106
+ node = TerminalNodeImpl(token)
107
+ self.addChild(node)
108
+ node.parentCtx = self
109
+ return node
110
+
111
+ def addErrorNode(self, badToken:Token):
112
+ node = ErrorNodeImpl(badToken)
113
+ self.addChild(node)
114
+ node.parentCtx = self
115
+ return node
116
+
117
+ def getChild(self, i:int, ttype:type = None):
118
+ if ttype is None:
119
+ return self.children[i] if len(self.children)>i else None
120
+ else:
121
+ for child in self.getChildren():
122
+ if not isinstance(child, ttype):
123
+ continue
124
+ if i==0:
125
+ return child
126
+ i -= 1
127
+ return None
128
+
129
+ def getChildren(self, predicate = None):
130
+ if self.children is not None:
131
+ for child in self.children:
132
+ if predicate is not None and not predicate(child):
133
+ continue
134
+ yield child
135
+
136
+ def getToken(self, ttype:int, i:int):
137
+ for child in self.getChildren():
138
+ if not isinstance(child, TerminalNode):
139
+ continue
140
+ if child.symbol.type != ttype:
141
+ continue
142
+ if i==0:
143
+ return child
144
+ i -= 1
145
+ return None
146
+
147
+ def getTokens(self, ttype:int ):
148
+ if self.getChildren() is None:
149
+ return []
150
+ tokens = []
151
+ for child in self.getChildren():
152
+ if not isinstance(child, TerminalNode):
153
+ continue
154
+ if child.symbol.type != ttype:
155
+ continue
156
+ tokens.append(child)
157
+ return tokens
158
+
159
+ def getTypedRuleContext(self, ctxType:type, i:int):
160
+ return self.getChild(i, ctxType)
161
+
162
+ def getTypedRuleContexts(self, ctxType:type):
163
+ children = self.getChildren()
164
+ if children is None:
165
+ return []
166
+ contexts = []
167
+ for child in children:
168
+ if not isinstance(child, ctxType):
169
+ continue
170
+ contexts.append(child)
171
+ return contexts
172
+
173
+ def getChildCount(self):
174
+ return len(self.children) if self.children else 0
175
+
176
+ def getSourceInterval(self):
177
+ if self.start is None or self.stop is None:
178
+ return INVALID_INTERVAL
179
+ else:
180
+ return (self.start.tokenIndex, self.stop.tokenIndex)
181
+
182
+
183
+ RuleContext.EMPTY = ParserRuleContext()
184
+
185
+ class InterpreterRuleContext(ParserRuleContext):
186
+
187
+ def __init__(self, parent:ParserRuleContext, invokingStateNumber:int, ruleIndex:int):
188
+ super().__init__(parent, invokingStateNumber)
189
+ self.ruleIndex = ruleIndex