ohmjs / ohm

A library and language for building parsers, interpreters, compilers, etc.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to get any text inside parentheses?

kassadin opened this issue · comments

Just like get(any text), which is text inside,may be contains '(' ')',so can't use (~")" any)* .
I can do it with regular expressions, but how can I do it with ohm?
ohm

regexr

It depends on exactly what your language needs to support, but does including end in your lookahead help?

E.g.:

Text = "get" "(" parenthesized ")"
parenthesized = (~(")" end) any)*

Great!
I didn't realize that ~ could act on Sequence, I tried many times before in ~(a|b), now I can continue
Thank you.

Note that

parenthesized = (~(")" end) any)*

can be simplified to

parenthesized = (~")" any)*

(The end is not necessary b/c any does not succeed at the end of the file.)