예제 #1
0
        /// <summary>
        /// Constructs a parser that consumes a whitespace and all comments
        /// parsed by the provider.Comment parser.
        /// </summary>
        /// <typeparam name="T">The result type of the given parser.</typeparam>
        /// <param name="parser">The parser to wrap.</param>
        /// <param name="provider">The provider for the Comment parser.</param>
        /// <returns>An extended Token() version of the given parser.</returns>
        public static Parser <T> Token <T>(this Parser <T> parser, ICommentParserProvider provider)
        {
            // if comment provider is not specified, act like normal Token()
            var trailingCommentParser =
                provider?.CommentParser?.AnyComment?.Token() ??
                Parse.WhiteSpace.Many().Text();

            // parse the value and as many trailing comments as possible
            return
                (from value in parser.Commented(provider).Token()
                 from comment in trailingCommentParser.Many()
                 select value.Value);
        }
예제 #2
0
 /// <summary>
 /// Constructs a parser that consumes a whitespace and all comments
 /// parsed by the provider.Comment parser, but parses only one trailing
 /// comment that starts exactly on the last line of the parsed value.
 /// </summary>
 /// <typeparam name="T">The result type of the given parser.</typeparam>
 /// <param name="parser">The parser to wrap.</param>
 /// <param name="provider">The provider for the Comment parser.</param>
 /// <returns>An extended Token() version of the given parser.</returns>
 public static Parser <IBeaconCommented <T> > Commented <T>(this Parser <T> parser, ICommentParserProvider provider) =>
 parser.Commented(provider?.CommentParser)
 .Select(x => (IBeaconCommented <T>) new Beacon <T>(x)).Positioned();
예제 #3
0
 /// <summary>
 /// Constructs a parser that consumes a whitespace and all comments
 /// parsed by the provider.Comment parser, but parses only one trailing
 /// comment that starts exactly on the last line of the parsed value.
 /// </summary>
 /// <typeparam name="T">The result type of the given parser.</typeparam>
 /// <param name="parser">The parser to wrap.</param>
 /// <param name="provider">The provider for the Comment parser.</param>
 /// <returns>An extended Token() version of the given parser.</returns>
 public static Parser <ICommented <T> > Commented <T>(this Parser <T> parser, ICommentParserProvider provider)
 {
     return(parser.Commented(provider?.CommentParser));
 }