mirror of
https://github.com/Instagram/LibCST.git
synced 2025-12-23 10:35:53 +00:00
Fix parsing of nested parenthesis around Number nodes
The parser would lose track of nested parenthesis, because it was reading the wrong lpar/rpar value. Thanks for reporting this, @rayjzeng!
This commit is contained in:
parent
a8ca94691e
commit
11349acdea
2 changed files with 30 additions and 2 deletions
|
|
@ -61,7 +61,34 @@ class NumberTest(CSTNodeTest):
|
|||
parse_expression,
|
||||
CodeRange.create((1, 0), (1, 3)),
|
||||
),
|
||||
# TODO: add test cases for "((5))" and "(+((5)))"
|
||||
# multiple nested parenthesis
|
||||
(
|
||||
cst.Number(
|
||||
cst.Integer(
|
||||
"5",
|
||||
lpar=(cst.LeftParen(), cst.LeftParen()),
|
||||
rpar=(cst.RightParen(), cst.RightParen()),
|
||||
)
|
||||
),
|
||||
"((5))",
|
||||
parse_expression,
|
||||
CodeRange.create((1, 0), (1, 5)),
|
||||
),
|
||||
(
|
||||
cst.Number(
|
||||
lpar=(cst.LeftParen(),),
|
||||
operator=cst.Plus(),
|
||||
number=cst.Integer(
|
||||
"5",
|
||||
lpar=(cst.LeftParen(), cst.LeftParen()),
|
||||
rpar=(cst.RightParen(), cst.RightParen()),
|
||||
),
|
||||
rpar=(cst.RightParen(),),
|
||||
),
|
||||
"(+((5)))",
|
||||
parse_expression,
|
||||
CodeRange.create((1, 1), (1, 7)),
|
||||
),
|
||||
)
|
||||
)
|
||||
def test_valid(
|
||||
|
|
|
|||
|
|
@ -790,7 +790,8 @@ def convert_atom_parens(config: ParserConfig, children: Sequence[Any]) -> Any:
|
|||
return WithLeadingWhitespace(
|
||||
inner_atom.with_changes(
|
||||
number=inner_atom.number.with_changes(
|
||||
lpar=(lpar, *inner_atom.lpar), rpar=(*inner_atom.rpar, rpar)
|
||||
lpar=(lpar, *inner_atom.number.lpar),
|
||||
rpar=(*inner_atom.number.rpar, rpar),
|
||||
)
|
||||
),
|
||||
lpar_tok.whitespace_before,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue