kach / nearley

📜🔜🌲 Simple, fast, powerful parser toolkit for JavaScript.
https://nearley.js.org
MIT License
3.6k stars 232 forks source link

How to match until next non-terminal rule? #520

Closed customcommander closed 4 years ago

customcommander commented 4 years ago

Apologies in advance for cross-posting. (See my question on Stack Overflow.)

TL; DR

I'm really struggling to come up with a rule that can either match until end of line or until next non-terminal rule.

I'm trying to write a parser for RIS content:

KW  - foo
KW  - bar
KW  - baz

Extracting foo, bar and baz is easy but things get complicated when KW spans across multiple line:

KW  - foo
bar
KW  - baz

Is this something that Nearly can handle? Any tips towards the right direction would be greatly appreciated.

Many thanks.

customcommander commented 4 years ago

I managed to find a solution thanks to @airportyh !