omlish 0.0.0.dev57__py3-none-any.whl → 0.0.0.dev59__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.
- omlish/__about__.py +2 -2
- omlish/antlr/__init__.py +0 -0
- omlish/antlr/_runtime/BufferedTokenStream.py +305 -0
- omlish/antlr/_runtime/CommonTokenFactory.py +64 -0
- omlish/antlr/_runtime/CommonTokenStream.py +90 -0
- omlish/antlr/_runtime/FileStream.py +30 -0
- omlish/antlr/_runtime/InputStream.py +90 -0
- omlish/antlr/_runtime/IntervalSet.py +183 -0
- omlish/antlr/_runtime/LL1Analyzer.py +176 -0
- omlish/antlr/_runtime/Lexer.py +332 -0
- omlish/antlr/_runtime/ListTokenSource.py +147 -0
- omlish/antlr/_runtime/Parser.py +583 -0
- omlish/antlr/_runtime/ParserInterpreter.py +173 -0
- omlish/antlr/_runtime/ParserRuleContext.py +189 -0
- omlish/antlr/_runtime/PredictionContext.py +632 -0
- omlish/antlr/_runtime/Recognizer.py +150 -0
- omlish/antlr/_runtime/RuleContext.py +230 -0
- omlish/antlr/_runtime/StdinStream.py +14 -0
- omlish/antlr/_runtime/Token.py +158 -0
- omlish/antlr/_runtime/TokenStreamRewriter.py +258 -0
- omlish/antlr/_runtime/Utils.py +36 -0
- omlish/antlr/_runtime/__init__.py +24 -0
- omlish/antlr/_runtime/_pygrun.py +174 -0
- omlish/antlr/_runtime/atn/ATN.py +135 -0
- omlish/antlr/_runtime/atn/ATNConfig.py +162 -0
- omlish/antlr/_runtime/atn/ATNConfigSet.py +215 -0
- omlish/antlr/_runtime/atn/ATNDeserializationOptions.py +27 -0
- omlish/antlr/_runtime/atn/ATNDeserializer.py +449 -0
- omlish/antlr/_runtime/atn/ATNSimulator.py +50 -0
- omlish/antlr/_runtime/atn/ATNState.py +267 -0
- omlish/antlr/_runtime/atn/ATNType.py +20 -0
- omlish/antlr/_runtime/atn/LexerATNSimulator.py +573 -0
- omlish/antlr/_runtime/atn/LexerAction.py +301 -0
- omlish/antlr/_runtime/atn/LexerActionExecutor.py +146 -0
- omlish/antlr/_runtime/atn/ParserATNSimulator.py +1664 -0
- omlish/antlr/_runtime/atn/PredictionMode.py +502 -0
- omlish/antlr/_runtime/atn/SemanticContext.py +333 -0
- omlish/antlr/_runtime/atn/Transition.py +271 -0
- omlish/antlr/_runtime/atn/__init__.py +4 -0
- omlish/antlr/_runtime/dfa/DFA.py +136 -0
- omlish/antlr/_runtime/dfa/DFASerializer.py +76 -0
- omlish/antlr/_runtime/dfa/DFAState.py +129 -0
- omlish/antlr/_runtime/dfa/__init__.py +4 -0
- omlish/antlr/_runtime/error/DiagnosticErrorListener.py +110 -0
- omlish/antlr/_runtime/error/ErrorListener.py +75 -0
- omlish/antlr/_runtime/error/ErrorStrategy.py +712 -0
- omlish/antlr/_runtime/error/Errors.py +176 -0
- omlish/antlr/_runtime/error/__init__.py +4 -0
- omlish/antlr/_runtime/tree/Chunk.py +33 -0
- omlish/antlr/_runtime/tree/ParseTreeMatch.py +121 -0
- omlish/antlr/_runtime/tree/ParseTreePattern.py +75 -0
- omlish/antlr/_runtime/tree/ParseTreePatternMatcher.py +377 -0
- omlish/antlr/_runtime/tree/RuleTagToken.py +53 -0
- omlish/antlr/_runtime/tree/TokenTagToken.py +50 -0
- omlish/antlr/_runtime/tree/Tree.py +194 -0
- omlish/antlr/_runtime/tree/Trees.py +114 -0
- omlish/antlr/_runtime/tree/__init__.py +2 -0
- omlish/antlr/_runtime/xpath/XPath.py +272 -0
- omlish/antlr/_runtime/xpath/XPathLexer.py +98 -0
- omlish/antlr/_runtime/xpath/__init__.py +4 -0
- omlish/marshal/__init__.py +10 -5
- omlish/marshal/nop.py +18 -0
- omlish/marshal/primitives.py +16 -6
- {omlish-0.0.0.dev57.dist-info → omlish-0.0.0.dev59.dist-info}/METADATA +1 -1
- {omlish-0.0.0.dev57.dist-info → omlish-0.0.0.dev59.dist-info}/RECORD +69 -9
- {omlish-0.0.0.dev57.dist-info → omlish-0.0.0.dev59.dist-info}/LICENSE +0 -0
- {omlish-0.0.0.dev57.dist-info → omlish-0.0.0.dev59.dist-info}/WHEEL +0 -0
- {omlish-0.0.0.dev57.dist-info → omlish-0.0.0.dev59.dist-info}/entry_points.txt +0 -0
- {omlish-0.0.0.dev57.dist-info → omlish-0.0.0.dev59.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,176 @@
|
|
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
|
+
|
9
|
+
# need forward declaration
|
10
|
+
Token = None
|
11
|
+
Lexer = None
|
12
|
+
Parser = None
|
13
|
+
TokenStream = None
|
14
|
+
ATNConfigSet = None
|
15
|
+
ParserRulecontext = None
|
16
|
+
PredicateTransition = None
|
17
|
+
BufferedTokenStream = None
|
18
|
+
|
19
|
+
class UnsupportedOperationException(Exception):
|
20
|
+
|
21
|
+
def __init__(self, msg:str):
|
22
|
+
super().__init__(msg)
|
23
|
+
|
24
|
+
class IllegalStateException(Exception):
|
25
|
+
|
26
|
+
def __init__(self, msg:str):
|
27
|
+
super().__init__(msg)
|
28
|
+
|
29
|
+
class CancellationException(IllegalStateException):
|
30
|
+
|
31
|
+
def __init__(self, msg:str):
|
32
|
+
super().__init__(msg)
|
33
|
+
|
34
|
+
# The root of the ANTLR exception hierarchy. In general, ANTLR tracks just
|
35
|
+
# 3 kinds of errors: prediction errors, failed predicate errors, and
|
36
|
+
# mismatched input errors. In each case, the parser knows where it is
|
37
|
+
# in the input, where it is in the ATN, the rule invocation stack,
|
38
|
+
# and what kind of problem occurred.
|
39
|
+
|
40
|
+
from ..InputStream import InputStream
|
41
|
+
from ..ParserRuleContext import ParserRuleContext
|
42
|
+
from ..Recognizer import Recognizer
|
43
|
+
|
44
|
+
class RecognitionException(Exception):
|
45
|
+
|
46
|
+
|
47
|
+
def __init__(self, message:str=None, recognizer:Recognizer=None, input:InputStream=None, ctx:ParserRulecontext=None):
|
48
|
+
super().__init__(message)
|
49
|
+
self.message = message
|
50
|
+
self.recognizer = recognizer
|
51
|
+
self.input = input
|
52
|
+
self.ctx = ctx
|
53
|
+
# The current {@link Token} when an error occurred. Since not all streams
|
54
|
+
# support accessing symbols by index, we have to track the {@link Token}
|
55
|
+
# instance itself.
|
56
|
+
self.offendingToken = None
|
57
|
+
# Get the ATN state number the parser was in at the time the error
|
58
|
+
# occurred. For {@link NoViableAltException} and
|
59
|
+
# {@link LexerNoViableAltException} exceptions, this is the
|
60
|
+
# {@link DecisionState} number. For others, it is the state whose outgoing
|
61
|
+
# edge we couldn't match.
|
62
|
+
self.offendingState = -1
|
63
|
+
if recognizer is not None:
|
64
|
+
self.offendingState = recognizer.state
|
65
|
+
|
66
|
+
# <p>If the state number is not known, this method returns -1.</p>
|
67
|
+
|
68
|
+
#
|
69
|
+
# Gets the set of input symbols which could potentially follow the
|
70
|
+
# previously matched symbol at the time this exception was thrown.
|
71
|
+
#
|
72
|
+
# <p>If the set of expected tokens is not known and could not be computed,
|
73
|
+
# this method returns {@code null}.</p>
|
74
|
+
#
|
75
|
+
# @return The set of token types that could potentially follow the current
|
76
|
+
# state in the ATN, or {@code null} if the information is not available.
|
77
|
+
#/
|
78
|
+
def getExpectedTokens(self):
|
79
|
+
if self.recognizer is not None:
|
80
|
+
return self.recognizer.atn.getExpectedTokens(self.offendingState, self.ctx)
|
81
|
+
else:
|
82
|
+
return None
|
83
|
+
|
84
|
+
|
85
|
+
class LexerNoViableAltException(RecognitionException):
|
86
|
+
|
87
|
+
def __init__(self, lexer:Lexer, input:InputStream, startIndex:int, deadEndConfigs:ATNConfigSet):
|
88
|
+
super().__init__(message=None, recognizer=lexer, input=input, ctx=None)
|
89
|
+
self.startIndex = startIndex
|
90
|
+
self.deadEndConfigs = deadEndConfigs
|
91
|
+
self.message = ""
|
92
|
+
|
93
|
+
def __str__(self):
|
94
|
+
symbol = ""
|
95
|
+
if self.startIndex >= 0 and self.startIndex < self.input.size:
|
96
|
+
symbol = self.input.getText(self.startIndex, self.startIndex)
|
97
|
+
# TODO symbol = Utils.escapeWhitespace(symbol, false);
|
98
|
+
return "LexerNoViableAltException('" + symbol + "')"
|
99
|
+
|
100
|
+
# Indicates that the parser could not decide which of two or more paths
|
101
|
+
# to take based upon the remaining input. It tracks the starting token
|
102
|
+
# of the offending input and also knows where the parser was
|
103
|
+
# in the various paths when the error. Reported by reportNoViableAlternative()
|
104
|
+
#
|
105
|
+
class NoViableAltException(RecognitionException):
|
106
|
+
|
107
|
+
def __init__(self, recognizer:Parser, input:TokenStream=None, startToken:Token=None,
|
108
|
+
offendingToken:Token=None, deadEndConfigs:ATNConfigSet=None, ctx:ParserRuleContext=None):
|
109
|
+
if ctx is None:
|
110
|
+
ctx = recognizer._ctx
|
111
|
+
if offendingToken is None:
|
112
|
+
offendingToken = recognizer.getCurrentToken()
|
113
|
+
if startToken is None:
|
114
|
+
startToken = recognizer.getCurrentToken()
|
115
|
+
if input is None:
|
116
|
+
input = recognizer.getInputStream()
|
117
|
+
super().__init__(recognizer=recognizer, input=input, ctx=ctx)
|
118
|
+
# Which configurations did we try at input.index() that couldn't match input.LT(1)?#
|
119
|
+
self.deadEndConfigs = deadEndConfigs
|
120
|
+
# The token object at the start index; the input stream might
|
121
|
+
# not be buffering tokens so get a reference to it. (At the
|
122
|
+
# time the error occurred, of course the stream needs to keep a
|
123
|
+
# buffer all of the tokens but later we might not have access to those.)
|
124
|
+
self.startToken = startToken
|
125
|
+
self.offendingToken = offendingToken
|
126
|
+
|
127
|
+
# This signifies any kind of mismatched input exceptions such as
|
128
|
+
# when the current input does not match the expected token.
|
129
|
+
#
|
130
|
+
class InputMismatchException(RecognitionException):
|
131
|
+
|
132
|
+
def __init__(self, recognizer:Parser):
|
133
|
+
super().__init__(recognizer=recognizer, input=recognizer.getInputStream(), ctx=recognizer._ctx)
|
134
|
+
self.offendingToken = recognizer.getCurrentToken()
|
135
|
+
|
136
|
+
|
137
|
+
# A semantic predicate failed during validation. Validation of predicates
|
138
|
+
# occurs when normally parsing the alternative just like matching a token.
|
139
|
+
# Disambiguating predicate evaluation occurs when we test a predicate during
|
140
|
+
# prediction.
|
141
|
+
|
142
|
+
class FailedPredicateException(RecognitionException):
|
143
|
+
|
144
|
+
def __init__(self, recognizer:Parser, predicate:str=None, message:str=None):
|
145
|
+
super().__init__(message=self.formatMessage(predicate,message), recognizer=recognizer,
|
146
|
+
input=recognizer.getInputStream(), ctx=recognizer._ctx)
|
147
|
+
s = recognizer._interp.atn.states[recognizer.state]
|
148
|
+
trans = s.transitions[0]
|
149
|
+
from ..atn.Transition import PredicateTransition
|
150
|
+
if isinstance(trans, PredicateTransition):
|
151
|
+
self.ruleIndex = trans.ruleIndex
|
152
|
+
self.predicateIndex = trans.predIndex
|
153
|
+
else:
|
154
|
+
self.ruleIndex = 0
|
155
|
+
self.predicateIndex = 0
|
156
|
+
self.predicate = predicate
|
157
|
+
self.offendingToken = recognizer.getCurrentToken()
|
158
|
+
|
159
|
+
def formatMessage(self, predicate:str, message:str):
|
160
|
+
if message is not None:
|
161
|
+
return message
|
162
|
+
else:
|
163
|
+
return "failed predicate: {" + predicate + "}?"
|
164
|
+
|
165
|
+
class ParseCancellationException(CancellationException):
|
166
|
+
|
167
|
+
pass
|
168
|
+
|
169
|
+
del Token
|
170
|
+
del Lexer
|
171
|
+
del Parser
|
172
|
+
del TokenStream
|
173
|
+
del ATNConfigSet
|
174
|
+
del ParserRulecontext
|
175
|
+
del PredicateTransition
|
176
|
+
del BufferedTokenStream
|
@@ -0,0 +1,33 @@
|
|
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
|
+
class Chunk(object):
|
11
|
+
pass
|
12
|
+
|
13
|
+
class TagChunk(Chunk):
|
14
|
+
__slots__ = ('tag', 'label')
|
15
|
+
|
16
|
+
def __init__(self, tag:str, label:str=None):
|
17
|
+
self.tag = tag
|
18
|
+
self.label = label
|
19
|
+
|
20
|
+
def __str__(self):
|
21
|
+
if self.label is None:
|
22
|
+
return self.tag
|
23
|
+
else:
|
24
|
+
return self.label + ":" + self.tag
|
25
|
+
|
26
|
+
class TextChunk(Chunk):
|
27
|
+
__slots__ = 'text'
|
28
|
+
|
29
|
+
def __init__(self, text:str):
|
30
|
+
self.text = text
|
31
|
+
|
32
|
+
def __str__(self):
|
33
|
+
return "'" + self.text + "'"
|
@@ -0,0 +1,121 @@
|
|
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
|
+
|
11
|
+
#
|
12
|
+
# Represents the result of matching a {@link ParseTree} against a tree pattern.
|
13
|
+
#
|
14
|
+
from io import StringIO
|
15
|
+
from .ParseTreePattern import ParseTreePattern
|
16
|
+
from .Tree import ParseTree
|
17
|
+
|
18
|
+
|
19
|
+
class ParseTreeMatch(object):
|
20
|
+
__slots__ = ('tree', 'pattern', 'labels', 'mismatchedNode')
|
21
|
+
#
|
22
|
+
# Constructs a new instance of {@link ParseTreeMatch} from the specified
|
23
|
+
# parse tree and pattern.
|
24
|
+
#
|
25
|
+
# @param tree The parse tree to match against the pattern.
|
26
|
+
# @param pattern The parse tree pattern.
|
27
|
+
# @param labels A mapping from label names to collections of
|
28
|
+
# {@link ParseTree} objects located by the tree pattern matching process.
|
29
|
+
# @param mismatchedNode The first node which failed to match the tree
|
30
|
+
# pattern during the matching process.
|
31
|
+
#
|
32
|
+
# @exception IllegalArgumentException if {@code tree} is {@code null}
|
33
|
+
# @exception IllegalArgumentException if {@code pattern} is {@code null}
|
34
|
+
# @exception IllegalArgumentException if {@code labels} is {@code null}
|
35
|
+
#
|
36
|
+
def __init__(self, tree:ParseTree, pattern:ParseTreePattern, labels:dict, mismatchedNode:ParseTree):
|
37
|
+
if tree is None:
|
38
|
+
raise Exception("tree cannot be null")
|
39
|
+
if pattern is None:
|
40
|
+
raise Exception("pattern cannot be null")
|
41
|
+
if labels is None:
|
42
|
+
raise Exception("labels cannot be null")
|
43
|
+
self.tree = tree
|
44
|
+
self.pattern = pattern
|
45
|
+
self.labels = labels
|
46
|
+
self.mismatchedNode = mismatchedNode
|
47
|
+
|
48
|
+
#
|
49
|
+
# Get the last node associated with a specific {@code label}.
|
50
|
+
#
|
51
|
+
# <p>For example, for pattern {@code <id:ID>}, {@code get("id")} returns the
|
52
|
+
# node matched for that {@code ID}. If more than one node
|
53
|
+
# matched the specified label, only the last is returned. If there is
|
54
|
+
# no node associated with the label, this returns {@code null}.</p>
|
55
|
+
#
|
56
|
+
# <p>Pattern tags like {@code <ID>} and {@code <expr>} without labels are
|
57
|
+
# considered to be labeled with {@code ID} and {@code expr}, respectively.</p>
|
58
|
+
#
|
59
|
+
# @param label The label to check.
|
60
|
+
#
|
61
|
+
# @return The last {@link ParseTree} to match a tag with the specified
|
62
|
+
# label, or {@code null} if no parse tree matched a tag with the label.
|
63
|
+
#
|
64
|
+
def get(self, label:str):
|
65
|
+
parseTrees = self.labels.get(label, None)
|
66
|
+
if parseTrees is None or len(parseTrees)==0:
|
67
|
+
return None
|
68
|
+
else:
|
69
|
+
return parseTrees[len(parseTrees)-1]
|
70
|
+
|
71
|
+
#
|
72
|
+
# Return all nodes matching a rule or token tag with the specified label.
|
73
|
+
#
|
74
|
+
# <p>If the {@code label} is the name of a parser rule or token in the
|
75
|
+
# grammar, the resulting list will contain both the parse trees matching
|
76
|
+
# rule or tags explicitly labeled with the label and the complete set of
|
77
|
+
# parse trees matching the labeled and unlabeled tags in the pattern for
|
78
|
+
# the parser rule or token. For example, if {@code label} is {@code "foo"},
|
79
|
+
# the result will contain <em>all</em> of the following.</p>
|
80
|
+
#
|
81
|
+
# <ul>
|
82
|
+
# <li>Parse tree nodes matching tags of the form {@code <foo:anyRuleName>} and
|
83
|
+
# {@code <foo:AnyTokenName>}.</li>
|
84
|
+
# <li>Parse tree nodes matching tags of the form {@code <anyLabel:foo>}.</li>
|
85
|
+
# <li>Parse tree nodes matching tags of the form {@code <foo>}.</li>
|
86
|
+
# </ul>
|
87
|
+
#
|
88
|
+
# @param label The label.
|
89
|
+
#
|
90
|
+
# @return A collection of all {@link ParseTree} nodes matching tags with
|
91
|
+
# the specified {@code label}. If no nodes matched the label, an empty list
|
92
|
+
# is returned.
|
93
|
+
#
|
94
|
+
def getAll(self, label:str):
|
95
|
+
nodes = self.labels.get(label, None)
|
96
|
+
if nodes is None:
|
97
|
+
return list()
|
98
|
+
else:
|
99
|
+
return nodes
|
100
|
+
|
101
|
+
|
102
|
+
#
|
103
|
+
# Gets a value indicating whether the match operation succeeded.
|
104
|
+
#
|
105
|
+
# @return {@code true} if the match operation succeeded; otherwise,
|
106
|
+
# {@code false}.
|
107
|
+
#
|
108
|
+
def succeeded(self):
|
109
|
+
return self.mismatchedNode is None
|
110
|
+
|
111
|
+
#
|
112
|
+
# {@inheritDoc}
|
113
|
+
#
|
114
|
+
def __str__(self):
|
115
|
+
with StringIO() as buf:
|
116
|
+
buf.write("Match ")
|
117
|
+
buf.write("succeeded" if self.succeeded() else "failed")
|
118
|
+
buf.write("; found ")
|
119
|
+
buf.write(str(len(self.labels)))
|
120
|
+
buf.write(" labels")
|
121
|
+
return buf.getvalue()
|
@@ -0,0 +1,75 @@
|
|
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
|
+
#
|
11
|
+
# A pattern like {@code <ID> = <expr>;} converted to a {@link ParseTree} by
|
12
|
+
# {@link ParseTreePatternMatcher#compile(String, int)}.
|
13
|
+
#
|
14
|
+
from .ParseTreePatternMatcher import ParseTreePatternMatcher
|
15
|
+
from .Tree import ParseTree
|
16
|
+
from ..xpath.XPathLexer import XPathLexer
|
17
|
+
|
18
|
+
|
19
|
+
class ParseTreePattern(object):
|
20
|
+
__slots__ = ('matcher', 'patternRuleIndex', 'pattern', 'patternTree')
|
21
|
+
|
22
|
+
# Construct a new instance of the {@link ParseTreePattern} class.
|
23
|
+
#
|
24
|
+
# @param matcher The {@link ParseTreePatternMatcher} which created this
|
25
|
+
# tree pattern.
|
26
|
+
# @param pattern The tree pattern in concrete syntax form.
|
27
|
+
# @param patternRuleIndex The parser rule which serves as the root of the
|
28
|
+
# tree pattern.
|
29
|
+
# @param patternTree The tree pattern in {@link ParseTree} form.
|
30
|
+
#
|
31
|
+
def __init__(self, matcher:ParseTreePatternMatcher, pattern:str, patternRuleIndex:int , patternTree:ParseTree):
|
32
|
+
self.matcher = matcher
|
33
|
+
self.patternRuleIndex = patternRuleIndex
|
34
|
+
self.pattern = pattern
|
35
|
+
self.patternTree = patternTree
|
36
|
+
|
37
|
+
#
|
38
|
+
# Match a specific parse tree against this tree pattern.
|
39
|
+
#
|
40
|
+
# @param tree The parse tree to match against this tree pattern.
|
41
|
+
# @return A {@link ParseTreeMatch} object describing the result of the
|
42
|
+
# match operation. The {@link ParseTreeMatch#succeeded()} method can be
|
43
|
+
# used to determine whether or not the match was successful.
|
44
|
+
#
|
45
|
+
def match(self, tree:ParseTree):
|
46
|
+
return self.matcher.match(tree, self)
|
47
|
+
|
48
|
+
#
|
49
|
+
# Determine whether or not a parse tree matches this tree pattern.
|
50
|
+
#
|
51
|
+
# @param tree The parse tree to match against this tree pattern.
|
52
|
+
# @return {@code true} if {@code tree} is a match for the current tree
|
53
|
+
# pattern; otherwise, {@code false}.
|
54
|
+
#
|
55
|
+
def matches(self, tree:ParseTree):
|
56
|
+
return self.matcher.match(tree, self).succeeded()
|
57
|
+
|
58
|
+
# Find all nodes using XPath and then try to match those subtrees against
|
59
|
+
# this tree pattern.
|
60
|
+
#
|
61
|
+
# @param tree The {@link ParseTree} to match against this pattern.
|
62
|
+
# @param xpath An expression matching the nodes
|
63
|
+
#
|
64
|
+
# @return A collection of {@link ParseTreeMatch} objects describing the
|
65
|
+
# successful matches. Unsuccessful matches are omitted from the result,
|
66
|
+
# regardless of the reason for the failure.
|
67
|
+
#
|
68
|
+
def findAll(self, tree:ParseTree, xpath:str):
|
69
|
+
subtrees = XPath.findAll(tree, xpath, self.matcher.parser)
|
70
|
+
matches = list()
|
71
|
+
for t in subtrees:
|
72
|
+
match = self.match(t)
|
73
|
+
if match.succeeded():
|
74
|
+
matches.append(match)
|
75
|
+
return matches
|