Example #1
0
    # token()
    #
    # Method to return individual tokens
    # ----------------------------------------------------------------------
    def token(self):
        try:
            while True:
                tok = self.parser.next()
                if tok.type not in self.ignore: return tok
        except StopIteration:
            self.parser = None
            return None

if __name__ == '__main__':
    import pyflwor.ply.lex as lex
    lexer = lex.lex()

    # Run a preprocessor
    import sys
    f = open(sys.argv[1])
    input = f.read()

    p = Preprocessor(lexer)
    p.parse(input,sys.argv[1])
    while True:
        tok = p.token()
        if not tok: break
        print p.source, tok


Example #2
0
 def __new__(cls, **kwargs):
     self = super(Lexer, cls).__new__(cls, **kwargs)
     self.lexer = lex.lex(object=self, **kwargs)
     return self.lexer
Example #3
0
 def __new__(cls, **kwargs):
     self = super(Lexer, cls).__new__(cls, **kwargs)
     self.lexer = lex.lex(object=self, **kwargs)
     return self.lexer