Sprache Part 11: Parsing Comments
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
This post covers CommentParser
and Commented
, which are helpers for parsing single and multi-line comments.
CommentParser
The CommentParser
class is a helper for parsing comments with members SingleLineComment
, MultiLineComment
and AnyComment
for parsing different comment types, for example to parse XML comments
|
|
The default constructor creates a comment parser for parsing C style comments, and is equivalent to new CommentParser("//", "/*", "*/", "\n")
|
|
Commented
Constructs a parser that consumes a whitespace and all comments parsed by the commentParser.AnyComment parser, but parses only one trailing comment that starts exactly on the last line of the parsed value.
Parser<ICommented<T>> Commented<T>(this Parser<T> parser, IComment commentParser = null)
If a comment parser is not supplied then the default comment parser (which parses C style comments) is used. The return ICommented
type has properties for accessing the leading and trailing comments, as well as the element parsed by parser
.
|
|
This parser is used extensively by the ApexSharp parser.
Author Justin Pealing
LastMod 2020-06-19