desc stringlengths 3 26.7k | decl stringlengths 11 7.89k | bodies stringlengths 8 553k |
|---|---|---|
'Return a tree node representing an error. This node records the
tokens consumed during error recovery. The start token indicates the
input symbol at which the error was detected. The stop token indicates
the last symbol consumed during recovery.
You must specify the input stream so that the erroneous text can
be pa... | def errorNode(self, input, start, stop, exc):
| raise NotImplementedError
|
'Is tree considered a nil node used to make lists of child nodes?'
| def isNil(self, tree):
| raise NotImplementedError
|
'Add a child to the tree t. If child is a flat tree (a list), make all
in list children of t. Warning: if t has no children, but child does
and child isNil then you can decide it is ok to move children to t via
t.children = child.children; i.e., without copying the array. Just
make sure that this is consistent with ... | def addChild(self, t, child):
| raise NotImplementedError
|
'If oldRoot is a nil root, just copy or move the children to newRoot.
If not a nil root, make oldRoot a child of newRoot.
old=^(nil a b c), new=r yields ^(r a b c)
old=^(a b c), new=r yields ^(r ^(a b c))
If newRoot is a nil-rooted single child tree, use the single
child as the new root node.
old=^(nil a b c), new=^(ni... | def becomeRoot(self, newRoot, oldRoot):
| raise NotImplementedError
|
'Given the root of the subtree created for this rule, post process
it to do any simplifications or whatever you want. A required
behavior is to convert ^(nil singleSubtree) to singleSubtree
as the setting of start/stop indexes relies on a single non-nil root
for non-flat trees.
Flat trees such as for lists like "idlis... | def rulePostProcessing(self, root):
| raise NotImplementedError
|
'For identifying trees.
How to identify nodes so we can say "add node to a prior node"?
Even becomeRoot is an issue. Use System.identityHashCode(node)
usually.'
| def getUniqueID(self, node):
| raise NotImplementedError
|
'Create a new node derived from a token, with a new token type and
(optionally) new text.
This is invoked from an imaginary node ref on right side of a
rewrite rule as IMAG[$tokenLabel] or IMAG[$tokenLabel "IMAG"].
This should invoke createToken(Token).'
| def createFromToken(self, tokenType, fromToken, text=None):
| raise NotImplementedError
|
'Create a new node derived from a token, with a new token type.
This is invoked from an imaginary node ref on right side of a
rewrite rule as IMAG["IMAG"].
This should invoke createToken(int,String).'
| def createFromType(self, tokenType, text):
| raise NotImplementedError
|
'For tree parsing, I need to know the token type of a node'
| def getType(self, t):
| raise NotImplementedError
|
'Node constructors can set the type of a node'
| def setType(self, t, type):
| raise NotImplementedError
|
'Node constructors can set the text of a node'
| def setText(self, t, text):
| raise NotImplementedError
|
'Return the token object from which this node was created.
Currently used only for printing an error message.
The error display routine in BaseRecognizer needs to
display where the input the error occurred. If your
tree of limitation does not store information that can
lead you to the token, you can create a token fill... | def getToken(self, t):
| raise NotImplementedError
|
'Where are the bounds in the input token stream for this node and
all children? Each rule that creates AST nodes will call this
method right before returning. Flat trees (i.e., lists) will
still usually have a nil root node just to hold the children list.
That node would contain the start/stop indexes then.'
| def setTokenBoundaries(self, t, startToken, stopToken):
| raise NotImplementedError
|
'Get the token start index for this subtree; return -1 if no such index'
| def getTokenStartIndex(self, t):
| raise NotImplementedError
|
'Get the token stop index for this subtree; return -1 if no such index'
| def getTokenStopIndex(self, t):
| raise NotImplementedError
|
'Get a child 0..n-1 node'
| def getChild(self, t, i):
| raise NotImplementedError
|
'Set ith child (0..n-1) to t; t must be non-null and non-nil node'
| def setChild(self, t, i, child):
| raise NotImplementedError
|
'Remove ith child and shift children down from right.'
| def deleteChild(self, t, i):
| raise NotImplementedError
|
'How many children? If 0, then this is a leaf node'
| def getChildCount(self, t):
| raise NotImplementedError
|
'Who is the parent node of this node; if null, implies node is root.
If your node type doesn\'t handle this, it\'s ok but the tree rewrites
in tree parsers need this functionality.'
| def getParent(self, t):
| raise NotImplementedError
|
'Who is the parent node of this node; if null, implies node is root.
If your node type doesn\'t handle this, it\'s ok but the tree rewrites
in tree parsers need this functionality.'
| def setParent(self, t, parent):
| raise NotImplementedError
|
'What index is this node in the child list? Range: 0..n-1
If your node type doesn\'t handle this, it\'s ok but the tree rewrites
in tree parsers need this functionality.'
| def getChildIndex(self, t):
| raise NotImplementedError
|
'What index is this node in the child list? Range: 0..n-1
If your node type doesn\'t handle this, it\'s ok but the tree rewrites
in tree parsers need this functionality.'
| def setChildIndex(self, t, index):
| raise NotImplementedError
|
'Replace from start to stop child index of parent with t, which might
be a list. Number of children may be different
after this call.
If parent is null, don\'t do anything; must be at root of overall tree.
Can\'t replace whatever points to the parent externally. Do nothing.'
| def replaceChildren(self, parent, startChildIndex, stopChildIndex, t):
| raise NotImplementedError
|
'Deprecated, use createWithPayload, createFromToken or createFromType.
This method only exists to mimic the Java interface of TreeAdaptor.'
| def create(self, *args):
| if ((len(args) == 1) and isinstance(args[0], Token)):
return self.createWithPayload(args[0])
if ((len(args) == 2) and isinstance(args[0], (int, long)) and isinstance(args[1], Token)):
return self.createFromToken(args[0], args[1])
if ((len(args) == 3) and isinstance(args[0], (int, long)) and ... |
'Create a new node from an existing node does nothing for BaseTree
as there are no fields other than the children list, which cannot
be copied as the children are not considered part of this node.'
| def __init__(self, node=None):
| Tree.__init__(self)
self.children = []
self.parent = None
self.childIndex = 0
|
'@brief Get the children internal List
Note that if you directly mess with
the list, do so at your own risk.'
| def getChildren(self):
| return self.children
|
'Add t as child of this node.
Warning: if t has no children, but child does
and child isNil then this routine moves children to t via
t.children = child.children; i.e., without copying the array.'
| def addChild(self, childTree):
| if (childTree is None):
return
if childTree.isNil():
if (self.children is childTree.children):
raise ValueError('attempt to add child list to itself')
for (idx, child) in enumerate(childTree.children):
child.parent = self
child.childI... |
'Add all elements of kids list as children of this node'
| def addChildren(self, children):
| self.children += children
|
'Delete children from start to stop and replace with t even if t is
a list (nil-root tree). num of children can increase or decrease.
For huge child lists, inserting children can force walking rest of
children to set their childindex; could be slow.'
| def replaceChildren(self, startChildIndex, stopChildIndex, newTree):
| if ((startChildIndex >= len(self.children)) or (stopChildIndex >= len(self.children))):
raise IndexError('indexes invalid')
replacingHowMany = ((stopChildIndex - startChildIndex) + 1)
if newTree.isNil():
newChildren = newTree.children
else:
newChildren = [newTree]
replacin... |
'BaseTree doesn\'t track child indexes.'
| def getChildIndex(self):
| return 0
|
'BaseTree doesn\'t track child indexes.'
| def setChildIndex(self, index):
| pass
|
'BaseTree doesn\'t track parent pointers.'
| def getParent(self):
| return None
|
'BaseTree doesn\'t track parent pointers.'
| def setParent(self, t):
| pass
|
'Print out a whole tree not just a node'
| def toStringTree(self):
| if (len(self.children) == 0):
return self.toString()
buf = []
if (not self.isNil()):
buf.append('(')
buf.append(self.toString())
buf.append(' ')
for (i, child) in enumerate(self.children):
if (i > 0):
buf.append(' ')
buf.append(child.toSt... |
'Override to say how a node (not a tree) should look as text'
| def toString(self):
| raise NotImplementedError
|
'create tree node that holds the start and stop tokens associated
with an error.
If you specify your own kind of tree nodes, you will likely have to
override this method. CommonTree returns Token.INVALID_TOKEN_TYPE
if no token payload but you might have to set token type for diff
node type.'
| def errorNode(self, input, start, stop, exc):
| return CommonErrorNode(input, start, stop, exc)
|
'This is generic in the sense that it will work with any kind of
tree (not just Tree interface). It invokes the adaptor routines
not the tree node routines to do the construction.'
| def dupTree(self, t, parent=None):
| if (t is None):
return None
newTree = self.dupNode(t)
self.setChildIndex(newTree, self.getChildIndex(t))
self.setParent(newTree, parent)
for i in range(self.getChildCount(t)):
child = self.getChild(t, i)
newSubTree = self.dupTree(child, t)
self.addChild(newTree, newSu... |
'Add a child to the tree t. If child is a flat tree (a list), make all
in list children of t. Warning: if t has no children, but child does
and child isNil then you can decide it is ok to move children to t via
t.children = child.children; i.e., without copying the array. Just
make sure that this is consistent with ... | def addChild(self, tree, child):
| if ((tree is not None) and (child is not None)):
tree.addChild(child)
|
'If oldRoot is a nil root, just copy or move the children to newRoot.
If not a nil root, make oldRoot a child of newRoot.
old=^(nil a b c), new=r yields ^(r a b c)
old=^(a b c), new=r yields ^(r ^(a b c))
If newRoot is a nil-rooted single child tree, use the single
child as the new root node.
old=^(nil a b c), new=^(ni... | def becomeRoot(self, newRoot, oldRoot):
| if isinstance(newRoot, Token):
newRoot = self.create(newRoot)
if (oldRoot is None):
return newRoot
if (not isinstance(newRoot, CommonTree)):
newRoot = self.createWithPayload(newRoot)
if newRoot.isNil():
nc = newRoot.getChildCount()
if (nc == 1):
newRoo... |
'Transform ^(nil x) to x and nil to null'
| def rulePostProcessing(self, root):
| if ((root is not None) and root.isNil()):
if (root.getChildCount() == 0):
root = None
elif (root.getChildCount() == 1):
root = root.getChild(0)
root.setParent(None)
root.setChildIndex((-1))
return root
|
'Tell me how to create a token for use with imaginary token nodes.
For example, there is probably no input symbol associated with imaginary
token DECL, but you need to create it as a payload or whatever for
the DECL node as in ^(DECL type ID).
If you care what the token payload objects\' type is, you should
override th... | def createToken(self, fromToken=None, tokenType=None, text=None):
| raise NotImplementedError
|
'Duplicate a node. This is part of the factory;
override if you want another kind of node to be built.
I could use reflection to prevent having to override this
but reflection is slow.'
| def dupNode(self, treeNode):
| if (treeNode is None):
return None
return treeNode.dupNode()
|
'Tell me how to create a token for use with imaginary token nodes.
For example, there is probably no input symbol associated with imaginary
token DECL, but you need to create it as a payload or whatever for
the DECL node as in ^(DECL type ID).
If you care what the token payload objects\' type is, you should
override th... | def createToken(self, fromToken=None, tokenType=None, text=None):
| if (fromToken is not None):
return CommonToken(oldToken=fromToken)
return CommonToken(type=tokenType, text=text)
|
'Track start/stop token for subtree root created for a rule.
Only works with Tree nodes. For rules that match nothing,
seems like this will yield start=i and stop=i-1 in a nil node.
Might be useful info so I\'ll not force to be i..i.'
| def setTokenBoundaries(self, t, startToken, stopToken):
| if (t is None):
return
start = 0
stop = 0
if (startToken is not None):
start = startToken.index
if (stopToken is not None):
stop = stopToken.index
t.setTokenStartIndex(start)
t.setTokenStopIndex(stop)
|
'What is the Token associated with this node? If
you are not using CommonTree, then you must
override this in your own adaptor.'
| def getToken(self, t):
| if isinstance(t, CommonTree):
return t.getToken()
return None
|
'Get a tree node at an absolute index i; 0..n-1.
If you don\'t want to buffer up nodes, then this method makes no
sense for you.'
| def get(self, i):
| raise NotImplementedError
|
'Get tree node at current input pointer + i ahead where i=1 is next node.
i<0 indicates nodes in the past. So LT(-1) is previous node, but
implementations are not required to provide results for k < -1.
LT(0) is undefined. For i>=n, return null.
Return null for LT(0) and any index that results in an absolute address
... | def LT(self, k):
| raise NotImplementedError
|
'Where is this stream pulling nodes from? This is not the name, but
the object that provides node objects.'
| def getTreeSource(self):
| raise NotImplementedError
|
'If the tree associated with this stream was created from a TokenStream,
you can specify it here. Used to do rule $text attribute in tree
parser. Optional unless you use tree parser rule text attribute
or output=template and rewrite=true options.'
| def getTokenStream(self):
| raise NotImplementedError
|
'What adaptor can tell me how to interpret/navigate nodes and
trees. E.g., get text of a node.'
| def getTreeAdaptor(self):
| raise NotImplementedError
|
'As we flatten the tree, we use UP, DOWN nodes to represent
the tree structure. When debugging we need unique nodes
so we have to instantiate new ones. When doing normal tree
parsing, it\'s slow and a waste of memory to create unique
navigation nodes. Default should be false;'
| def setUniqueNavigationNodes(self, uniqueNavigationNodes):
| raise NotImplementedError
|
'Return the text of all nodes from start to stop, inclusive.
If the stream does not buffer all the nodes then it can still
walk recursively from start until stop. You can always return
null or "" too, but users should not access $ruleLabel.text in
an action of course in that case.'
| def toString(self, start, stop):
| raise NotImplementedError
|
'Replace from start to stop child index of parent with t, which might
be a list. Number of children may be different
after this call. The stream is notified because it is walking the
tree and might need to know you are monkeying with the underlying
tree. Also, it might be able to modify the node stream to avoid
rest... | def replaceChildren(self, parent, startChildIndex, stopChildIndex, t):
| raise NotImplementedError
|
'Walk tree with depth-first-search and fill nodes buffer.
Don\'t do DOWN, UP nodes if its a list (t is isNil).'
| def fillBuffer(self):
| self._fillBuffer(self.root)
self.p = 0
|
'What is the stream index for node? 0..n-1
Return -1 if node not found.'
| def getNodeIndex(self, node):
| if (self.p == (-1)):
self.fillBuffer()
for (i, t) in enumerate(self.nodes):
if (t == node):
return i
return (-1)
|
'As we flatten the tree, we use UP, DOWN nodes to represent
the tree structure. When debugging we need unique nodes
so instantiate new ones when uniqueNavigationNodes is true.'
| def addNavigationNode(self, ttype):
| navNode = None
if (ttype == DOWN):
if self.hasUniqueNavigationNodes():
navNode = self.adaptor.createFromType(DOWN, 'DOWN')
else:
navNode = self.down
elif self.hasUniqueNavigationNodes():
navNode = self.adaptor.createFromType(UP, 'UP')
else:
navNode... |
'Look backwards k nodes'
| def LB(self, k):
| if (k == 0):
return None
if ((self.p - k) < 0):
return None
return self.nodes[(self.p - k)]
|
'Make stream jump to a new location, saving old location.
Switch back with pop().'
| def push(self, index):
| self.calls.append(self.p)
self.seek(index)
|
'Seek back to previous index saved during last push() call.
Return top of stack (return index).'
| def pop(self):
| ret = self.calls.pop((-1))
self.seek(ret)
return ret
|
'Used for testing, just return the token type stream'
| def __str__(self):
| if (self.p == (-1)):
self.fillBuffer()
return ' '.join([str(self.adaptor.getType(node)) for node in self.nodes])
|
'Set the input stream'
| def setTreeNodeStream(self, input):
| self.input = input
|
'Match \'.\' in tree parser has special meaning. Skip node or
entire tree if node has children. If children, scan until
corresponding UP node.'
| def matchAny(self, ignore):
| self._state.errorRecovery = False
look = self.input.LT(1)
if (self.input.getTreeAdaptor().getChildCount(look) == 0):
self.input.consume()
return
level = 0
tokenType = self.input.getTreeAdaptor().getType(look)
while ((tokenType != EOF) and (not ((tokenType == UP) and (level == 0))... |
'We have DOWN/UP nodes in the stream that have no line info; override.
plus we want to alter the exception type. Don\'t try to recover
from tree parser errors inline...'
| def mismatch(self, input, ttype, follow):
| raise MismatchedTreeNodeException(ttype, input)
|
'Prefix error message with the grammar name because message is
always intended for the programmer because the parser built
the input tree not the user.'
| def getErrorHeader(self, e):
| return (self.getGrammarFileName() + (': node from %sline %s:%s' % (['', 'after '][e.approximateLineInfo], e.line, e.charPositionInLine)))
|
'Tree parsers parse nodes they usually have a token object as
payload. Set the exception token and do the default behavior.'
| def getErrorMessage(self, e, tokenNames):
| if isinstance(self, TreeParser):
adaptor = e.input.getTreeAdaptor()
e.token = adaptor.getToken(e.node)
if (e.token is not None):
e.token = CommonToken(type=adaptor.getType(e.node), text=adaptor.getText(e.node))
return BaseRecognizer.getErrorMessage(self, e, tokenNames)
|
'Reset the condition of this stream so that it appears we have
not consumed any of its elements. Elements themselves are untouched.
Once we reset the stream, any future use will need duplicates. Set
the dirty bit.'
| def reset(self):
| self.cursor = 0
self.dirty = True
|
'Return the next element in the stream. If out of elements, throw
an exception unless size()==1. If size is 1, then return elements[0].
Return a duplicate node/subtree if stream is out of elements and
size==1. If we\'ve already used the element, dup (dirty bit set).'
| def nextTree(self):
| if (self.dirty or ((self.cursor >= len(self)) and (len(self) == 1))):
el = self._next()
return self.dup(el)
el = self._next()
return el
|
'do the work of getting the next element, making sure that it\'s
a tree node or subtree. Deal with the optimization of single-
element list versus list of size > 1. Throw an exception
if the stream is empty or we\'re out of elements and size>1.
protected so you can override in a subclass if necessary.'
| def _next(self):
| if (len(self) == 0):
raise RewriteEmptyStreamException(self.elementDescription)
if (self.cursor >= len(self)):
if (len(self) == 1):
return self.toTree(self.singleElement)
raise RewriteCardinalityException(self.elementDescription)
if (self.singleElement is not None):
... |
'When constructing trees, sometimes we need to dup a token or AST
subtree. Dup\'ing a token means just creating another AST node
around it. For trees, you must call the adaptor.dupTree() unless
the element is for a tree root; then it must be a node dup.'
| def dup(self, el):
| raise NotImplementedError
|
'Ensure stream emits trees; tokens must be converted to AST nodes.
AST nodes can be passed through unmolested.'
| def toTree(self, el):
| return el
|
'Deprecated. Directly access elementDescription attribute'
| def getDescription(self):
| return self.elementDescription
|
'Treat next element as a single node even if it\'s a subtree.
This is used instead of next() when the result has to be a
tree root node. Also prevents us from duplicating recently-added
children; e.g., ^(type ID)+ adds ID to type and then 2nd iteration
must dup the type node, but ID has been added.
Referencing a rule ... | def nextNode(self):
| if (self.dirty or ((self.cursor >= len(self)) and (len(self) == 1))):
el = self._next()
return self.adaptor.dupNode(el)
el = self._next()
return el
|
'Using the map of token names to token types, return the type.'
| def getTokenType(self, tokenName):
| try:
return self.tokenNameToTypeMap[tokenName]
except KeyError:
return INVALID_TOKEN_TYPE
|
'Create a tree or node from the indicated tree pattern that closely
follows ANTLR tree grammar tree element syntax:
(root child1 ... child2).
You can also just pass in a node: ID
Any node can have a text argument: ID[foo]
(notice there are no quotes around foo--it\'s clear it\'s a string).
nil is a special name meaning... | def create(self, pattern):
| tokenizer = TreePatternLexer(pattern)
parser = TreePatternParser(tokenizer, self, self.adaptor)
return parser.pattern()
|
'Walk the entire tree and make a node name to nodes mapping.
For now, use recursion but later nonrecursive version may be
more efficient. Returns a dict int -> list where the list is
of your AST node type. The int is the token type of the node.'
| def index(self, tree):
| m = {}
self._index(tree, m)
return m
|
'Do the work for index'
| def _index(self, t, m):
| if (t is None):
return
ttype = self.adaptor.getType(t)
elements = m.get(ttype)
if (elements is None):
m[ttype] = elements = []
elements.append(t)
for i in range(self.adaptor.getChildCount(t)):
child = self.adaptor.getChild(t, i)
self._index(child, m)
|
'Return a list of matching token.
what may either be an integer specifzing the token type to find or
a string with a pattern that must be matched.'
| def find(self, tree, what):
| if isinstance(what, (int, long)):
return self._findTokenType(tree, what)
elif isinstance(what, basestring):
return self._findPattern(tree, what)
else:
raise TypeError("'what' must be string or integer")
|
'Return a List of tree nodes with token type ttype'
| def _findTokenType(self, t, ttype):
| nodes = []
def visitor(tree, parent, childIndex, labels):
nodes.append(tree)
self.visit(t, ttype, visitor)
return nodes
|
'Return a List of subtrees matching pattern.'
| def _findPattern(self, t, pattern):
| subtrees = []
tokenizer = TreePatternLexer(pattern)
parser = TreePatternParser(tokenizer, self, TreePatternTreeAdaptor())
tpattern = parser.pattern()
if ((tpattern is None) or tpattern.isNil() or isinstance(tpattern, WildcardTreePattern)):
return None
rootTokenType = tpattern.getType()
... |
'Visit every node in tree matching what, invoking the visitor.
If what is a string, it is parsed as a pattern and only matching
subtrees will be visited.
The implementation uses the root node of the pattern in combination
with visit(t, ttype, visitor) so nil-rooted patterns are not allowed.
Patterns with wildcard roots... | def visit(self, tree, what, visitor):
| if isinstance(what, (int, long)):
self._visitType(tree, None, 0, what, visitor)
elif isinstance(what, basestring):
self._visitPattern(tree, what, visitor)
else:
raise TypeError("'what' must be string or integer")
|
'Do the recursive work for visit'
| def _visitType(self, t, parent, childIndex, ttype, visitor):
| if (t is None):
return
if (self.adaptor.getType(t) == ttype):
visitor(t, parent, childIndex, None)
for i in range(self.adaptor.getChildCount(t)):
child = self.adaptor.getChild(t, i)
self._visitType(child, t, i, ttype, visitor)
|
'For all subtrees that match the pattern, execute the visit action.'
| def _visitPattern(self, tree, pattern, visitor):
| tokenizer = TreePatternLexer(pattern)
parser = TreePatternParser(tokenizer, self, TreePatternTreeAdaptor())
tpattern = parser.pattern()
if ((tpattern is None) or tpattern.isNil() or isinstance(tpattern, WildcardTreePattern)):
return
rootTokenType = tpattern.getType()
def rootvisitor(tree... |
'Given a pattern like (ASSIGN %lhs:ID %rhs:.) with optional labels
on the various nodes and \'.\' (dot) as the node/subtree wildcard,
return true if the pattern matches and fill the labels Map with
the labels pointing at the appropriate nodes. Return false if
the pattern is malformed or the tree does not match.
If a n... | def parse(self, t, pattern, labels=None):
| tokenizer = TreePatternLexer(pattern)
parser = TreePatternParser(tokenizer, self, TreePatternTreeAdaptor())
tpattern = parser.pattern()
return self._parse(t, tpattern, labels)
|
'Do the work for parse. Check to see if the t2 pattern fits the
structure and token types in t1. Check text if the pattern has
text arguments on nodes. Fill labels map with pointers to nodes
in tree matched against nodes in pattern with labels.'
| def _parse(self, t1, t2, labels):
| if ((t1 is None) or (t2 is None)):
return False
if (not isinstance(t2, WildcardTreePattern)):
if (self.adaptor.getType(t1) != t2.getType()):
return False
if (t2.hasTextArg and (self.adaptor.getText(t1) != t2.getText())):
return False
if ((t2.label is not None)... |
'Compare t1 and t2; return true if token types/text, structure match
exactly.
The trees are examined in their entirety so that (A B) does not match
(A B C) nor (A (B C)).'
| def equals(self, t1, t2, adaptor=None):
| if (adaptor is None):
adaptor = self.adaptor
return self._equals(t1, t2, adaptor)
|
'Get int at current input pointer + i ahead where i=1 is next int.
Negative indexes are allowed. LA(-1) is previous token (token
just matched). LA(-i) where i is before first token should
yield -1, invalid char / EOF.'
| def LA(self, i):
| raise NotImplementedError
|
'Tell the stream to start buffering if it hasn\'t already. Return
current input position, index(), or some other marker so that
when passed to rewind() you get back to the same spot.
rewind(mark()) should not affect the input cursor. The Lexer
track line/col info as well as input index so its markers are
not pure inp... | def mark(self):
| raise NotImplementedError
|
'Return the current input symbol index 0..n where n indicates the
last symbol has been read. The index is the symbol about to be
read not the most recently read symbol.'
| def index(self):
| raise NotImplementedError
|
'Reset the stream so that next call to index would return marker.
The marker will usually be index() but it doesn\'t have to be. It\'s
just a marker to indicate what state the stream was in. This is
essentially calling release() and seek(). If there are markers
created after this marker argument, this routine must u... | def rewind(self, marker=None):
| raise NotImplementedError
|
'You may want to commit to a backtrack but don\'t want to force the
stream to keep bookkeeping objects around for a marker that is
no longer necessary. This will have the same behavior as
rewind() except it releases resources without the backward seek.
This must throw away resources for all markers back to the marker
... | def release(self, marker=None):
| raise NotImplementedError
|
'Set the input cursor to the position indicated by index. This is
normally used to seek ahead in the input stream. No buffering is
required to do this unless you know your stream will use seek to
move backwards such as when backtracking.
This is different from rewind in its multi-directional
requirement and in that i... | def seek(self, index):
| raise NotImplementedError
|
'Only makes sense for streams that buffer everything up probably, but
might be useful to display the entire stream or for testing. This
value includes a single EOF.'
| def size(self):
| raise NotImplementedError
|
'Where are you getting symbols from? Normally, implementations will
pass the buck all the way to the lexer who can ask its input stream
for the file name or whatever.'
| def getSourceName(self):
| raise NotImplementedError
|
'For infinite streams, you don\'t need this; primarily I\'m providing
a useful interface for action code. Just make sure actions don\'t
use this on streams that don\'t support it.'
| def substring(self, start, stop):
| raise NotImplementedError
|
'Get the ith character of lookahead. This is the same usually as
LA(i). This will be used for labels in the generated
lexer code. I\'d prefer to return a char here type-wise, but it\'s
probably better to be 32-bit clean and be consistent with LA.'
| def LT(self, i):
| raise NotImplementedError
|
'ANTLR tracks the line information automatically'
| def getLine(self):
| raise NotImplementedError
|
'Because this stream can rewind, we need to be able to reset the line'
| def setLine(self, line):
| raise NotImplementedError
|
'The index of the character relative to the beginning of the line 0..n-1'
| def getCharPositionInLine(self):
| raise NotImplementedError
|
'Get Token at current input pointer + i ahead where i=1 is next Token.
i<0 indicates tokens in the past. So -1 is previous token and -2 is
two tokens ago. LT(0) is undefined. For i>=n, return Token.EOFToken.
Return null for LT(0) and any index that results in an absolute address
that is negative.'
| def LT(self, k):
| raise NotImplementedError
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.