Skip to content

Commit

Permalink
Merge pull request #47 from NixOS/issue_46_trailing_comma
Browse files Browse the repository at this point in the history
Fix #46: Trailing comma in function parameters
  • Loading branch information
JojOatXGME authored Jul 22, 2022
2 parents 452fe69 + 91324c7 commit 36b873e
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
### Removed

### Fixed
- Trailing commas reported as syntax error (#46)

### Security

Expand Down
2 changes: 1 addition & 1 deletion src/main/lang/Nix.bnf
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ private let_recover ::= braces_recover !(ASSERT | SEMI | IF | THEN | ELSE | LET

expr_lambda ::= lambda_params !missing_semi COLON expr { pin=3 }
private lambda_params ::= ID [ !missing_semi AT param_set ] | param_set [ !missing_semi AT ID ]
param_set ::= LCURLY [ ( param COMMA )* ( ELLIPSIS | param ) ] recover_param_set RCURLY { pin=1 }
param_set ::= LCURLY ( param COMMA )* [ ( ELLIPSIS | param ) ] recover_param_set RCURLY { pin=1 }
param ::= ID [ param_has ] { pin=2 recoverWhile=param_recover }
private param_has ::= HAS expr { pin=1 }
private param_recover ::= curly_recover !COMMA
Expand Down
8 changes: 8 additions & 0 deletions src/test/java/org/nixos/idea/lang/ParsingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ public void testFunction() {
doTest(true);
}

public void testFunctionEmptySet() {
doTest(true);
}

public void testFunctionTrailingComma() {
doTest(true);
}

public void testIdentifier() {
doTest(true);
}
Expand Down
1 change: 1 addition & 0 deletions src/test/testData/ParsingTest/FunctionEmptySet.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ }: null
10 changes: 10 additions & 0 deletions src/test/testData/ParsingTest/FunctionEmptySet.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Nix File(0,9)
NixExprLambdaImpl(EXPR_LAMBDA)(0,9)
NixParamSetImpl(PARAM_SET)(0,3)
PsiElement({)('{')(0,1)
PsiWhiteSpace(' ')(1,2)
PsiElement(})('}')(2,3)
PsiElement(:)(':')(3,4)
PsiWhiteSpace(' ')(4,5)
NixIdentifierImpl(IDENTIFIER)(5,9)
PsiElement(ID)('null')(5,9)
5 changes: 5 additions & 0 deletions src/test/testData/ParsingTest/FunctionTrailingComma.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[
({ x, }: null)
({ x, y, }: null)
({ x ? null, }: null)
]
65 changes: 65 additions & 0 deletions src/test/testData/ParsingTest/FunctionTrailingComma.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
Nix File(0,58)
NixListImpl(LIST)(0,58)
PsiElement([)('[')(0,1)
PsiWhiteSpace('\n')(1,2)
NixParensImpl(PARENS)(2,16)
PsiElement(()('(')(2,3)
NixExprLambdaImpl(EXPR_LAMBDA)(3,15)
NixParamSetImpl(PARAM_SET)(3,9)
PsiElement({)('{')(3,4)
PsiWhiteSpace(' ')(4,5)
NixParamImpl(PARAM)(5,6)
PsiElement(ID)('x')(5,6)
PsiElement(,)(',')(6,7)
PsiWhiteSpace(' ')(7,8)
PsiElement(})('}')(8,9)
PsiElement(:)(':')(9,10)
PsiWhiteSpace(' ')(10,11)
NixIdentifierImpl(IDENTIFIER)(11,15)
PsiElement(ID)('null')(11,15)
PsiElement())(')')(15,16)
PsiWhiteSpace('\n')(16,17)
NixParensImpl(PARENS)(17,34)
PsiElement(()('(')(17,18)
NixExprLambdaImpl(EXPR_LAMBDA)(18,33)
NixParamSetImpl(PARAM_SET)(18,27)
PsiElement({)('{')(18,19)
PsiWhiteSpace(' ')(19,20)
NixParamImpl(PARAM)(20,21)
PsiElement(ID)('x')(20,21)
PsiElement(,)(',')(21,22)
PsiWhiteSpace(' ')(22,23)
NixParamImpl(PARAM)(23,24)
PsiElement(ID)('y')(23,24)
PsiElement(,)(',')(24,25)
PsiWhiteSpace(' ')(25,26)
PsiElement(})('}')(26,27)
PsiElement(:)(':')(27,28)
PsiWhiteSpace(' ')(28,29)
NixIdentifierImpl(IDENTIFIER)(29,33)
PsiElement(ID)('null')(29,33)
PsiElement())(')')(33,34)
PsiWhiteSpace('\n')(34,35)
NixParensImpl(PARENS)(35,56)
PsiElement(()('(')(35,36)
NixExprLambdaImpl(EXPR_LAMBDA)(36,55)
NixParamSetImpl(PARAM_SET)(36,49)
PsiElement({)('{')(36,37)
PsiWhiteSpace(' ')(37,38)
NixParamImpl(PARAM)(38,46)
PsiElement(ID)('x')(38,39)
PsiWhiteSpace(' ')(39,40)
PsiElement(?)('?')(40,41)
PsiWhiteSpace(' ')(41,42)
NixIdentifierImpl(IDENTIFIER)(42,46)
PsiElement(ID)('null')(42,46)
PsiElement(,)(',')(46,47)
PsiWhiteSpace(' ')(47,48)
PsiElement(})('}')(48,49)
PsiElement(:)(':')(49,50)
PsiWhiteSpace(' ')(50,51)
NixIdentifierImpl(IDENTIFIER)(51,55)
PsiElement(ID)('null')(51,55)
PsiElement())(')')(55,56)
PsiWhiteSpace('\n')(56,57)
PsiElement(])(']')(57,58)

0 comments on commit 36b873e

Please sign in to comment.