Sprache Part 2: Parsing Strings
Contents
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
Last time was all about parsing single characters, and all of the parsers returned char. This post goes through all of the primitive parsers that match multiple characters.
String
Parses a string of characters.
Parser<IEnumerable<char>> String(string s)
Note that the return type of this is IEnumerable<char> rather than string:
|
|
Text
Convert a stream of characters to a string.
Parser<string> Text(this Parser<IEnumerable<char>> characters)
This doesn’t change what input the parser consumes, it just converts the type returned from the parser. Its intended for use with parser that return char streams like String, or parsers constructed using Many.
|
|
IgnoreCase
Parse a string in a case-insensitive fashion.
Parser<char> IgnoreCase(char c)
|
|
Number
Parses numbers as strings, note that the return type is string, so Text is not required:
|
|
Decimal
Parse a decimal number using the current culture’s separator character.
|
|
DecimalInvariant
Parses a decimal number with the invariant culture.
|
|
LineEnd
Parses line endings.
|
|
Author Justin Pealing
LastMod 2020-03-16