mirror of
https://github.com/python/cpython.git
synced 2025-12-10 11:00:14 +00:00
merge 2to3 improvments
This commit is contained in:
parent
afcd5f36f0
commit
dd6a4edc45
18 changed files with 405 additions and 140 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue