示例#1
0
文件: Parser.cs 项目: erikma/msbuild
        private GenericExpressionNode BooleanTerm(string expression)
        {
            GenericExpressionNode node = RelationalExpr(expression);

            if (node == null)
            {
                errorPosition = _lexer.GetErrorPosition();
                ProjectErrorUtilities.ThrowInvalidProject(_elementLocation, "UnexpectedTokenInCondition", expression, _lexer.IsNextString(), errorPosition);
            }

            if (!_lexer.IsNext(Token.TokenType.EndOfInput))
            {
                node = BooleanTermPrime(expression, node);
            }
            return(node);
        }
示例#2
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);
        }
示例#3
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;
        }
示例#4
0
        public void ComplexTests1()
        {
            Scanner lexer;

            lexer = new Scanner("'String with a $(Property) inside'", ParserOptions.AllowAll);
            Assert.IsTrue(lexer.Advance() && lexer.IsNext(Token.TokenType.String));
            Assert.AreEqual(String.Compare("String with a $(Property) inside", lexer.IsNextString()), 0);

            lexer = new Scanner("'String with an embedded \\' in it'", ParserOptions.AllowAll);
            Assert.IsTrue(lexer.Advance() && lexer.IsNext(Token.TokenType.String));
            //          Assert.AreEqual(String.Compare("String with an embedded ' in it", lexer.IsNextString()), 0);

            lexer = new Scanner("'String with a $(Property) inside'", ParserOptions.AllowAll);
            Assert.IsTrue(lexer.Advance() && lexer.IsNext(Token.TokenType.String));
            Assert.AreEqual(String.Compare("String with a $(Property) inside", lexer.IsNextString()), 0);

            lexer = new Scanner("@(list, ' ')", ParserOptions.AllowAll);
            Assert.IsTrue(lexer.Advance() && lexer.IsNext(Token.TokenType.ItemList));
            Assert.AreEqual(String.Compare("@(list, ' ')", lexer.IsNextString()), 0);

            lexer = new Scanner("@(files->'%(Filename)')", ParserOptions.AllowAll);
            Assert.IsTrue(lexer.Advance() && lexer.IsNext(Token.TokenType.ItemList));
            Assert.AreEqual(String.Compare("@(files->'%(Filename)')", lexer.IsNextString()), 0);
        }
