protected override IEnumerable <Alpha> ReadImpl(ITextScanner scanner, ITextContext context) { foreach (var element in InnerLexer.Read(scanner, context)) { yield return(new Alpha(element)); } }
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)); } } }
protected override IEnumerable <HorizontalTab> ReadImpl(ITextScanner scanner, ITextContext context) { foreach (var terminal in InnerLexer.Read(scanner, context)) { yield return(new HorizontalTab(terminal)); } }
protected override IEnumerable <LinearWhiteSpace> ReadImpl(ITextScanner scanner, ITextContext context) { foreach (var repetition in InnerLexer.Read(scanner, context)) { yield return(new LinearWhiteSpace(repetition)); } }
protected override IEnumerable <CarriageReturn> ReadImpl(ITextScanner scanner, ITextContext context) { foreach (var terminal in InnerLexer.Read(scanner, context)) { yield return(new CarriageReturn(terminal)); } }
protected override IEnumerable <Term> ReadImpl(ITextScanner scanner, ITextContext context) { foreach (var concatenation in InnerLexer.Read(scanner, context)) { yield return(new Term(concatenation)); } }
protected override IEnumerable <Bit> ReadImpl(ITextScanner scanner, ITextContext context) { foreach (var alternation in InnerLexer.Read(scanner, context)) { yield return(new Bit(alternation)); } }
/// <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)); }
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))); }
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); } } } }
protected override IEnumerable <VisibleCharacter> ReadImpl(ITextScanner scanner, ITextContext context) { foreach (var terminal in InnerLexer.Read(scanner, context)) { yield return(new VisibleCharacter(terminal)); } }
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)); } }
protected override IEnumerable <SubcomponentsDelimiter> ReadImpl( ITextScanner scanner, ITextContext context) { foreach (var alternation in InnerLexer.Read(scanner, context)) { yield return(new SubcomponentsDelimiter(alternation)); } }
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)); } }
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)); } }
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)); } }
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)); } }
protected override IEnumerable <Method> ReadImpl( ITextScanner scanner, ITextContext context) { foreach (var token in InnerLexer.Read(scanner, context)) { yield return(new Method(token)); } }
protected override IEnumerable <LeastSignificantInt32> ReadImpl( ITextScanner scanner, ITextContext context) { foreach (var alternation in InnerLexer.Read(scanner, context)) { yield return(new LeastSignificantInt32(alternation)); } }
protected override IEnumerable <Fragment> ReadImpl( ITextScanner scanner, ITextContext context) { foreach (var repetition in InnerLexer.Read(scanner, context)) { yield return(new Fragment(repetition)); } }
protected override IEnumerable <ProtocolVersion> ReadImpl( ITextScanner scanner, ITextContext context) { foreach (var token in InnerLexer.Read(scanner, context)) { yield return(new ProtocolVersion(token)); } }
protected override IEnumerable <Connection> ReadImpl( ITextScanner scanner, ITextContext context) { foreach (var requiredDelimitedList in InnerLexer.Read(scanner, context)) { yield return(new Connection(requiredDelimitedList)); } }
protected override IEnumerable <TransferEncodingCollection> ReadImpl( ITextScanner scanner, ITextContext context) { foreach (var optionalDelimitedList in InnerLexer.Read(scanner, context)) { yield return(new TransferEncodingCollection(optionalDelimitedList)); } }