Skip to content

Commit

Permalink
panc: Adjust grammar to allow a single trailing comma in choice types
Browse files Browse the repository at this point in the history
This allows longer lists of choices to be line-wrapped more cleanly.

Also add line breaks and trailing commas to several tests to ensure this is tested.
  • Loading branch information
jrha committed Jan 27, 2025
1 parent dd39350 commit bb3944c
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 8 deletions.
2 changes: 1 addition & 1 deletion panc/src/main/jjtree/PanParser.jjt
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,7 @@ org.quattor.pan.ttemplate.SourceRange typeSpec() #TypeSpec :
org.quattor.pan.ttemplate.SourceRange baseTypeSpec() #BaseTypeSpec :
{ Token t = null, b=null, e=null; org.quattor.pan.utils.Range r = null; }
{
t=<CHOICE> <LPAREN> stringLiteral() (<COMMA> stringLiteral())* e=<RPAREN>
t=<CHOICE> <LPAREN> stringLiteral() (LOOKAHEAD(2) <COMMA> stringLiteral())* [ <COMMA> ] e=<RPAREN>
{
jjtThis.setIdentifier(t.image);
jjtThis.setSourceRange(PanParserUtils.sourceRangeFromTokens(t,(e!=null)?e:t));
Expand Down
7 changes: 6 additions & 1 deletion panc/src/test/pan/Functionality/choice/choice18.pan
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

object template choice18;

type mychoice = choice("aa", "bb", "aaa", "bbb");
type mychoice = choice(
"aa",
"bb",
"aaa",
"bbb",
);
bind '/x' = mychoice with length(SELF) == 3;
'/x' = "aaa";
7 changes: 6 additions & 1 deletion panc/src/test/pan/Functionality/choice/choice19.pan
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

object template choice19;

type mychoice = choice("aa", "bb", "aaa", "bbb");
type mychoice = choice(
"aa",
"bb",
"aaa",
"bbb",
);
bind '/x' = mychoice with length(SELF) == 3;
'/x' = "aa";
7 changes: 6 additions & 1 deletion panc/src/test/pan/Functionality/choice/choice20.pan
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

object template choice20;

type mychoice = choice("aa", "bb", "aaa", "bbb");
type mychoice = choice(
"aa",
"bb",
"aaa",
"bbb",
);
bind '/x' = mychoice with length(SELF) == 3;
'/x' = "ddd";
9 changes: 7 additions & 2 deletions panc/src/test/pan/Functionality/choice/choice21.pan
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

object template choice21;

type mychoice = choice("aa", "bb", "aaa", "bbb");
type mychoice = choice(
"aa",
"bb",
"aaa",
"bbb",
);
bind '/x' = mychoice(3);
'/x' = "aaa";
'/x' = "aaa";
9 changes: 7 additions & 2 deletions panc/src/test/pan/Functionality/choice/choice22.pan
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

object template choice22;

type mychoice = choice("aa", "bb", "aaa", "bbb");
type mychoice = choice(
"aa",
"bb",
"aaa",
"bbb",
);
bind '/x' = mychoice(3);
'/x' = "aa";
'/x' = "aa";

0 comments on commit bb3944c

Please sign in to comment.