예제 #1
0
파일: Parser.cs 프로젝트: erikma/msbuild
        //
        // Main entry point for parser.
        // You pass in the expression you want to parse, and you get an
        // ExpressionTree out the back end.
        //
        internal GenericExpressionNode Parse(string expression, ParserOptions optionSettings, ElementLocation elementLocation)
        {
            // We currently have no support (and no scenarios) for disallowing property references
            // in Conditions.
            ErrorUtilities.VerifyThrow(0 != (optionSettings & ParserOptions.AllowProperties),
                                       "Properties should always be allowed.");

            _options         = optionSettings;
            _elementLocation = elementLocation;

            _lexer = new Scanner(expression, _options);
            if (!_lexer.Advance())
            {
                errorPosition = _lexer.GetErrorPosition();
                ProjectErrorUtilities.ThrowInvalidProject(elementLocation, _lexer.GetErrorResource(), expression, errorPosition, _lexer.UnexpectedlyFound);
            }
            GenericExpressionNode node = Expr(expression);

            if (!_lexer.IsNext(Token.TokenType.EndOfInput))
            {
                errorPosition = _lexer.GetErrorPosition();
                ProjectErrorUtilities.ThrowInvalidProject(elementLocation, "UnexpectedTokenInCondition", expression, _lexer.IsNextString(), errorPosition);
            }
            return(node);
        }
예제 #2
0
        public void SingleEquals()
        {
            Scanner lexer;

            lexer = new Scanner("a=b", ParserOptions.AllowProperties);
            AdvanceToScannerError(lexer);
            Assert.Equal(lexer.GetErrorResource(), "IllFormedEqualsInCondition");
            Assert.Equal(lexer.UnexpectedlyFound, "b");
        }
예제 #3
0
파일: Parser.cs 프로젝트: erikma/msbuild
 private bool Same(string expression, Token.TokenType token)
 {
     if (_lexer.IsNext(token))
     {
         if (!_lexer.Advance())
         {
             errorPosition = _lexer.GetErrorPosition();
             if (_lexer.UnexpectedlyFound != null)
             {
                 ProjectErrorUtilities.ThrowInvalidProject(_elementLocation, _lexer.GetErrorResource(), expression, errorPosition, _lexer.UnexpectedlyFound);
             }
             else
             {
                 ProjectErrorUtilities.ThrowInvalidProject(_elementLocation, _lexer.GetErrorResource(), expression, errorPosition);
             }
         }
         return(true);
     }
     else
     {
         return(false);
     }
 }
예제 #4
0
        //
        // Main entry point for parser.
        // You pass in the expression you want to parse, and you get an
        // ExpressionTree out the back end.
        //
        internal GenericExpressionNode Parse(string expression, ParserOptions optionSettings, ElementLocation elementLocation)
        {
            // We currently have no support (and no scenarios) for disallowing property references
            // in Conditions.
            ErrorUtilities.VerifyThrow(0 != (optionSettings & ParserOptions.AllowProperties),
                "Properties should always be allowed.");

            _options = optionSettings;
            _elementLocation = elementLocation;

            _lexer = new Scanner(expression, _options);
            if (!_lexer.Advance())
            {
                errorPosition = _lexer.GetErrorPosition();
                ProjectErrorUtilities.VerifyThrowInvalidProject(false, elementLocation, _lexer.GetErrorResource(), expression, errorPosition, _lexer.UnexpectedlyFound);
            }
            GenericExpressionNode node = Expr(expression);
            if (!_lexer.IsNext(Token.TokenType.EndOfInput))
            {
                errorPosition = _lexer.GetErrorPosition();
                ProjectErrorUtilities.VerifyThrowInvalidProject(false, elementLocation, "UnexpectedTokenInCondition", expression, _lexer.IsNextString(), errorPosition);
            }
            return node;
        }
