-
This code successfully parses any text:
However, if I move
it complains "the token list should not be empty". Why position of I'm also puzzled why token list is "empty" in second case? I've explicitly told it to use |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Defining tokens as separate declarations inside the grammar is needed for collecting the tokens and building a tokenizer on top of them. If you use tokens "inline" in other parsers, the grammar's current implementation won't be able to register the tokens and use them in a tokenizer. So, the workaround is to always declare tokens as delegated properties inside a grammar. Given that the set of tokens and their order really matters in parsing, following the convention of defining tokens as delegated properties also makes it more clear as to what tokens are there and in which order. The grammar implementation could potentially be improved in some ways that would make best effort to enforce registering tokens as properties. If you want, you can customize the logic for registering tokens in your grammar and override the grammar's |
Beta Was this translation helpful? Give feedback.
Defining tokens as separate declarations inside the grammar is needed for collecting the tokens and building a tokenizer on top of them. If you use tokens "inline" in other parsers, the grammar's current implementation won't be able to register the tokens and use them in a tokenizer.
So, the workaround is to always declare tokens as delegated properties inside a grammar.
Given that the set of tokens and their order really matters in parsing, following the convention of defining tokens as delegated properties also makes it more clear as to what tokens are there and in which order.
The grammar implementation could potentially be improved in some ways that would make best effort to enforce r…