mirror of
https://github.com/davidhalter/parso.git
synced 2025-12-15 08:57:11 +08:00
Use strings as a non-terminal symbol in all grammars
This makes it easier to write the same logic for all Python versions
This commit is contained in:
@@ -119,7 +119,8 @@ atom: ('(' [yield_expr|testlist_comp] ')' |
|
|||||||
'[' [listmaker] ']' |
|
'[' [listmaker] ']' |
|
||||||
'{' [dictorsetmaker] '}' |
|
'{' [dictorsetmaker] '}' |
|
||||||
'`' testlist1 '`' |
|
'`' testlist1 '`' |
|
||||||
NAME | NUMBER | STRING+)
|
NAME | NUMBER | strings)
|
||||||
|
strings: STRING+
|
||||||
listmaker: test ( list_for | (',' test)* [','] )
|
listmaker: test ( list_for | (',' test)* [','] )
|
||||||
# Dave: Renamed testlist_gexpr to testlist_comp, because in 2.7+ this is the
|
# Dave: Renamed testlist_gexpr to testlist_comp, because in 2.7+ this is the
|
||||||
# default. It's more consistent like this.
|
# default. It's more consistent like this.
|
||||||
|
|||||||
@@ -104,7 +104,8 @@ atom: ('(' [yield_expr|testlist_comp] ')' |
|
|||||||
'[' [listmaker] ']' |
|
'[' [listmaker] ']' |
|
||||||
'{' [dictorsetmaker] '}' |
|
'{' [dictorsetmaker] '}' |
|
||||||
'`' testlist1 '`' |
|
'`' testlist1 '`' |
|
||||||
NAME | NUMBER | STRING+)
|
NAME | NUMBER | strings)
|
||||||
|
strings: STRING+
|
||||||
listmaker: test ( list_for | (',' test)* [','] )
|
listmaker: test ( list_for | (',' test)* [','] )
|
||||||
testlist_comp: test ( comp_for | (',' test)* [','] )
|
testlist_comp: test ( comp_for | (',' test)* [','] )
|
||||||
lambdef: 'lambda' [varargslist] ':' test
|
lambdef: 'lambda' [varargslist] ':' test
|
||||||
|
|||||||
@@ -103,7 +103,8 @@ power: atom trailer* ['**' factor]
|
|||||||
atom: ('(' [yield_expr|testlist_comp] ')' |
|
atom: ('(' [yield_expr|testlist_comp] ')' |
|
||||||
'[' [testlist_comp] ']' |
|
'[' [testlist_comp] ']' |
|
||||||
'{' [dictorsetmaker] '}' |
|
'{' [dictorsetmaker] '}' |
|
||||||
NAME | NUMBER | STRING+ | '...' | 'None' | 'True' | 'False')
|
NAME | NUMBER | strings | '...' | 'None' | 'True' | 'False')
|
||||||
|
strings: STRING+
|
||||||
testlist_comp: (test|star_expr) ( comp_for | (',' (test|star_expr))* [','] )
|
testlist_comp: (test|star_expr) ( comp_for | (',' (test|star_expr))* [','] )
|
||||||
trailer: '(' [arglist] ')' | '[' subscriptlist ']' | '.' NAME
|
trailer: '(' [arglist] ')' | '[' subscriptlist ']' | '.' NAME
|
||||||
subscriptlist: subscript (',' subscript)* [',']
|
subscriptlist: subscript (',' subscript)* [',']
|
||||||
|
|||||||
@@ -103,7 +103,8 @@ power: atom trailer* ['**' factor]
|
|||||||
atom: ('(' [yield_expr|testlist_comp] ')' |
|
atom: ('(' [yield_expr|testlist_comp] ')' |
|
||||||
'[' [testlist_comp] ']' |
|
'[' [testlist_comp] ']' |
|
||||||
'{' [dictorsetmaker] '}' |
|
'{' [dictorsetmaker] '}' |
|
||||||
NAME | NUMBER | STRING+ | '...' | 'None' | 'True' | 'False')
|
NAME | NUMBER | strings | '...' | 'None' | 'True' | 'False')
|
||||||
|
strings: STRING+
|
||||||
testlist_comp: (test|star_expr) ( comp_for | (',' (test|star_expr))* [','] )
|
testlist_comp: (test|star_expr) ( comp_for | (',' (test|star_expr))* [','] )
|
||||||
trailer: '(' [arglist] ')' | '[' subscriptlist ']' | '.' NAME
|
trailer: '(' [arglist] ')' | '[' subscriptlist ']' | '.' NAME
|
||||||
subscriptlist: subscript (',' subscript)* [',']
|
subscriptlist: subscript (',' subscript)* [',']
|
||||||
|
|||||||
@@ -110,7 +110,8 @@ atom_expr: ['await'] atom trailer*
|
|||||||
atom: ('(' [yield_expr|testlist_comp] ')' |
|
atom: ('(' [yield_expr|testlist_comp] ')' |
|
||||||
'[' [testlist_comp] ']' |
|
'[' [testlist_comp] ']' |
|
||||||
'{' [dictorsetmaker] '}' |
|
'{' [dictorsetmaker] '}' |
|
||||||
NAME | NUMBER | STRING+ | '...' | 'None' | 'True' | 'False')
|
NAME | NUMBER | strings | '...' | 'None' | 'True' | 'False')
|
||||||
|
strings: STRING+
|
||||||
testlist_comp: (test|star_expr) ( comp_for | (',' (test|star_expr))* [','] )
|
testlist_comp: (test|star_expr) ( comp_for | (',' (test|star_expr))* [','] )
|
||||||
trailer: '(' [arglist] ')' | '[' subscriptlist ']' | '.' NAME
|
trailer: '(' [arglist] ')' | '[' subscriptlist ']' | '.' NAME
|
||||||
subscriptlist: subscript (',' subscript)* [',']
|
subscriptlist: subscript (',' subscript)* [',']
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
from parso.python import tree
|
from parso.python import tree
|
||||||
from parso.python.token import (DEDENT, INDENT, ENDMARKER, NEWLINE, NUMBER,
|
from parso.python.token import (DEDENT, INDENT, ENDMARKER, NEWLINE, NUMBER,
|
||||||
STRING, tok_name, NAME)
|
STRING, tok_name, NAME, FSTRING_STRING)
|
||||||
from parso.parser import BaseParser
|
from parso.parser import BaseParser
|
||||||
from parso.pgen2.parse import token_to_ilabel
|
from parso.pgen2.parse import token_to_ilabel
|
||||||
|
|
||||||
@@ -129,6 +129,8 @@ class Parser(BaseParser):
|
|||||||
return tree.Newline(value, start_pos, prefix)
|
return tree.Newline(value, start_pos, prefix)
|
||||||
elif type == ENDMARKER:
|
elif type == ENDMARKER:
|
||||||
return tree.EndMarker(value, start_pos, prefix)
|
return tree.EndMarker(value, start_pos, prefix)
|
||||||
|
elif type == FSTRING_STRING:
|
||||||
|
return tree.FStringString(value, start_pos, prefix)
|
||||||
else:
|
else:
|
||||||
return tree.Operator(value, start_pos, prefix)
|
return tree.Operator(value, start_pos, prefix)
|
||||||
|
|
||||||
|
|||||||
@@ -262,6 +262,15 @@ class String(Literal):
|
|||||||
return match.group(2)[:-len(match.group(1))]
|
return match.group(2)[:-len(match.group(1))]
|
||||||
|
|
||||||
|
|
||||||
|
class FStringString(Leaf):
|
||||||
|
"""
|
||||||
|
f-strings contain f-string expressions and normal python strings. These are
|
||||||
|
the string parts of f-strings.
|
||||||
|
"""
|
||||||
|
type = 'fstring_string'
|
||||||
|
__slots__ = ()
|
||||||
|
|
||||||
|
|
||||||
class _StringComparisonMixin(object):
|
class _StringComparisonMixin(object):
|
||||||
def __eq__(self, other):
|
def __eq__(self, other):
|
||||||
"""
|
"""
|
||||||
|
|||||||
Reference in New Issue
Block a user