tree-sitter-teal
tree-sitter-teal copied to clipboard
string_key field
A record_entry
is:
record_entry: $ => choice(
seq(
field("key", $.identifier),
":", field("type", $._type)
),
seq(
"[", field("string_key", $.string), "]",
":", field("type", $._type)
),
// TODO: there has to be a way around doing this, but I can't figure it out
...[ "type", "record", "enum", "userdata", "metamethod" ].map((reserved_id) => seq(
field("key", alias(reserved_id, $.identifier)),
":", field("type", $._type)
)),
seq(
"type", field("key", $.identifier), "=", field("value", choice($._type, $._newtype))
),
seq(
"record",
field("key", $.identifier),
field("typeargs", optional($.typeargs)),
field("value", $.record_body),
),
seq(
"enum", field("key", $.identifier),
field("value", $.enum_body),
),
),
Notice how every one of them has a "key" field, except for the case where the key may contain spaces. Is there a reason for this? As far as I can tell, this just makes things more complicated. If you need to make sure whether it is a string key or not, you can check the node kind - in the string key case, it will be a string
instead of an identifier
.