Hello,
I have this grammar:
@skip { spaces | newLine }
@top Program { Expr }
@precedence {
join @left
}
Expr {
JoinExpr
}
JoinExpr {
BasicExpr |
JoinExpr !join "," Expr
}
BoundedExpr {
"{" Expr "}"
}
BasicExpr {
String |
BoundedExpr
}
@tokens {
String { '"' (!["\\] | "\\" _)* '"' }
spaces[@export] { $[\u0009 \u000b\u00a0\u1680\u2000-\u200a\u202f\u205f\u3000\ufeff]+ }
newLine[@export] { $[\r\n\u2028\u2029] }
}
It works fine, for example this code {"a", "b"}
will produce this parse tree:
Program:
└╴Expr:
└╴JoinExpr:
└╴BasicExpr:
└╴BoundedExpr:
└╴Expr:
└╴JoinExpr:
├╴JoinExpr:
│ └╴BasicExpr:
│ └╴String: "a"
└╴Expr:
└╴JoinExpr:
└╴BasicExpr:
└╴String: "b"
Now I want to support the case with trailing comma before the closing brace like {"a", "b" ,}
How can I achieve that? I tried the following but not working:
@skip { spaces | newLine }
@top Program { Expr }
@precedence {
trailing,
join @left
}
Expr {
JoinExpr
}
JoinExpr {
BasicExpr |
JoinExpr !join "," Expr
}
BoundedExpr {
"{" Expr !trailing ","? "}"
}
BasicExpr {
String |
BoundedExpr
}
@tokens {
String { '"' (!["\\] | "\\" _)* '"' }
spaces[@export] { $[\u0009 \u000b\u00a0\u1680\u2000-\u200a\u202f\u205f\u3000\ufeff]+ }
newLine[@export] { $[\r\n\u2028\u2029] }
}
Any thoughts?