tree-sitter / tree-sitter-cli

CLI tool for creating and testing tree-sitter parsers
MIT License
45 stars 15 forks source link

Interpret arrays as sequences and implicitly sequence multiple rules #36

Open queerviolet opened 6 years ago

queerviolet commented 6 years ago

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.

maxbrunsfeld commented 6 years ago

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?"

queerviolet commented 6 years ago

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