Inheritance: NVLiteralExpression
Exemplo n.º 1
0
        private NVExpression ParseNVStringLiteralOrDictionary()
        {
            // NVStringLiteralOrDictionary -> { nvText | NVReference }
            //                             -> "%" "{" [ NVDictionaryItem { "," NVDictionaryItem } ] "}".

            NVExpression expr = null;

            if (CurrentTokenType == TokenType.NVDictionaryPercent)
            {
                _scanner.GetToken();

                MatchToken(TokenType.NVDictionaryLCurly);

                if (CurrentTokenType == TokenType.NVDictionaryKey)
                {
                    ParseNVDictionaryItem();

                    while (CurrentTokenType == TokenType.NVComma)
                    {
                        _scanner.GetToken();

                        ParseNVDictionaryItem();
                    }
                }

                MatchToken(TokenType.NVDictionaryRCurly);

                //TODO: Change to DictionaryExpression, this is just a
                expr = new NVBoolExpression(false);
                expr.Position = new Position(GetCurrentTokenPosition());
            }
            else
            {
                //TODO: { nvText | NVReference }
                while (CurrentTokenType != TokenType.NVDoubleQuote)
                {
                    if (CurrentTokenType == TokenType.NVStringLiteral)
                    {
                        expr = new NVStringExpression(_scanner.CurrentToken.Image);
                        expr.Position = new Position(GetCurrentTokenPosition());
                    }
                    //TODO make only work in intellisense mode
                    else if (CurrentTokenType == TokenType.Error)
                    {
                        //TODO: check if this is causing CVSI to lock up
                        return new NVStringExpression("");
                    }
                    else
                    {
                        AddError(string.Format("Unexpected token type '{0}'", CurrentTokenType));
                        break;
                    }
                    _scanner.GetToken();
                }
            }

            return expr;
        }
Exemplo n.º 2
0
        private NVExpression ParseNVPrimary()
        {
            // NVPrimary -> NVReference
            //           -> "(" NVExpression ")"
            //           -> "true"
            //           -> "false"
            //           -> nvIntegerLiteral
            //           -> "'" nvStringLiteral "'"
            //           -> "\"" NVStringLiteralOrDictionary "\""
            //           -> "[" [ NVExpression NVRangeOrArray ] "]".

            NVExpression expr = null;

            if (CurrentTokenType == TokenType.NVDollar)
            {
                //TODO: Change to ParseNVDesignatorExpression
                ParseNVReference();

                expr = new NVBoolExpression(false);
                expr.Position = new Position(GetCurrentTokenPosition());
            }
            else if (CurrentTokenType == TokenType.NVLParen)
            {
                _scanner.GetToken();

                expr = ParseNVExpression();

                MatchToken(TokenType.NVRParen);
            }
            else if (CurrentTokenType == TokenType.NVTrue)
            {
                expr = new NVBoolExpression(true);
                expr.Position = new Position(GetCurrentTokenPosition());
                _scanner.GetToken();
            }
            else if (CurrentTokenType == TokenType.NVFalse)
            {
                expr = new NVBoolExpression(false);
                expr.Position = new Position(GetCurrentTokenPosition());
                _scanner.GetToken();
            }
            else if (CurrentTokenType == TokenType.NVIntegerLiteral)
            {
                expr = new NVNumExpression(int.Parse(_scanner.CurrentToken.Image));
                expr.Position = new Position(GetCurrentTokenPosition());
                _scanner.GetToken();
            }
            else if (CurrentTokenType == TokenType.NVSingleQuote)
            {
                _scanner.GetToken();

                if (CurrentTokenType == TokenType.NVStringLiteral)
                {
                    expr = new NVStringExpression(_scanner.CurrentToken.Image);
                    expr.Position = new Position(GetCurrentTokenPosition());
                    _scanner.GetToken();
                }

                if (CurrentTokenType == TokenType.NVSingleQuote)
                {
                    _scanner.GetToken();
                }
                else
                {
                    AddError("Expected single quote for closing string literal");
                }
            }
            else if (CurrentTokenType == TokenType.NVDoubleQuote)
            {
                _scanner.GetToken();

                expr = ParseNVStringLiteralOrDictionary();

                MatchToken(TokenType.NVDoubleQuote);
            }
            else if (CurrentTokenType == TokenType.NVLBrack)
            {
                _scanner.GetToken();

                if (CurrentTokenType != TokenType.NVRBrack)
                {
                    ParseNVExpression();
                    expr = ParseNVRangeOrArray();
                }
                else
                {
                    //TODO: replace with an empty NVArrayExpression
                    expr = new NVBoolExpression(false);
                    expr.Position = new Position(GetCurrentTokenPosition());
                }

                MatchToken(TokenType.NVRBrack);
            }
            else
            {
                AddError(string.Format("Expected expression, was '{0}'", CurrentTokenType));
            }

            return expr;
        }