|
|
t | _lexer_cache = LRUCache(50) |
| |
|
| whitespace_re = re.compile(r"\s+") |
| |
|
| newline_re = re.compile(r"(\r\n|\r|\n)") |
| |
| | string_re |
| |
| | integer_re |
| |
| | float_re |
| |
|
| TOKEN_ADD = intern("add") |
| |
|
| TOKEN_ASSIGN = intern("assign") |
| |
|
| TOKEN_COLON = intern("colon") |
| |
|
| TOKEN_COMMA = intern("comma") |
| |
|
| TOKEN_DIV = intern("div") |
| |
|
| TOKEN_DOT = intern("dot") |
| |
|
| TOKEN_EQ = intern("eq") |
| |
|
| TOKEN_FLOORDIV = intern("floordiv") |
| |
|
| TOKEN_GT = intern("gt") |
| |
|
| TOKEN_GTEQ = intern("gteq") |
| |
|
| TOKEN_LBRACE = intern("lbrace") |
| |
|
| TOKEN_LBRACKET = intern("lbracket") |
| |
|
| TOKEN_LPAREN = intern("lparen") |
| |
|
| TOKEN_LT = intern("lt") |
| |
|
| TOKEN_LTEQ = intern("lteq") |
| |
|
| TOKEN_MOD = intern("mod") |
| |
|
| TOKEN_MUL = intern("mul") |
| |
|
| TOKEN_NE = intern("ne") |
| |
|
| TOKEN_PIPE = intern("pipe") |
| |
|
| TOKEN_POW = intern("pow") |
| |
|
| TOKEN_RBRACE = intern("rbrace") |
| |
|
| TOKEN_RBRACKET = intern("rbracket") |
| |
|
| TOKEN_RPAREN = intern("rparen") |
| |
|
| TOKEN_SEMICOLON = intern("semicolon") |
| |
|
| TOKEN_SUB = intern("sub") |
| |
|
| TOKEN_TILDE = intern("tilde") |
| |
|
| TOKEN_WHITESPACE = intern("whitespace") |
| |
|
| TOKEN_FLOAT = intern("float") |
| |
|
| TOKEN_INTEGER = intern("integer") |
| |
|
| TOKEN_NAME = intern("name") |
| |
|
| TOKEN_STRING = intern("string") |
| |
|
| TOKEN_OPERATOR = intern("operator") |
| |
|
| TOKEN_BLOCK_BEGIN = intern("block_begin") |
| |
|
| TOKEN_BLOCK_END = intern("block_end") |
| |
|
| TOKEN_VARIABLE_BEGIN = intern("variable_begin") |
| |
|
| TOKEN_VARIABLE_END = intern("variable_end") |
| |
|
| TOKEN_RAW_BEGIN = intern("raw_begin") |
| |
|
| TOKEN_RAW_END = intern("raw_end") |
| |
|
| TOKEN_COMMENT_BEGIN = intern("comment_begin") |
| |
|
| TOKEN_COMMENT_END = intern("comment_end") |
| |
|
| TOKEN_COMMENT = intern("comment") |
| |
|
| TOKEN_LINESTATEMENT_BEGIN = intern("linestatement_begin") |
| |
|
| TOKEN_LINESTATEMENT_END = intern("linestatement_end") |
| |
|
| TOKEN_LINECOMMENT_BEGIN = intern("linecomment_begin") |
| |
|
| TOKEN_LINECOMMENT_END = intern("linecomment_end") |
| |
|
| TOKEN_LINECOMMENT = intern("linecomment") |
| |
|
| TOKEN_DATA = intern("data") |
| |
|
| TOKEN_INITIAL = intern("initial") |
| |
|
| TOKEN_EOF = intern("eof") |
| |
| dict | operators |
| |
|
dict | reverse_operators = {v: k for k, v in operators.items()} |
| |
| | operator_re |
| |
| | ignored_tokens |
| |
| | ignore_if_empty |
| |
Implements a Jinja / Python combination lexer. The ``Lexer`` class
is used to do some preprocessing. It filters out invalid operators like
the bitshift operators we don't allow in templates. It separates
template code and python code in expressions.