def accept(self, input:InputStream, lexerActionExecutor:LexerActionExecutor, startIndex:int, index:int, line:int, charPos:int): if LexerATNSimulator.debug: print("ACTION", lexerActionExecutor) # seek to after last char in token input.seek(index) self.line = line self.column = charPos if lexerActionExecutor is not None and self.recog is not None: lexerActionExecutor.execute(self.recog, input, startIndex)
def testStream(self): stream = InputStream("abcde") self.assertEqual(0, stream.index) self.assertEqual(5, stream.size) self.assertEqual(ord("a"), stream.LA(1)) stream.consume() self.assertEqual(1, stream.index) stream.seek(5) self.assertEqual(Token.EOF, stream.LA(1)) self.assertEqual("bcd", stream.getText(1, 3)) stream.reset() self.assertEqual(0, stream.index)
def accept(self, input: InputStream, lexerActionExecutor: LexerActionExecutor, startIndex: int, index: int, line: int, charPos: int): if self.debug: print("ACTION %s\n", lexerActionExecutor) # seek to after last char in token input.seek(index) self.line = line self.column = charPos if input.LA(1) != Token.EOF: self.consume(input) if lexerActionExecutor is not None and self.recog is not None: lexerActionExecutor.execute(self.recog, input, startIndex)
def evaluatePredicate(self, input:InputStream, ruleIndex:int, predIndex:int, speculative:bool): # assume true if no recognizer was provided if self.recog is None: return True if not speculative: return self.recog.sempred(None, ruleIndex, predIndex) savedcolumn = self.column savedLine = self.line index = input.index marker = input.mark() try: self.consume(input) return self.recog.sempred(None, ruleIndex, predIndex) finally: self.column = savedcolumn self.line = savedLine input.seek(index) input.release(marker)
def accept( self, input: InputStream, lexerActionExecutor: LexerActionExecutor, startIndex: int, index: int, line: int, charPos: int, ): if self.debug: print("ACTION %s\n", lexerActionExecutor) # seek to after last char in token input.seek(index) self.line = line self.column = charPos if input.LA(1) != Token.EOF: self.consume(input) if lexerActionExecutor is not None and self.recog is not None: lexerActionExecutor.execute(self.recog, input, startIndex)
def execute(self, lexer:Lexer, input:InputStream, startIndex:int): requiresSeek = False stopIndex = input.index try: for lexerAction in self.lexerActions: if isinstance(lexerAction, LexerIndexedCustomAction): offset = lexerAction.offset input.seek(startIndex + offset) lexerAction = lexerAction.action requiresSeek = (startIndex + offset) != stopIndex elif lexerAction.isPositionDependent: input.seek(stopIndex) requiresSeek = False lexerAction.execute(lexer) finally: if requiresSeek: input.seek(stopIndex)
def execute(self, lexer: Lexer, input: InputStream, startIndex: int): requiresSeek = False stopIndex = input.index try: for lexerAction in self.lexerActions: if isinstance(lexerAction, LexerIndexedCustomAction): offset = lexerAction.offset input.seek(startIndex + offset) lexerAction = lexerAction.action requiresSeek = (startIndex + offset) != stopIndex elif lexerAction.isPositionDependent: input.seek(stopIndex) requiresSeek = False lexerAction.execute(lexer) finally: if requiresSeek: input.seek(stopIndex)