paulstansifer / unseemly

Macros have types!
http://unseemly.github.io/
MIT License
131 stars 5 forks source link

Parse zero repetitions of something correctly #14

Open paulstansifer opened 5 years ago

paulstansifer commented 5 years ago

When we assemble a Node from its constituent Ast, we should check to see if any Named names in its grammar are absent from the parse result so far. If so, we should store them as zero copies of a repeated term because that's (presumably) what they are.

(They could also be under a branch of an Alt, but this seems like it's still an improvement in this case.)

See the TODO in earley::c_parse, in the Scope case.

End-to-end test that otherwise fails:

assert_m!(eval_unseemly_program("( .[ a : struct {} . a]. *[extra : five]*)"), Ok(_));
paulstansifer commented 2 years ago

The proposed method isn't a complete fix; what if we have Star(Star(Named(...))? You might have 5 copies at the first layer, each of which has zero copies, or you might have zero copies at the first layer (and the difference might matter).

The current representation for EnvMBEs is bad (#45), but I've made it more possible to represent zero-repetition repeats in this commit: https://github.com/paulstansifer/unseemly/commit/4973d811fe2485bdfbc388cae9160cfd6415e226