Sync NT joined_str and formmated_value with AST

This commit is contained in:
rocky
2017-12-05 23:17:51 -05:00
parent e064791870
commit 7b39002476
2 changed files with 13 additions and 10 deletions

View File

@@ -39,7 +39,10 @@ class PythonParser(GenericASTBuilder):
'print_items', 'print_items',
# PyPy: # PyPy:
'imports_cont', 'imports_cont',
'kvlist_n'] 'kvlist_n',
# Python 3.6+
'joined_str',
]
self.collect = frozenset(nt_list) self.collect = frozenset(nt_list)
def ast_first_offset(self, ast): def ast_first_offset(self, ast):

View File

@@ -88,20 +88,20 @@ class Python36Parser(Python35Parser):
self.add_unique_doc_rules(rules_str, customize) self.add_unique_doc_rules(rules_str, customize)
elif opname == 'BUILD_STRING': elif opname == 'BUILD_STRING':
v = token.attr v = token.attr
fstring_expr_or_str_n = "fstring_expr_or_str_%s" % v joined_str_n = "formatted_value_%s" % v
rules_str = """ rules_str = """
expr ::= fstring_expr expr ::= fstring_expr
fstring_expr ::= expr FORMAT_VALUE fstring_expr ::= expr FORMAT_VALUE
str ::= LOAD_CONST str ::= LOAD_CONST
fstring_expr_or_str ::= fstring_expr formatted_value ::= fstring_expr
fstring_expr_or_str ::= str formatted_value ::= str
expr ::= fstring_multi expr ::= fstring_multi
fstring_multi ::= fstring_expr_or_strs BUILD_STRING fstring_multi ::= joined_str BUILD_STRING
fstring_expr_or_strs ::= fstring_expr_or_str+ joined_str ::= formatted_value+
fstring_multi ::= %s BUILD_STRING fstring_multi ::= %s BUILD_STRING
%s ::= %sBUILD_STRING %s ::= %sBUILD_STRING
""" % (fstring_expr_or_str_n, fstring_expr_or_str_n, "fstring_expr_or_str " * v) """ % (joined_str_n, joined_str_n, "formatted_value " * v)
self.add_unique_doc_rules(rules_str, customize) self.add_unique_doc_rules(rules_str, customize)
def custom_classfunc_rule(self, opname, token, customize, def custom_classfunc_rule(self, opname, token, customize,