Sprache Part 9: Positioned
This is part of a series of posts documenting Sprache:
- Sprache Part 1: Parsing Characters
- Sprache Part 2: Parsing Strings
- Sprache Part 3: Repetition (Many, AtLeastOnce, Until, Repeat, Once)
- Sprache Part 4: Or and XOr
- Sprache Part 5: Select, Return, and Regex
- Sprache Part 6: DelimitedBy
- Sprache Part 7: ChainOperator and ChainRightOperator
- Sprache Part 8: Token, Contained, Identifier, LineTerminator
- Sprache Part 9: Positioned
- Sprache Part 10: Optional and XOptional
- Sprache Part 11: Parsing Comments
- Sprache Part 12: Ref, Named, End, Not, Except, Then, Where, Preview, Concat
This post covers the Positioned
method, intended to allow parsers to return information about the position of parsed elements in the input. To use this, the types returned by the parser must implement the IPositionAware
interface.
The below example implements a very simple expression parser which also returns position information.
|
|
Something thats a little awkward is that because of the generic type parameter each type in the inheritance hierachy needs to implement IPositionAware
separately for the Positioned
extension method to be usable.
Author Justin Pealing
LastMod 2020-05-23