Ejemplo n.º 1
0
        /// <summary>
        /// Creates the token.
        /// </summary>
        protected TToken CreateToken(TTokenType type, int charsFromEndToSkip = 0, Func <TToken, TokenError> errorProvider = null)
        {
            var t = NewToken();

            t.LineNumber    = CurrentLine;
            t.ColumnNumber  = Math.Max(0, PositionOnLine - DistanceSinceLastToken - 1);
            t.StartPosition = LastTokenPosition;
            t.Length        = DistanceSinceLastToken - charsFromEndToSkip;
            t.Type          = type;
            t.Text          = CurrentTokenChars.ToString().Substring(0, DistanceSinceLastToken - charsFromEndToSkip);
            Tokens.Add(t);
            if (errorProvider != null)
            {
                t.Error = errorProvider(t);
            }

            CurrentTokenChars.Remove(0, t.Length);
            LastTokenPosition = position - charsFromEndToSkip;

            OnTokenFound(t);

            return(LastToken = t);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates the token.
        /// </summary>
        protected TToken CreateToken(TTokenType type, int charsFromEndToSkip = 0, Func <TToken, TokenError> errorProvider = null)
        {
            LastToken = new TToken()
            {
                LineNumber    = CurrentLine,
                ColumnNumber  = Math.Max(0, PositionOnLine - DistanceSinceLastToken - 1),
                StartPosition = LastTokenPosition,
                Length        = DistanceSinceLastToken - charsFromEndToSkip,
                Type          = type,
                Text          = CurrentTokenChars.ToString().Substring(0, DistanceSinceLastToken - charsFromEndToSkip)
            };
            Tokens.Add(LastToken);
            if (errorProvider != null)
            {
                LastToken.Error = errorProvider(LastToken);
            }

            CurrentTokenChars.Remove(0, LastToken.Length);
            LastTokenPosition = reader.Position - charsFromEndToSkip;

            OnTokenFound(LastToken);

            return(LastToken);
        }
Ejemplo n.º 3
0
        protected TToken CreateToken(TTokenType type, int charsFromEndToSkip = 0, Func <TToken, TokenError>?errorProvider = null)
        {
            var text = CurrentTokenChars.ToString().Substring(0, DistanceSinceLastToken - charsFromEndToSkip);
            var t    = NewToken(text,
                                type,
                                lineNumber: CurrentLine,
                                columnNumber: Math.Max(0, PositionOnLine - DistanceSinceLastToken - 1),
                                length: DistanceSinceLastToken - charsFromEndToSkip,
                                startPosition: LastTokenPosition
                                );

            Tokens.Add(t);
            if (errorProvider != null)
            {
                t.Error = errorProvider(t);
            }

            CurrentTokenChars.Remove(0, t.Length);
            LastTokenPosition = position - charsFromEndToSkip;

            OnTokenFound(t);

            return(LastToken = t);
        }