Skip to content

Commit 794a32f

Browse files
author
Claudiu Popa
committed
Allow whitespaces before PrimaryExpressions.
Fix a pathological case where the elements of a PrimaryExpression are separated by whitespaces. For instance, having a newline after the dot of InvocationExpression is valid.
1 parent 8381f10 commit 794a32f

File tree

3 files changed

+7
-13
lines changed

3 files changed

+7
-13
lines changed

TODO

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
* The Command grammar can't parse the string "New-Object 'int[,]' 3,2"
22
* Pathological case for Command grammar for the string "New-Object -ArgumentList 3,2 -TypeName 'int[,]'"
33

4-
* Pathological case for SwitchCondition
5-
6-
($PSBoundParameters.GetEnumerator().
7-
Where({$_.Value -eq $true}).Key)
8-
94
* Pathological case for the following:
105

116
for ($i = 1; $i -le 10; ++$i) { "$i $($i*$i)" }

tests/test_grammar.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1571,9 +1571,8 @@ def test_switch_condition(self):
15711571
'-file C:\\obito',
15721572
'-file $ps1',
15731573

1574-
# TODO: other pathological case
1575-
# '($PSBoundParameters.GetEnumerator().\n'
1576-
# 'Where({$_.Value -eq $true}).Key)',
1574+
'($PSBoundParameters.GetEnumerator().\n'
1575+
'Where({$_.Value -eq $true}).Key)',
15771576
]
15781577
self._test_expected(SwitchCondition, parts)
15791578

wispy/grammar.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,7 @@ class ArgumentList(Grammar):
699699

700700

701701
class InvocationExpressionPrime(Grammar):
702-
grammar = (OR(".", "::"), MemberName,
702+
grammar = (OR(".", "::"), OPTIONAL(WHITESPACE), MemberName,
703703
ArgumentList, OPTIONAL(REF("InvocationExpressionPrime")))
704704

705705

@@ -793,18 +793,18 @@ class Value(Grammar):
793793

794794

795795
class PrimaryExpressionPrime(Grammar):
796-
grammar = OR(MemberAccessPrime,
796+
grammar = OR(InvocationExpressionPrime,
797+
MemberAccessPrime,
797798
ElementAccessPrime,
798-
InvocationExpressionPrime,
799799
PostIncrementExpressionPrime,
800800
PostDecrementExpressionPrime)
801801

802802

803803
class PrimaryExpression(Grammar):
804+
pe = (OPTIONAL(WHITESPACE), REPEAT(PrimaryExpressionPrime))
804805
grammar = (
805806
Value,
806-
OPTIONAL(OR(REPEAT(PrimaryExpressionPrime),
807-
REF('PrimaryExpression'))),
807+
OPTIONAL(OR(REPEAT(pe), REF('PrimaryExpression')))
808808
)
809809

810810

0 commit comments

Comments
 (0)