示例#5
0
        public void FunctionTests()
        {
            Scanner lexer;

            lexer = new Scanner("Foo()", ParserOptions.AllowAll);
            Assert.IsTrue(lexer.Advance() && lexer.IsNext(Token.TokenType.Function));
            Assert.AreEqual(String.Compare("Foo", lexer.IsNextString()), 0);
            Assert.IsTrue(lexer.Advance() && lexer.IsNext(Token.TokenType.LeftParenthesis));
            Assert.IsTrue(lexer.Advance() && lexer.IsNext(Token.TokenType.RightParenthesis));

            lexer = new Scanner("Foo( 1 )", ParserOptions.AllowAll);
            Assert.IsTrue(lexer.Advance() && lexer.IsNext(Token.TokenType.Function));
            Assert.AreEqual(String.Compare("Foo", lexer.IsNextString()), 0);
            Assert.IsTrue(lexer.Advance() && lexer.IsNext(Token.TokenType.LeftParenthesis));
            Assert.IsTrue(lexer.Advance() && lexer.IsNext(Token.TokenType.Numeric));
            Assert.IsTrue(lexer.Advance() && lexer.IsNext(Token.TokenType.RightParenthesis));

            lexer = new Scanner("Foo( $(Property) )", ParserOptions.AllowAll);
            Assert.IsTrue(lexer.Advance() && lexer.IsNext(Token.TokenType.Function));
            Assert.AreEqual(String.Compare("Foo", lexer.IsNextString()), 0);
            Assert.IsTrue(lexer.Advance() && lexer.IsNext(Token.TokenType.LeftParenthesis));
            Assert.IsTrue(lexer.Advance() && lexer.IsNext(Token.TokenType.Property));
            Assert.IsTrue(lexer.Advance() && lexer.IsNext(Token.TokenType.RightParenthesis));

            lexer = new Scanner("Foo( @(ItemList) )", ParserOptions.AllowAll);
            Assert.IsTrue(lexer.Advance() && lexer.IsNext(Token.TokenType.Function));
            Assert.AreEqual(String.Compare("Foo", lexer.IsNextString()), 0);
            Assert.IsTrue(lexer.Advance() && lexer.IsNext(Token.TokenType.LeftParenthesis));
            Assert.IsTrue(lexer.Advance() && lexer.IsNext(Token.TokenType.ItemList));
            Assert.IsTrue(lexer.Advance() && lexer.IsNext(Token.TokenType.RightParenthesis));

            lexer = new Scanner("Foo( simplestring )", ParserOptions.AllowAll);
            Assert.IsTrue(lexer.Advance() && lexer.IsNext(Token.TokenType.Function));
            Assert.AreEqual(String.Compare("Foo", lexer.IsNextString()), 0);
            Assert.IsTrue(lexer.Advance() && lexer.IsNext(Token.TokenType.LeftParenthesis));
            Assert.IsTrue(lexer.Advance() && lexer.IsNext(Token.TokenType.String));
            Assert.IsTrue(lexer.Advance() && lexer.IsNext(Token.TokenType.RightParenthesis));

            lexer = new Scanner("Foo( 'Not a Simple String' )", ParserOptions.AllowAll);
            Assert.IsTrue(lexer.Advance() && lexer.IsNext(Token.TokenType.Function));
            Assert.AreEqual(String.Compare("Foo", lexer.IsNextString()), 0);
            Assert.IsTrue(lexer.Advance() && lexer.IsNext(Token.TokenType.LeftParenthesis));
            Assert.IsTrue(lexer.Advance() && lexer.IsNext(Token.TokenType.String));
            Assert.IsTrue(lexer.Advance() && lexer.IsNext(Token.TokenType.RightParenthesis));

            lexer = new Scanner("Foo( 'Not a Simple String', 1234 )", ParserOptions.AllowAll);
            Assert.IsTrue(lexer.Advance() && lexer.IsNext(Token.TokenType.Function));
            Assert.AreEqual(String.Compare("Foo", lexer.IsNextString()), 0);
            Assert.IsTrue(lexer.Advance() && lexer.IsNext(Token.TokenType.LeftParenthesis));
            Assert.IsTrue(lexer.Advance() && lexer.IsNext(Token.TokenType.String));
            Assert.IsTrue(lexer.Advance() && lexer.IsNext(Token.TokenType.Comma));
            Assert.IsTrue(lexer.Advance() && lexer.IsNext(Token.TokenType.Numeric));
            Assert.IsTrue(lexer.Advance() && lexer.IsNext(Token.TokenType.RightParenthesis));

            lexer = new Scanner("Foo( $(Property), 'Not a Simple String', 1234 )", ParserOptions.AllowAll);
            Assert.IsTrue(lexer.Advance() && lexer.IsNext(Token.TokenType.Function));
            Assert.AreEqual(String.Compare("Foo", lexer.IsNextString()), 0);
            Assert.IsTrue(lexer.Advance() && lexer.IsNext(Token.TokenType.LeftParenthesis));
            Assert.IsTrue(lexer.Advance() && lexer.IsNext(Token.TokenType.Property));
            Assert.IsTrue(lexer.Advance() && lexer.IsNext(Token.TokenType.Comma));
            Assert.IsTrue(lexer.Advance() && lexer.IsNext(Token.TokenType.String));
            Assert.IsTrue(lexer.Advance() && lexer.IsNext(Token.TokenType.Comma));
            Assert.IsTrue(lexer.Advance() && lexer.IsNext(Token.TokenType.Numeric));
            Assert.IsTrue(lexer.Advance() && lexer.IsNext(Token.TokenType.RightParenthesis));

            lexer = new Scanner("Foo( @(ItemList), $(Property), simplestring, 'Not a Simple String', 1234 )", ParserOptions.AllowAll);
            Assert.IsTrue(lexer.Advance() && lexer.IsNext(Token.TokenType.Function));
            Assert.AreEqual(String.Compare("Foo", lexer.IsNextString()), 0);
            Assert.IsTrue(lexer.Advance() && lexer.IsNext(Token.TokenType.LeftParenthesis));
            Assert.IsTrue(lexer.Advance() && lexer.IsNext(Token.TokenType.ItemList));
            Assert.IsTrue(lexer.Advance() && lexer.IsNext(Token.TokenType.Comma));
            Assert.IsTrue(lexer.Advance() && lexer.IsNext(Token.TokenType.Property));
            Assert.IsTrue(lexer.Advance() && lexer.IsNext(Token.TokenType.Comma));
            Assert.IsTrue(lexer.Advance() && lexer.IsNext(Token.TokenType.String));
            Assert.IsTrue(lexer.Advance() && lexer.IsNext(Token.TokenType.Comma));
            Assert.IsTrue(lexer.Advance() && lexer.IsNext(Token.TokenType.String));
            Assert.IsTrue(lexer.Advance() && lexer.IsNext(Token.TokenType.Comma));
            Assert.IsTrue(lexer.Advance() && lexer.IsNext(Token.TokenType.Numeric));
            Assert.IsTrue(lexer.Advance() && lexer.IsNext(Token.TokenType.RightParenthesis));
        }
