ohmjs / ohm

A library and language for building parsers, interpreters, compilers, etc.
MIT License
5.01k stars 217 forks source link

Idiomatic way to do partial (prefix) parses #484

Open anton-trunov opened 4 months ago

anton-trunov commented 4 months ago

I'm probably missing it from the docs, but how do I parse only a prefix of the input? For instance, I have some preamble in my input that I need to parse separately, so I should get my CST and the rest of the input, much like in the style of parser combinators. E.g. parsing a comma-separated list from the following input string [4, 2]rest-of-input would give me the CST representation of the valid prefix [4, 2] and rest-of-input.

My current workaround includes something like PrefixRule' = PrefixRule any* and creating a separate parser starting with PrefixRule'.