tree-sitter-cli icon indicating copy to clipboard operation
tree-sitter-cli copied to clipboard

Interpret arrays as sequences and implicitly sequence multiple rules

Open queerviolet opened this issue 7 years ago • 2 comments

This PR is purely ergonomic. I find that I keep doing things like this:

optional(',', $.decimal_digits)

(instead of

optional(seq(',', $.decimal_digits))

)

My time-of-confusion is dropping, but I'm still doing it occasionally, so I figure maybe it's worth just making it work.

As an also-nice-I-think side effect, this PR means we'll now interpret arrays as sequences when they occur as rule bodies.

queerviolet avatar Aug 02 '18 17:08 queerviolet

That's funny; I added a similar feature in the past but then reverted it, mainly because arrays have special meaning in other places of the grammar (conflicts, extras, externals, inline), and so auto-converting them to rules in certain cases seemed to muddy the waters more than it helped.

I think that I'd rather address this problem by having optional and repeat1 throw exceptions if you ever pass more than one argument, with an error like "Did you mean to put these rules in a seq or a choice?"

maxbrunsfeld avatar Aug 02 '18 17:08 maxbrunsfeld

Ahhhh. Okay, that's fair. I'll tweak this PR to do that.

queerviolet avatar Aug 02 '18 17:08 queerviolet