示例#1
0
class CallbackLexer(purplex.Lexer):
    FOO = purplex.TokenDef(r'foo')
    BAR = purplex.TokenDef(r'bar')
    BAZ = purplex.TokenDef(r'baz')

    def on_BAR(self, token):
        pass

    def on_BAZ(self, token):
        pass
示例#2
0
class MyLexer(purplex.Lexer):
    LABEL = purplex.TokenDef(r'[A-Z]+')
    AND = purplex.TokenDef(r'\&')
    BICOND = purplex.TokenDef(r'<->')
    COND = purplex.TokenDef(r'->')
    NOT = purplex.TokenDef(r'~')
    OR = purplex.TokenDef(r'v')
    LPAREN = purplex.TokenDef(r'\(')
    RPAREN = purplex.TokenDef(r'\)')
    WHITESPACE = purplex.TokenDef(r'[\s\n]+', ignore=True)
示例#3
0
class JavaScriptLexer(purplex.Lexer):
    """Lexer for a subset of JavaScript."""
    # TODO negatives? floats?
    INTEGER = purplex.TokenDef(r'\d+')
    FLOAT = purplex.TokenDef(r'[-+]?\d*[.]\d+')

    NULL = purplex.TokenDef(r'null')
    TRUE = purplex.TokenDef(r'true')
    FALSE = purplex.TokenDef(r'false')

    LIST_START = purplex.TokenDef(r'\[')
    LIST_END = purplex.TokenDef(r'\]')
    OBJECT_START = purplex.TokenDef(r'\{')
    OBJECT_END = purplex.TokenDef(r'\}')
    COMMA = purplex.TokenDef(r',')
    COLON = purplex.TokenDef(r':')

    STRING = purplex.TokenDef(_STRING_RE)
    # TODO more unquoted keys are allowed
    KEY = purplex.TokenDef(r'[a-zA-Z0-9_$]+')

    WHITESPACE = purplex.TokenDef(r'[\s\n]+', ignore=True)
示例#4
0
class JavaScriptLexer(purplex.Lexer):
    """Lexer for a subset of JavaScript."""
    # TODO: Negative integers
    INTEGER = purplex.TokenDef(r'\d+')
    FLOAT = purplex.TokenDef(r'[-+]?\d*[.]\d+')

    NULL = purplex.TokenDef(r'null')
    TRUE = purplex.TokenDef(r'true')
    FALSE = purplex.TokenDef(r'false')

    LIST_START = purplex.TokenDef(r'\[')
    LIST_END = purplex.TokenDef(r'\]')
    OBJECT_START = purplex.TokenDef(r'\{')
    OBJECT_END = purplex.TokenDef(r'\}')
    COMMA = purplex.TokenDef(r',')
    COLON = purplex.TokenDef(r':')

    STRING = purplex.TokenDef(
        '(\'(([^\\\\\'])|(\\\\.))*?\')|("(([^\\\\"])|(\\\\.))*?")')
    # TODO more unquoted keys are allowed
    KEY = purplex.TokenDef(r'[a-zA-Z0-9_$]+')

    WHITESPACE = purplex.TokenDef(r'[\s\n]+', ignore=True)
示例#5
0
class TieLexer_foosecond(purplex.Lexer):
    THREE_LETTERS = purplex.TokenDef(r'...')
    FOO = purplex.TokenDef(r'foo')
示例#6
0
class TieLexer_foofirst(purplex.Lexer):
    FOO = purplex.TokenDef(r'foo')
    THREE_LETTERS = purplex.TokenDef(r'...')
示例#7
0
class SubclassedLongestLexer(LongestLexer):
    QUAD_FOO = purplex.TokenDef(r'foofoofoofoo')
示例#8
0
class LongestLexer(purplex.Lexer):
    DOUBLE_FOO = purplex.TokenDef(r'foofoo')
    FOO = purplex.TokenDef(r'foo')
    TRIPLE_FOO = purplex.TokenDef(r'foofoofoo')
示例#9
0
class IgnoreLexer(purplex.Lexer):
    IDENT = purplex.TokenDef(r'[a-zA-Z]+')
    WHITESPACE = purplex.TokenDef('[\s\n]+', ignore=True)
示例#10
0
class FooBarLexer(purplex.Lexer):
    FOO = purplex.TokenDef(r'foo')
    BAR = purplex.TokenDef(r'bar')