/// <summary><inheritDoc/></summary> public virtual IToken NextToken() { if (i >= tokens.Count) { if (eofToken == null) { int start = -1; if (tokens.Count > 0) { int previousStop = tokens[tokens.Count - 1].StopIndex; if (previousStop != -1) { start = previousStop + 1; } } int stop = Math.Max(-1, start - 1); eofToken = _factory.Create(Tuple.Create((ITokenSource)this, InputStream), TokenConstants.EOF, "EOF", TokenConstants.DefaultChannel, start, stop, Line, Column); } return(eofToken); } IToken t = tokens[i]; if (i == tokens.Count - 1 && t.Type == TokenConstants.EOF) { eofToken = t; } i++; return(t); }
public Lexer(ICharStream input, TextWriter output, TextWriter errorOutput) { this._input = input; this.Output = output; this.ErrorOutput = errorOutput; this._tokenFactorySourcePair = Tuple.Create((ITokenSource)this, input); }
/// <summary>Set the char stream and reset the lexer</summary> public virtual void SetInputStream(ICharStream input) { this._input = null; this._tokenFactorySourcePair = Tuple.Create((ITokenSource)this, _input); Reset(); this._input = input; this._tokenFactorySourcePair = Tuple.Create((ITokenSource)this, _input); }
public virtual IList <Sharpen.Tuple <K, V> > GetPairs() { IList <Sharpen.Tuple <K, V> > pairs = new ArrayList <Sharpen.Tuple <K, V> >(); foreach (KeyValuePair <K, IList <V> > pair in this) { foreach (V value in pair.Value) { pairs.Add(Tuple.Create(pair.Key, value)); } } return(pairs); }
protected internal virtual IToken ConstructToken(ITokenSource tokenSource, int expectedTokenType, string tokenText, IToken current) { ITokenFactory factory = tokenSource.TokenFactory; return(factory.Create(Tuple.Create(tokenSource, current.TokenSource.InputStream), expectedTokenType, tokenText, TokenConstants.DefaultChannel, -1, -1, current.Line, current.Column)); }