Skip to content

Commit

Permalink
Remove stray type annotations from Python2 runtime
Browse files Browse the repository at this point in the history
Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
  • Loading branch information
agatti authored and parrt committed Jun 15, 2023
1 parent b7b8135 commit d2e2584
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions runtime/Python2/src/antlr4/xpath/XPath.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ class XPath(object):
WILDCARD = "*" # word not operator/separator
NOT = "!" # word for invert operator

def __init__(self, parser:Parser, path:str):
def __init__(self, parser, path):
self.parser = parser
self.path = path
self.elements = self.split(path)

def split(self, path:str):
def split(self, path):
input = InputStream(path)
lexer = XPathLexer(input)
def recover(self, e):
Expand Down Expand Up @@ -124,7 +124,7 @@ def recover(self, e):
# element. {@code anywhere} is {@code true} if {@code //} precedes the
# word.
#
def getXPathElement(self, wordToken:Token, anywhere:bool):
def getXPathElement(self, wordToken, anywhere):
if wordToken.type==Token.EOF:
raise Exception("Missing path element at end of path")

Expand Down Expand Up @@ -156,7 +156,7 @@ def getXPathElement(self, wordToken:Token, anywhere:bool):


@staticmethod
def findAll(tree:ParseTree, xpath:str, parser:Parser):
def findAll(tree, xpath, parser):
p = XPath(parser, xpath)
return p.evaluate(tree)

Expand All @@ -165,7 +165,7 @@ def findAll(tree:ParseTree, xpath:str, parser:Parser):
# path. The root {@code /} is relative to the node passed to
# {@link #evaluate}.
#
def evaluate(self, t:ParseTree):
def evaluate(self, t):
dummyRoot = ParserRuleContext()
dummyRoot.children = [t] # don't set t's parent.

Expand All @@ -191,7 +191,7 @@ def evaluate(self, t:ParseTree):

class XPathElement(object):

def __init__(self, nodeName:str):
def __init__(self, nodeName):
self.nodeName = nodeName
self.invert = False

Expand All @@ -205,41 +205,41 @@ def __str__(self):
#
class XPathRuleAnywhereElement(XPathElement):

def __init__(self, ruleName:str, ruleIndex:int):
def __init__(self, ruleName, ruleIndexint):
super().__init__(ruleName)
self.ruleIndex = ruleIndex

def evaluate(self, t:ParseTree):
def evaluate(self, t):
# return all ParserRuleContext descendants of t that match ruleIndex (or do not match if inverted)
return filter(lambda c: isinstance(c, ParserRuleContext) and (self.invert ^ (c.getRuleIndex() == self.ruleIndex)), Trees.descendants(t))

class XPathRuleElement(XPathElement):

def __init__(self, ruleName:str, ruleIndex:int):
def __init__(self, ruleName, ruleIndex):
super().__init__(ruleName)
self.ruleIndex = ruleIndex

def evaluate(self, t:ParseTree):
def evaluate(self, t):
# return all ParserRuleContext children of t that match ruleIndex (or do not match if inverted)
return filter(lambda c: isinstance(c, ParserRuleContext) and (self.invert ^ (c.getRuleIndex() == self.ruleIndex)), Trees.getChildren(t))

class XPathTokenAnywhereElement(XPathElement):

def __init__(self, ruleName:str, tokenType:int):
def __init__(self, ruleName, tokenType):
super().__init__(ruleName)
self.tokenType = tokenType

def evaluate(self, t:ParseTree):
def evaluate(self, t):
# return all TerminalNode descendants of t that match tokenType (or do not match if inverted)
return filter(lambda c: isinstance(c, TerminalNode) and (self.invert ^ (c.symbol.type == self.tokenType)), Trees.descendants(t))

class XPathTokenElement(XPathElement):

def __init__(self, ruleName:str, tokenType:int):
def __init__(self, ruleName, tokenType):
super().__init__(ruleName)
self.tokenType = tokenType

def evaluate(self, t:ParseTree):
def evaluate(self, t):
# return all TerminalNode children of t that match tokenType (or do not match if inverted)
return filter(lambda c: isinstance(c, TerminalNode) and (self.invert ^ (c.symbol.type == self.tokenType)), Trees.getChildren(t))

Expand All @@ -249,7 +249,7 @@ class XPathWildcardAnywhereElement(XPathElement):
def __init__(self):
super().__init__(XPath.WILDCARD)

def evaluate(self, t:ParseTree):
def evaluate(self, t):
if self.invert:
return list() # !* is weird but valid (empty)
else:
Expand All @@ -262,7 +262,7 @@ def __init__(self):
super().__init__(XPath.WILDCARD)


def evaluate(self, t:ParseTree):
def evaluate(self, t):
if self.invert:
return list() # !* is weird but valid (empty)
else:
Expand Down

0 comments on commit d2e2584

Please sign in to comment.