I don’t think this is a bug, but perhaps?
I can get my grammar to work when I use lower case for “element-attribute” like so:
@top Atom { Text | Element }
Element { tag-name element-attributes }
element-attributes { "[" element-attribute "]" }
element-attribute { tag-name }
Text { string }
@tokens {
tag-name { $[a-z0-9#\-\.]+ '+'? }
string { '"' char* '"' }
char { $[\u{20}\u{21}\u{23}-\u{5b}\u{5d}-\u{10ffff}] | "\\" esc }
esc { $["\\\/bfnrt] | "u" hex hex hex hex }
hex { $[0-9a-fA-F] }
ws { $[ \n\r\t] }
}
@detectDelim
Give an input like “div[disabled]”, this produces
{
"type": {
"name": "Atom",
"props": {},
"id": 1,
"flags": 1
},
"children": [
{
"type": {
"name": "Element",
"props": {},
"id": 3,
"flags": 0
},
"children": [],
"positions": [],
"length": 13
}
],
"positions": [
0
],
"length": 13
}
However, I’d like “ElementAttribute” to be part of the syntax tree, so I capitalize:
@top Atom { Text | Element }
Element { tag-name element-attributes }
element-attributes { "[" ElementAttribute "]" }
ElementAttribute { tag-name }
Text { string }
@tokens {
tag-name { $[a-z0-9#\-\.]+ '+'? }
string { '"' char* '"' }
char { $[\u{20}\u{21}\u{23}-\u{5b}\u{5d}-\u{10ffff}] | "\\" esc }
esc { $["\\\/bfnrt] | "u" hex hex hex hex }
hex { $[0-9a-fA-F] }
ws { $[ \n\r\t] }
}
@detectDelim
Now the output given “div[disabled]” is ambiguous:
{
"type": {
"name": "Atom",
"props": {},
"id": 1,
"flags": 1
},
"children": [
{
"buffer": {
"0": 3,
"1": 0,
"2": 13,
"3": 8,
"4": 4,
"5": 4,
"6": 12,
"7": 8
},
"length": 13,
"set": {
"types": [
{
"name": "⚠",
"props": {},
"id": 0,
"flags": 6
},
{
"name": "Atom",
"props": {},
"id": 1,
"flags": 1
},
{
"name": "Text",
"props": {},
"id": 2,
"flags": 0
},
{
"name": "Element",
"props": {},
"id": 3,
"flags": 0
},
{
"name": "ElementAttribute",
"props": {},
"id": 4,
"flags": 0
}
]
},
"type": {
"name": "",
"props": {},
"id": 0,
"flags": 8
}
}
],
"positions": [
0
],
"length": 13
}
I’m confused on how this subtle difference causes the grammar to break. Perhaps I’m missing something fundamental about LR, would appreciate any pointers.