diff options
Diffstat (limited to 'Lib/lib2to3/patcomp.py')
-rw-r--r-- | Lib/lib2to3/patcomp.py | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/Lib/lib2to3/patcomp.py b/Lib/lib2to3/patcomp.py index 24251cb..3831622 100644 --- a/Lib/lib2to3/patcomp.py +++ b/Lib/lib2to3/patcomp.py @@ -14,7 +14,7 @@ __author__ = "Guido van Rossum <guido@python.org>" import os # Fairly local imports -from .pgen2 import driver, literals, token, tokenize, parse +from .pgen2 import driver, literals, token, tokenize, parse, grammar # Really local imports from . import pytree @@ -138,7 +138,7 @@ class PatternCompiler(object): node = nodes[0] if node.type == token.STRING: value = str(literals.evalString(node.value)) - return pytree.LeafPattern(content=value) + return pytree.LeafPattern(_type_of_literal(value), value) elif node.type == token.NAME: value = node.value if value.isupper(): @@ -179,6 +179,15 @@ TOKEN_MAP = {"NAME": token.NAME, "TOKEN": None} +def _type_of_literal(value): + if value[0].isalpha(): + return token.NAME + elif value in grammar.opmap: + return grammar.opmap[value] + else: + return None + + def pattern_convert(grammar, raw_node_info): """Converts raw node information to a Node or Leaf instance.""" type, value, context, children = raw_node_info |