Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def t_comment_body_part(t):
r'(.|\n)*\*/'
print("comment body %s" % t)
t.lexer.begin('INITIAL')
def t_error(t):
pass
t_comment_error = t_error
t_comment_ignore = t_ignore
lex.lex()
data = "3 + 4 /* This is a comment */ + 10"
lex.runmain(data=data)
t.value = 0
return t
t_ignore = " \t"
def t_newline(t):
r'\n+'
t.lineno += t.value.count("\n")
def t_error(t):
print("Illegal character '%s'" % t.value[0])
t.lexer.skip(1)
# Build the lexer
lex.lex(optimize=1)
lex.runmain(data="3+4")
t.value = 0
return t
t_ignore = " \t"
def t_newline(t):
r'\n+'
t.lineno += t.value.count("\n")
def t_error(t):
print("Illegal character '%s'" % t.value[0])
t.lexer.skip(1)
# Build the lexer
lex.lex(optimize=1,lextab="lexdir.sub.calctab" ,outputdir="lexdir/sub")
lex.runmain(data="3+4")
t_PICKMARKER = 'pickMarker'
t_PUTMARKER = 'putMarker'
def t_INT(t):
r'\d+'
t.value = int(t.value)
return t
def t_error(t):
print("Illegal character %s" % repr(t.value[0]))
t.lexer.skip(1)
lexer = lex.lex()
if __name__ == '__main__':
lex.runmain(lexer)
example = """
def run():
repeat(4):
putMarker()
move()
turnLeft()
"""
lex.input(example)
while True:
tok = lex.token()
if not tok: break
print(tok)
# put it back on the left in case it was retrieved
# from the lookahead buffer
self.lookahead.appendleft(tok)
return None
return tok
def return_token(self, tok):
self.lookahead.appendleft(tok)
def return_tokens(self, toks):
self.lookahead.extendleft(reversed(toks))
if __name__ == "__main__":
try:
lex.runmain(lexer=Lexer(None))
except EOFError:
pass
def t_comment(t):
r'/\*(.|\n)*?\*/'
t.lexer.lineno += t.value.count('\n')
# Preprocessor directive (ignored)
def t_preprocessor(t):
r'\#(.)*?\n'
t.lexer.lineno += 1
def t_error(t):
print("Illegal character %s" % repr(t.value[0]))
t.lexer.skip(1)
lexer = lex.lex(optimize=1)
if __name__ == "__main__":
lex.runmain(lexer)
return t
def t_recipe_RECIPE_LINE(t):
r'.*\n'
t.type = 'RECIPE_LINE'
t.lexer.lineno += t.value.count("\n")
return t
# Error handling rule
def t_ANY_error(t):
print "Illegal character '%s' in line %s" % (t.value[0], t.lineno)
t.lexer.skip(1)
lexer = lex.lex(optimize=1)
if __name__ == "__main__":
lex.runmain(lexer)
def t_comment(t):
r'/\*(.|\n)*?\*/'
t.lexer.lineno += t.value.count('\n')
# Preprocessor directive (ignored)
def t_preprocessor(t):
r'\#(.)*?\n'
t.lexer.lineno += 1
def t_error(t):
print("Illegal character %s" % repr(t.value[0]))
t.lexer.skip(1)
lexer = lex.lex()
if __name__ == "__main__":
lex.runmain(lexer)
# Preprocessor directive (ignored)
def t_preprocessor(t):
r'\#(.)*?\n'
t.lexer.lineno += 1
def t_error(t):
print("Illegal character %s" % repr(t.value[0]))
t.lexer.skip(1)
lexer = lex.lex()
if __name__ == "__main__":
lex.runmain(lexer)
def t_comment(t):
r' /\*(.|\n)*?\*/'
t.lineno += t.value.count('\n')
# Preprocessor directive (ignored)
def t_preprocessor(t):
r'\#(.)*?\n'
t.lineno += 1
def t_error(t):
print "Illegal character %s" % repr(t.value[0])
t.lexer.skip(1)
lexer = lex.lex(optimize=1)
if __name__ == "__main__":
lex.runmain(lexer)