Beispiel #1
0
        public bool ScanTokenAndProvideInfoAboutIt(TokenInfo tokenInfo, ref int state)
        {
            var token = stashedToken;
            stashedToken = null;
            if (token == null)
                try
                {
                    token = lexer.NextToken();
                }
                catch (Exception)
                {
                    tokenInfo.StartIndex = current;
                    tokenInfo.EndIndex = endIndex ;
                    tokenInfo.Type = TokenType.Text;  // it has to be Text rather than Comment, otherwise there will be no notification for the typing inside the token
                    tokenInfo.Color = TokenColor.Comment;
                    current = tokenInfo.EndIndex + 1;
                    stashedToken = null;
                    return true;
                }

            if (current < token.GetMappedColumn()-1)
            {
                tokenInfo.StartIndex = current;
                tokenInfo.EndIndex = Math.Min(endIndex, offset + token.GetMappedColumn() - 2);
                tokenInfo.Type = TokenType.Text;  // it has to be Text rather than Comment, otherwise there will be no notification for the typing inside the token
                tokenInfo.Color = TokenColor.Comment;
                current = tokenInfo.EndIndex + 2;
                stashedToken = token;
                return true;
            }

            if (token.Type == BooLexer.EOL || token.Type == BooLexer.EOF)
                return false;

            int quotes = 0;

            switch (GetTokenType(token))
            {
                case BooTokenType.DocumentString:
                    quotes = 6;
                    tokenInfo.Type = TokenType.String;
                    tokenInfo.Color = TokenColor.String;
                    break;

                case BooTokenType.String:
                    quotes = 2;
                    tokenInfo.Type = TokenType.String;
                    tokenInfo.Color = TokenColor.String;
                    break;

                case BooTokenType.MemberSelector:
                    tokenInfo.Type = TokenType.Text;
                    tokenInfo.Color = TokenColor.Text;
                    tokenInfo.Trigger = TokenTriggers.MemberSelect;
                    break;

                case BooTokenType.WhiteSpace:
                    tokenInfo.Type = TokenType.WhiteSpace;
                    tokenInfo.Color = TokenColor.Text;
                    break;

                case BooTokenType.Identifier:
                    tokenInfo.Type = TokenType.Identifier;
                    tokenInfo.Color = TokenColor.Text;
                    break;

                case BooTokenType.Keyword:
                    tokenInfo.Type = TokenType.Keyword;
                    tokenInfo.Color = TokenColor.Keyword;
                    break;

                default:
                    tokenInfo.Color = TokenColor.Text;
                    break;
            }

            tokenInfo.StartIndex = offset + token.GetMappedColumn() - 1;
            tokenInfo.EndIndex = Math.Min(endIndex, offset + quotes + token.GetMappedColumn() - 1 + token.getText().Length - 1);

            current = tokenInfo.EndIndex + 1;
            return true;
        }
Beispiel #2
0
        public bool ScanTokenAndProvideInfoAboutIt(TokenInfo tokenInfo, ref int state)
        {
            var token = stashedToken;

            stashedToken = null;
            if (token == null)
            {
                try
                {
                    token = lexer.NextToken();
                }
                catch (Exception e)
                {
                    if (e.Message.StartsWith("unexpected char:"))
                    {
                        return(false);
                    }
                    tokenInfo.StartIndex = current;
                    tokenInfo.EndIndex   = endIndex;
                    tokenInfo.Type       = TokenType.Text; // it has to be Text rather than Comment, otherwise there will be no notification for the typing inside the token
                    tokenInfo.Color      = TokenColor.Comment;
                    current      = tokenInfo.EndIndex + 1;
                    stashedToken = null;
                    return(true);
                }
            }

            if (current < token.GetMappedColumn() - 1)
            {
                tokenInfo.StartIndex = current;
                tokenInfo.EndIndex   = Math.Min(endIndex, offset + token.GetMappedColumn() - 2);
                tokenInfo.Type       = TokenType.Text; // it has to be Text rather than Comment, otherwise there will be no notification for the typing inside the token
                tokenInfo.Color      = TokenColor.Comment;
                current      = tokenInfo.EndIndex + 2;
                stashedToken = token;
                return(true);
            }

            if (token.Type == BooLexer.EOL || token.Type == BooLexer.EOF)
            {
                return(false);
            }

            int quotes = 0;

            switch (GetTokenType(token))
            {
            case BooTokenType.DocumentString:
                quotes          = 6;
                tokenInfo.Type  = TokenType.String;
                tokenInfo.Color = TokenColor.String;
                break;

            case BooTokenType.String:
                quotes          = 2;
                tokenInfo.Type  = TokenType.String;
                tokenInfo.Color = TokenColor.String;
                break;

            case BooTokenType.MemberSelector:
                tokenInfo.Type    = TokenType.Text;
                tokenInfo.Color   = TokenColor.Text;
                tokenInfo.Trigger = TokenTriggers.MemberSelect;
                break;

            case BooTokenType.WhiteSpace:
                tokenInfo.Type  = TokenType.WhiteSpace;
                tokenInfo.Color = TokenColor.Text;
                break;

            case BooTokenType.Identifier:
                tokenInfo.Type  = TokenType.Identifier;
                tokenInfo.Color = TokenColor.Text;
                break;

            case BooTokenType.Keyword:
                tokenInfo.Type  = TokenType.Keyword;
                tokenInfo.Color = TokenColor.Keyword;
                break;

            default:
                tokenInfo.Color = TokenColor.Text;
                break;
            }

            tokenInfo.StartIndex = offset + token.GetMappedColumn() - 1;
            if (token.getText() == null)
            {
                tokenInfo.EndIndex = tokenInfo.StartIndex;
            }
            else
            {
                tokenInfo.EndIndex = Math.Min(endIndex, offset + quotes + token.GetMappedColumn() - 1 + token.getText().Length - 1);
            }

            current = tokenInfo.EndIndex + 1;
            return(true);
        }