kschiess / parslet

A small PEG based parser library. See the Hacking page in the Wiki as well.
kschiess.github.com/parslet
MIT License
809 stars 95 forks source link

Implicitly ignore whitespace? #57

Closed d11wtq closed 13 years ago

d11wtq commented 13 years ago

Is there a simple way to make it such that rules like the following assume there may be whitespace between the tokens, without the need to explicitly spell it out in every single rule? For example, using lex and yacc, you just make WSP a no-op and the lexer skips over it, meaning its not visible in your parse tree.

# simply
rule(:math_expr) { t_int.as(:left) >> operator.as(:op) >> t_int.as(:right) }

# rather than the verbose
rule(:math_expr) { t_int.as(:left) >> wsp? >> operator.as(:op) >> wsp? >> t_int.as(:right) }
kschiess commented 13 years ago

Will that do?

d11wtq commented 13 years ago

Ah, yes, thank you! I didn't realize you could just change the way the stream operates like that. It certainly looks like it would do the trick :)

Thanks for parslet!