Пример #1
0
        public virtual void Reset(string text)
        {
            int length;

            if (text == null)
            {
                length = 0;
                _text  = new char[length + 1];
            }
            else
            {
                length = text.Length;
                _text  = new char[length + 1];
                text.CopyTo(0, _text, 0, length);
            }
            _text[length] = '\0';

            _pos            = 0;
            _start          = 0;
            _end            = 0;
            _lastTokenStart = 0;
            _lastTokenEnd   = 0;
            _line           = 0;
            _column         = 0;
            _lineStart      = 0;

            _token = new Token(null, TokenTypeInfo.GetTokenTypeInfo(TokenType.EOF), _pos, _pos, new Location(this.CurrentPosition(), this.CurrentPosition()));

            // The context stack is used to superficially track syntactic
            // context to predict whether a regular expression is allowed in a
            // given position.
            _contexts = new Stack <TokenContext>();
            _contexts.Push(TokenContext.BraceStatement);
            _exprAllowed = true;
        }
Пример #2
0
        protected void FinishToken(TokenType type, string value)
        {
            _end = _pos;
            var preToken = this._token;

            _token = new Token(value, TokenTypeInfo.GetTokenTypeInfo(type), _start, _end, new Location(this._startPos, this.CurrentPosition()));
            this.UpdateContext(preToken);
        }
Пример #3
0
 public Token(string value, TokenTypeInfo info, int start, int end, Location loc)
 {
     Value          = value;
     Info           = info;
     Start          = start;
     End            = end;
     SourceLocation = loc;
 }
Пример #4
0
 private static void SetTokenTypeInfo(TokenType tokenType, TokenTypeInfo info)
 {
     info.Type = tokenType;
     TokenTypes.Add(tokenType, info);
 }
Пример #5
0
 private static void SetBinop(TokenType tokenType, TokenTypeInfo info)
 {
     info.BeforeExpr = true;
     SetTokenTypeInfo(tokenType, info);
 }
Пример #6
0
 private static void SetKeyword(TokenType tokenType, TokenTypeInfo info)
 {
     info.Keyword = info.Label;
     Keywords.Add(info.Keyword, tokenType);
     SetTokenTypeInfo(tokenType, info);
 }