Make the ParseContext trait more ergonomic #4
Labels
No labels
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
mle/selkirk#4
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Currently, implementing the
ParseContexttrait is somewhat awkward — theget_prefixandget_postfixfunctions have a lot of overlap, especially for delimiters, and it's easy to add a delimiter to one of them without remembering to add it to the other, or to add its matching delimiter, etc.Maybe this just means providing a useful impl of
ParseContextthat can be constructed without these problems, or maybe it means redesigning the trait itself.State transition table:
A "—" indicates that a token is not valid in that context
It's tempting for a
ParseContextto have a single lookup function, but that's not sufficient, since some tokens could have different meanings in different contexts — for example (in a prototypical arithmetic language):-is a prefix operator inInitialandPostOperatorstates, but a binary operator inPostTermstateeis a term inInitialandPostOperatorstates, but a binary operator inPostTermstateMaybe the lookup function can return a type like
For example:
-->Element::Both(Prefix::Unary(..), Postfix::Binary(..))e->Element::Both(Prefix::Term(..), Postfix::Binary(..))!->Element::Both(Prefix::Unary(..), Postfix::Postfix(..))(->Element::Delimiter(Delimiter::Left(..))*->Element::Postfix(Postfix::Binary)foobar->Element::Prefix(Prefix::Term(..))