-
-
Notifications
You must be signed in to change notification settings - Fork 187
Description
The current documentation states that the difference between State and Context is that Context can influence the parsing progress of the Parser, while State cannot. However, this is not the case. The Parser::try_map_with
method allows reading the current State and Context, and based on this, it can decide whether to fail the parsing at this point. This indicates that State, just like Context, has the ability to alter the parsing progress.
In my understanding, the real distinction between State and Context lies in their respective scopes. Simply put, State is "left-to-right," while Context is "top-down." If we organize all parsers into a tree, a parser can read State from previously parsed content, even if that content does not come directly from the parser's parent node (e.g., it could come from a left sibling of an ancestor node in the parsing tree, as long as its parsing occurred before this node). On the other hand, a parser can only read Context from one of its ancestor nodes (via Parser::then_with_ctx
or similar mechanisms).
I am currently implementing a C language parser, where left context is needed to distinguish between variable names and type names. In this use case, I found that using State rather than Context to store the context allows for a more natural implementation.
If my understanding is correct, please consider revising the documentation's description of State and Context.