示例#6
0
        public void PropsStringsAndBooleanSingleTokenTests()
        {
            Scanner lexer = new Scanner("$(foo)", ParserOptions.AllowAll);
            Assert.IsTrue(lexer.Advance());
            Assert.AreEqual(lexer.IsNext(Token.TokenType.Property), true);
            lexer = new Scanner("@(foo)", ParserOptions.AllowAll);
            Assert.IsTrue(lexer.Advance());
            Assert.AreEqual(lexer.IsNext(Token.TokenType.ItemList), true);
            lexer = new Scanner("abcde", ParserOptions.AllowAll);
            Assert.IsTrue(lexer.Advance());
            Assert.AreEqual(lexer.IsNext(Token.TokenType.String), true);
            Assert.AreEqual(String.Compare("abcde", lexer.IsNextString()), 0);

            lexer = new Scanner("'abc-efg'", ParserOptions.AllowAll);
            Assert.IsTrue(lexer.Advance());
            Assert.AreEqual(lexer.IsNext(Token.TokenType.String), true);
            Assert.AreEqual(String.Compare("abc-efg", lexer.IsNextString()), 0);

            lexer = new Scanner("and", ParserOptions.AllowAll);
            Assert.IsTrue(lexer.Advance());
            Assert.AreEqual(lexer.IsNext(Token.TokenType.And), true);
            Assert.AreEqual(String.Compare("and", lexer.IsNextString()), 0);
            lexer = new Scanner("or", ParserOptions.AllowAll);
            Assert.IsTrue(lexer.Advance());
            Assert.AreEqual(lexer.IsNext(Token.TokenType.Or), true);
            Assert.AreEqual(String.Compare("or", lexer.IsNextString()), 0);
            lexer = new Scanner("AnD", ParserOptions.AllowAll);
            Assert.IsTrue(lexer.Advance());
            Assert.AreEqual(lexer.IsNext(Token.TokenType.And), true);
            Assert.AreEqual(String.Compare(Token.And.String, lexer.IsNextString()), 0);
            lexer = new Scanner("Or", ParserOptions.AllowAll);
            Assert.IsTrue(lexer.Advance());
            Assert.AreEqual(lexer.IsNext(Token.TokenType.Or), true);
            Assert.AreEqual(String.Compare(Token.Or.String, lexer.IsNextString()), 0);
        }
示例#7
0
        public void NumericSingleTokenTests()
        {
            Scanner lexer;

            lexer = new Scanner("1234", ParserOptions.AllowAll);
            Assert.IsTrue(lexer.Advance());
            Assert.AreEqual(lexer.IsNext(Token.TokenType.Numeric), true);
            Assert.AreEqual(String.Compare("1234", lexer.IsNextString()), 0);

            lexer = new Scanner("-1234", ParserOptions.AllowAll);
            Assert.IsTrue(lexer.Advance());
            Assert.AreEqual(lexer.IsNext(Token.TokenType.Numeric), true);
            Assert.AreEqual(String.Compare("-1234", lexer.IsNextString()), 0);

            lexer = new Scanner("+1234", ParserOptions.AllowAll);
            Assert.IsTrue(lexer.Advance());
            Assert.AreEqual(lexer.IsNext(Token.TokenType.Numeric), true);
            Assert.AreEqual(String.Compare("+1234", lexer.IsNextString()), 0);

            lexer = new Scanner("1234.1234", ParserOptions.AllowAll);
            Assert.IsTrue(lexer.Advance());
            Assert.AreEqual(lexer.IsNext(Token.TokenType.Numeric), true);
            Assert.AreEqual(String.Compare("1234.1234", lexer.IsNextString()), 0);

            lexer = new Scanner(".1234", ParserOptions.AllowAll);
            Assert.IsTrue(lexer.Advance());
            Assert.AreEqual(lexer.IsNext(Token.TokenType.Numeric), true);
            Assert.AreEqual(String.Compare(".1234", lexer.IsNextString()), 0);

            lexer = new Scanner("1234.", ParserOptions.AllowAll);
            Assert.IsTrue(lexer.Advance());
            Assert.AreEqual(lexer.IsNext(Token.TokenType.Numeric), true);
            Assert.AreEqual(String.Compare("1234.", lexer.IsNextString()), 0);
            lexer = new Scanner("0x1234", ParserOptions.AllowAll);
            Assert.IsTrue(lexer.Advance());
            Assert.AreEqual(lexer.IsNext(Token.TokenType.Numeric), true);
            Assert.AreEqual(String.Compare("0x1234", lexer.IsNextString()), 0);
            lexer = new Scanner("0X1234abcd", ParserOptions.AllowAll);
            Assert.IsTrue(lexer.Advance());
            Assert.AreEqual(lexer.IsNext(Token.TokenType.Numeric), true);
            Assert.AreEqual(String.Compare("0X1234abcd", lexer.IsNextString()), 0);
            lexer = new Scanner("0x1234ABCD", ParserOptions.AllowAll);
            Assert.IsTrue(lexer.Advance());
            Assert.AreEqual(lexer.IsNext(Token.TokenType.Numeric), true);
            Assert.AreEqual(String.Compare("0x1234ABCD", lexer.IsNextString()), 0);
        }