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
This post covers
Commented, which are helpers for parsing single and multi-line comments.
CommentParser class is a helper for parsing comments with members
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")
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
This parser is used extensively by the ApexSharp parser.
Author Justin Pealing