Example #1
0
 protected override IEnumerable <Alpha> ReadImpl(ITextScanner scanner, ITextContext context)
 {
     foreach (var element in InnerLexer.Read(scanner, context))
     {
         yield return(new Alpha(element));
     }
 }
Example #2
0
 private IEnumerable <Repetition> Branch(
     [NotNull] ITextScanner scanner,
     [NotNull] ITextContext root,
     [NotNull] List <Element> elements)
 {
     if (elements.Count == UpperBound)
     {
         yield return(new Repetition(string.Concat(elements), elements, root));
     }
     else
     {
         var element = Lexer.Read(scanner);
         if (element != null)
         {
             var copy = new List <Element>(elements)
             {
                 element
             };
             foreach (var repetition in Branch(scanner, root, copy))
             {
                 yield return(repetition);
             }
         }
         else if (elements.Count >= LowerBound)
         {
             yield return(new Repetition(string.Concat(elements), elements, root));
         }
     }
 }
Example #3
0
 protected override IEnumerable <HorizontalTab> ReadImpl(ITextScanner scanner, ITextContext context)
 {
     foreach (var terminal in InnerLexer.Read(scanner, context))
     {
         yield return(new HorizontalTab(terminal));
     }
 }
Example #4
0
 protected override IEnumerable <LinearWhiteSpace> ReadImpl(ITextScanner scanner, ITextContext context)
 {
     foreach (var repetition in InnerLexer.Read(scanner, context))
     {
         yield return(new LinearWhiteSpace(repetition));
     }
 }
Example #5
0
 protected override IEnumerable <CarriageReturn> ReadImpl(ITextScanner scanner, ITextContext context)
 {
     foreach (var terminal in InnerLexer.Read(scanner, context))
     {
         yield return(new CarriageReturn(terminal));
     }
 }
Example #6
0
 protected override IEnumerable <Term> ReadImpl(ITextScanner scanner, ITextContext context)
 {
     foreach (var concatenation in InnerLexer.Read(scanner, context))
     {
         yield return(new Term(concatenation));
     }
 }
Example #7
0
 protected override IEnumerable <Bit> ReadImpl(ITextScanner scanner, ITextContext context)
 {
     foreach (var alternation in InnerLexer.Read(scanner, context))
     {
         yield return(new Bit(alternation));
     }
 }
Example #8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="scanner"></param>
        /// <exception cref="ArgumentNullException"></exception>
        /// <returns></returns>
        public override ReadResult <Alternative> Read(ITextScanner scanner)
        {
            if (scanner == null)
            {
                throw new ArgumentNullException(nameof(scanner));
            }
            var context = scanner.GetContext();
            IList <SyntaxError> errors       = new List <SyntaxError>(lexers.Length);
            SyntaxError         partialMatch = null;

            // ReSharper disable once ForCanBeConvertedToForeach
            for (var i = 0; i < lexers.Length; i++)
            {
                var result = lexers[i].ReadElement(scanner);
                if (result.Success)
                {
                    return(ReadResult <Alternative> .FromResult(new Alternative(result.Text, result.Element, context, i + 1)));
                }

                errors.Add(result.Error);
                if (partialMatch == null || result.Text.Length > partialMatch.Text.Length)
                {
                    partialMatch = result.Error;
                }
            }

            Debug.Assert(partialMatch != null, "partialMatch != null");
            return(ReadResult <Alternative> .FromSyntaxError(partialMatch));
        }
Example #9
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)));
        }
Example #10
0
 private IEnumerable <Concatenation> Branch(
     ITextScanner scanner,
     ITextContext root,
     List <Element> elements)
 {
     if (elements.Count == lexers.Count)
     {
         yield return(new Concatenation(string.Concat(elements), elements, root));
     }
     else
     {
         var next    = lexers[elements.Count];
         var element = next.Read(scanner);
         if (element != null)
         {
             var copy = new List <Element>(elements)
             {
                 element
             };
             foreach (var concat in Branch(scanner, root, copy))
             {
                 yield return(concat);
             }
         }
     }
 }
Example #11
0
 protected override IEnumerable <VisibleCharacter> ReadImpl(ITextScanner scanner, ITextContext context)
 {
     foreach (var terminal in InnerLexer.Read(scanner, context))
     {
         yield return(new VisibleCharacter(terminal));
     }
 }
Example #12
0
 protected override IEnumerable <UserInformation> ReadImpl(
     ITextScanner scanner,
     ITextContext context)
 {
     foreach (var repetition in InnerLexer.Read(scanner, context))
     {
         yield return(new UserInformation(repetition));
     }
 }
 protected override IEnumerable <AuthorityForm> ReadImpl(
     ITextScanner scanner,
     ITextContext context)
 {
     foreach (var authority in InnerLexer.Read(scanner, context))
     {
         yield return(new AuthorityForm(authority));
     }
 }