예제 #5
0
        public void IllFormedProperty()
        {
            Scanner lexer;

            lexer = new Scanner("$(", ParserOptions.AllowProperties);
            AdvanceToScannerError(lexer);
            Assert.IsTrue(lexer.GetErrorResource() == "IllFormedPropertyCloseParenthesisInCondition");

            lexer = new Scanner("$x", ParserOptions.AllowProperties);
            AdvanceToScannerError(lexer);
            Assert.IsTrue(lexer.GetErrorResource() == "IllFormedPropertyOpenParenthesisInCondition");
        }
예제 #6
0
        public void ItemListTests()
        {
            Scanner lexer;

            lexer = new Scanner("@(foo)", ParserOptions.AllowProperties);
            Assert.IsFalse(lexer.Advance());
            Assert.IsTrue(String.Compare(lexer.GetErrorResource(), "ItemListNotAllowedInThisConditional") == 0);

            lexer = new Scanner("1234 '@(foo)'", ParserOptions.AllowProperties);
            Assert.IsTrue(lexer.Advance());
            Assert.IsFalse(lexer.Advance());
            Assert.IsTrue(String.Compare(lexer.GetErrorResource(), "ItemListNotAllowedInThisConditional") == 0);

            lexer = new Scanner("'1234 @(foo)'", ParserOptions.AllowProperties);
            Assert.IsFalse(lexer.Advance());
            Assert.IsTrue(String.Compare(lexer.GetErrorResource(), "ItemListNotAllowedInThisConditional") == 0);
        }
예제 #7
0
        public void IllFormedQuotedString()
        {
            Scanner lexer;

            lexer = new Scanner("false or 'abc", ParserOptions.AllowAll);
            AdvanceToScannerError(lexer);
            Assert.IsTrue(lexer.GetErrorResource() == "IllFormedQuotedStringInCondition");
            Assert.IsTrue(lexer.UnexpectedlyFound == null);

            lexer = new Scanner("\'", ParserOptions.AllowAll);
            AdvanceToScannerError(lexer);
            Assert.IsTrue(lexer.GetErrorResource() == "IllFormedQuotedStringInCondition");
            Assert.IsTrue(lexer.UnexpectedlyFound == null);
        }
예제 #8
0
        public void IllFormedItemList()
        {
            Scanner lexer;

            lexer = new Scanner("@(", ParserOptions.AllowAll);
            AdvanceToScannerError(lexer);
            Assert.IsTrue(lexer.GetErrorResource() == "IllFormedItemListCloseParenthesisInCondition");
            Assert.IsTrue(lexer.UnexpectedlyFound == null);

            lexer = new Scanner("@x", ParserOptions.AllowAll);
            AdvanceToScannerError(lexer);
            Assert.IsTrue(lexer.GetErrorResource() == "IllFormedItemListOpenParenthesisInCondition");
            Assert.IsTrue(lexer.UnexpectedlyFound == null);

            lexer = new Scanner("@(x", ParserOptions.AllowAll);
            AdvanceToScannerError(lexer);
            Assert.IsTrue(lexer.GetErrorResource() == "IllFormedItemListCloseParenthesisInCondition");
            Assert.IsTrue(lexer.UnexpectedlyFound == null);

            lexer = new Scanner("@(x->'%(y)", ParserOptions.AllowAll);
            AdvanceToScannerError(lexer);
            Assert.IsTrue(lexer.GetErrorResource() == "IllFormedItemListQuoteInCondition");
            Assert.IsTrue(lexer.UnexpectedlyFound == null);

            lexer = new Scanner("@(x->'%(y)', 'x", ParserOptions.AllowAll);
            AdvanceToScannerError(lexer);
            Assert.IsTrue(lexer.GetErrorResource() == "IllFormedItemListQuoteInCondition");
            Assert.IsTrue(lexer.UnexpectedlyFound == null);

            lexer = new Scanner("@(x->'%(y)', 'x'", ParserOptions.AllowAll);
            AdvanceToScannerError(lexer);
            Assert.IsTrue(lexer.GetErrorResource() == "IllFormedItemListCloseParenthesisInCondition");
            Assert.IsTrue(lexer.UnexpectedlyFound == null);
        }