How to use the ply.lex.runmain function in ply

To help you get started, we’ve selected a few ply examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dabeaz / ply / test / lex_state_try.py View on Github external
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)
github dabeaz / ply / test / lex_optimize.py View on Github external
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")
github dabeaz / ply / test / lex_optimize3.py View on Github external
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")
github carpedm20 / program-synthesis-rl-tensorflow / karel / spec / lexer.py View on Github external
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)
github robotpy / robotpy-cppheaderparser / CppHeaderParser / lexer.py View on Github external
# 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
github gnachman / iTerm2 / tools / ply / ply-3.4 / example / ansic / clex.py View on Github external
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)
github grycap / im / IM / radl / radl_lex.py View on Github external
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)
github echronos / echronos / external_tools / ply_info / example / ansic / clex.py View on Github external
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)
github dabeaz / ply / example / ansic / clex.py View on Github external
# 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)
github gem5 / gem5 / ext / ply / example / ansic / clex.py View on Github external
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)