Example #14
0
 protected override IEnumerable <SubcomponentsDelimiter> ReadImpl(
     ITextScanner scanner,
     ITextContext context)
 {
     foreach (var alternation in InnerLexer.Read(scanner, context))
     {
         yield return(new SubcomponentsDelimiter(alternation));
     }
 }
Example #15
0
 protected override IEnumerable <BadWhiteSpace> ReadImpl(
     ITextScanner scanner,
     ITextContext context)
 {
     foreach (var optionalWhiteSpace in InnerLexer.Read(scanner, context))
     {
         yield return(new BadWhiteSpace(optionalWhiteSpace));
     }
 }
 protected override IEnumerable <TransferEncoding> ReadImpl(
     ITextScanner scanner,
     ITextContext context)
 {
     foreach (var requiredDelimitedList in InnerLexer.Read(scanner, context))
     {
         yield return(new TransferEncoding(requiredDelimitedList));
     }
 }
Example #17
0
 protected override IEnumerable <OptionalDelimitedList> ReadImpl(
     ITextScanner scanner,
     ITextContext context)
 {
     foreach (var repetition in InnerLexer.Read(scanner, context))
     {
         yield return(new OptionalDelimitedList(repetition));
     }
 }
 protected override IEnumerable <AsteriskForm> ReadImpl(
     ITextScanner scanner,
     ITextContext context)
 {
     foreach (var terminal in InnerLexer.Read(scanner, context))
     {
         yield return(new AsteriskForm(terminal));
     }
 }
 protected override IEnumerable <ChunkExtensionName> ReadImpl(
     ITextScanner scanner,
     ITextContext context)
 {
     foreach (var token in InnerLexer.Read(scanner, context))
     {
         yield return(new ChunkExtensionName(token));
     }
 }
 protected override IEnumerable <SegmentNonZeroLength> ReadImpl(
     ITextScanner scanner,
     ITextContext context)
 {
     foreach (var repetition in InnerLexer.Read(scanner, context))
     {
         yield return(new SegmentNonZeroLength(repetition));
     }
 }
Example #21
0
 public ReadImpl(
     [NotNull] Lexer <TElement> lexer,
     [NotNull] ITextScanner scanner,
     [NotNull] ITextContext context)
 {
     this.lexer   = lexer ?? throw new ArgumentNullException(nameof(lexer));
     this.scanner = scanner ?? throw new ArgumentNullException(nameof(scanner));
     this.context = context ?? throw new ArgumentNullException(nameof(context));
 }
 protected override IEnumerable <AbsolutePath> ReadImpl(
     ITextScanner scanner,
     ITextContext context)
 {
     foreach (var repetition in InnerLexer.Read(scanner, context))
     {
         yield return(new AbsolutePath(repetition));
     }
 }
Example #23
0
 public LexerImpl(
     [NotNull] Lexer <TElement> impl,
     [NotNull] ITextScanner scanner,
     [NotNull] ITextContext context)
 {
     this.impl    = impl;
     this.scanner = scanner;
     this.context = context;
 }
 protected override IEnumerable <TransferCodingCollection> ReadImpl(
     ITextScanner scanner,
     ITextContext context)
 {
     foreach (var alternation in InnerLexer.Read(scanner, context))
     {
         yield return(new TransferCodingCollection(alternation));
     }
 }
Example #25
0
 protected override IEnumerable <Method> ReadImpl(
     ITextScanner scanner,
     ITextContext context)
 {
     foreach (var token in InnerLexer.Read(scanner, context))
     {
         yield return(new Method(token));
     }
 }
Example #26
0
 protected override IEnumerable <LeastSignificantInt32> ReadImpl(
     ITextScanner scanner,
     ITextContext context)
 {
     foreach (var alternation in InnerLexer.Read(scanner, context))
     {
         yield return(new LeastSignificantInt32(alternation));
     }
 }
Example #27
0
 protected override IEnumerable <Fragment> ReadImpl(
     ITextScanner scanner,
     ITextContext context)
 {
     foreach (var repetition in InnerLexer.Read(scanner, context))
     {
         yield return(new Fragment(repetition));
     }
 }
Example #28
0
 protected override IEnumerable <ProtocolVersion> ReadImpl(
     ITextScanner scanner,
     ITextContext context)
 {
     foreach (var token in InnerLexer.Read(scanner, context))
     {
         yield return(new ProtocolVersion(token));
     }
 }
Example #29
0
 protected override IEnumerable <Connection> ReadImpl(
     ITextScanner scanner,
     ITextContext context)
 {
     foreach (var requiredDelimitedList in InnerLexer.Read(scanner, context))
     {
         yield return(new Connection(requiredDelimitedList));
     }
 }
Example #30
0
 protected override IEnumerable <TransferEncodingCollection> ReadImpl(
     ITextScanner scanner,
     ITextContext context)
 {
     foreach (var optionalDelimitedList in InnerLexer.Read(scanner, context))
     {
         yield return(new TransferEncodingCollection(optionalDelimitedList));
     }
 }