Beispiel #1
0
        public override ReadResult <Terminal> Read(ITextScanner scanner)
        {
            if (scanner == null)
            {
                throw new ArgumentNullException(nameof(scanner));
            }
            var         context = scanner.GetContext();
            MatchResult result  = null;

            // ReSharper disable once ForCanBeConvertedToForeach
            for (var i = 0; i < valueRange.Length; i++)
            {
                var c = valueRange[i];
                result = scanner.TryMatch(c);
                if (result.EndOfInput)
                {
                    return(ReadResult <Terminal> .FromSyntaxError(SyntaxError.FromMatchResult(result, context)));
                }
                if (result.Success)
                {
                    return(ReadResult <Terminal> .FromResult(new Terminal(result.Text, context)));
                }
            }
            Debug.Assert(result != null, "result != null");
            return(ReadResult <Terminal> .FromSyntaxError(SyntaxError.FromMatchResult(result, context)));
        }
Beispiel #2
0
 protected override IEnumerable<Terminal> ReadImpl(ITextScanner scanner, ITextContext context)
 {
     if (scanner.Peek() == -1)
     {
         return Empty;
     }
     var result = scanner.TryMatch(terminal, comparer);
     if (result.IsMatch)
     {
         return new[] { new Terminal(result.Text, context) };
     }
     return Empty;
 }
Beispiel #3
0
        public override ReadResult <Terminal> Read(ITextScanner scanner)
        {
            if (scanner == null)
            {
                throw new ArgumentNullException(nameof(scanner));
            }
            var context = scanner.GetContext();
            var result  = scanner.TryMatch(terminal, comparer);

            if (result.Success)
            {
                return(ReadResult <Terminal> .FromResult(new Terminal(result.Text, context)));
            }
            return(ReadResult <Terminal> .FromSyntaxError(SyntaxError.FromMatchResult(result, context)));
        }
Beispiel #4
0
        protected override IEnumerable <Terminal> ReadImpl(ITextScanner scanner, ITextContext context)
        {
            if (scanner.Peek() == -1)
            {
                return(Empty);
            }

            // ReSharper disable once ForCanBeConvertedToForeach
            for (var i = 0; i < valueRange.Length; i++)
            {
                var c      = valueRange[i];
                var result = scanner.TryMatch(c);
                if (result.IsMatch)
                {
                    return(new[] { new Terminal(result.Text, context) });
                }
            }
            return(Empty);
        }