Beispiel #1
0
        /// <summary>
        /// Parses the first matching item.
        /// </summary>
        public static TParser ParseFirst <TParser>(this Parser <LexicalToken, TParser> parser, LexicalToken[] tokens)
        {
            var source = new ArraySource <LexicalToken>(tokens);
            var result = parser.Parse(source, 0);

            return(result.Value);
        }
Beispiel #2
0
        /// <summary>
        /// Repeatedly parses all matching items.
        /// </summary>
        public static IEnumerable <TParser> ParseAll <TParser>(this Parser <LexicalToken, TParser> parser, LexicalToken[] tokens)
        {
            var source = new ArraySource <LexicalToken>(tokens);
            var start  = 0;

            while (!source.IsEnd(start))
            {
                var result = parser.Parse(source, start);

                if (result.Length <= 0)
                {
                    break;
                }

                yield return(result.Value);

                start += result.Length;
            }
        }
Beispiel #3
0
        /// <summary>
        /// Scans the first matching item.
        /// </summary>
        public static int ScanFirst(this Parser <LexicalToken> parser, string text, bool alwaysProduceEOF = false)
        {
            var source = new ArraySource <LexicalToken>(LexicalGrammar.GetTokens(text, alwaysProduceEOF));

            return(parser.Scan(source, 0));
        }