-
Hi, I am trying to parse a very simple language with PEGTL. I think I have found the problem, but don't understand why; white spaces are not ignored. I understand it must be possible to not ignore white space so that indentation-aware languages can also be parsed. But I couldn't find a mechanism to "eat" white spaces by default. Given:
the following cannot be parsed:
If I add How can white spaces be ignored/eaten/skipped for the entire grammar, without specifying those explicitly? Do I need a new control class? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
There is no way to generally ignore whitespace as it is one of the inherent properties of the PEG approach to not have a separate tokenisation pass. I'm also unsure what exactly eating spaces for the "entire grammar" would actually mean; if you change the control class to skip whitespace after every successful rule match you would probably allow whitespace in places you don't really want that. One could of course use another class template to control after which rules whitespace is to be skipped, but that might not be much easier than to embed the appropriate rules in the grammar. Let us know if you find a solution that could be of general use, we also haven't really thought much about this question because our usual approach is to embed the whitespace rules throughout the grammar. For example look at how the |
Beta Was this translation helpful? Give feedback.
-
pyparsing is also a PEG parser, but supports "ignore" rules whcih can be used for whitespace and comments. I don't know how it prevents the ignore rules from being matched in inappropriate places, such as in the middle of identifiers, keywords, or numeric literals. |
Beta Was this translation helpful? Give feedback.
There is no way to generally ignore whitespace as it is one of the inherent properties of the PEG approach to not have a separate tokenisation pass.
I'm also unsure what exactly eating spaces for the "entire grammar" would actually mean; if you change the control class to skip whitespace after every successful rule match you would probably allow whitespace in places you don't really want that.
One could of course use another class template to control after which rules whitespace is to be skipped, but that might not be much easier than to embed the appropriate rules in the grammar.
Let us know if you find a solution that could be of general use, we also haven't really thought much about th…