Example #1
0
        // [DebuggerStepThrough]
        public void Parse(string s)
        {
            // replace disturbing chars
            string src = s.Replace("\n", "");

            src = src.Replace("\t", "");
            src = Regex.Replace(src, "~.+~", ""); // remove comments

            // transform source
            string[] cmdss = src.Split(Convert.ToChar("{"));
            src = src.Remove(0, cmdss[0].Length + 1);
            src = src.Remove(src.Length - 2, 2);
            src = src.Replace("}", "\n");

            UseStatementParser.Parse(cmdss[0], this);

            //parsing commands
            foreach (string cm in src.Split(Convert.ToChar("\n")))
            {
                var sh = BlockHeaderParser.Parse(cm.Split(Convert.ToChar("{"))[0]);

                var cmd = new Section {
                    Header = { Name = sh.Name }
                };

                VarDefParser.Parse(DataTypes, cm, cmd);
                FunctionCallParser.Parse(cm, cmd, this);
                VarSetParser.Parse(DataTypes, cm, cmd);
                ClassParser.Parse(cm, this);

                Sections.Add(cmd);
            }
        }
        public void FunctionCallWithOnlyOpeningParenthesis()
        {
            FunctionCallParser tokenizer = GetFunctionCallParser("func(");
            QueryToken         result;
            Action             parse = () => tokenizer.TryParseIdentifierAsFunction(null, out result);

            parse.ShouldThrow <ODataException>().WithMessage(ODataErrorStrings.UriQueryExpressionParser_ExpressionExpected(5, "func("));
        }
        public void ParseNonDottedIdentifier()
        {
            FunctionCallParser tokenizer = GetFunctionCallParser("func()");
            QueryToken         result;
            bool success = tokenizer.TryParseIdentifierAsFunction(null, out result);

            success.Should().BeTrue();
            result.ShouldBeFunctionCallToken("func").And.Arguments.Should().BeEmpty();
        }
        public void ParseManyDottedIdentifier()
        {
            FunctionCallParser tokenizer = GetFunctionCallParser("one.two.three.four.five.six()");
            QueryToken         result;
            bool success = tokenizer.TryParseIdentifierAsFunction(null, out result);

            success.Should().BeTrue();
            result.ShouldBeFunctionCallToken("one.two.three.four.five.six").And.Arguments.Should().BeEmpty();
        }
Example #5
0
        public void ParseDottedIdentifier()
        {
            FunctionCallParser tokenizer = GetFunctionCallParser("geo.distance()");
            QueryToken         result;
            bool success = tokenizer.TryParseIdentifierAsFunction(null, out result);

            Assert.True(success);
            Assert.Empty(result.ShouldBeFunctionCallToken("geo.distance").Arguments);
        }
Example #6
0
        public void FunctionCallWithNamedArguments()
        {
            FunctionCallParser tokenizer = GetFunctionCallParser("func(stuff=1, morestuff=2)");
            QueryToken         result;
            bool success = tokenizer.TryParseIdentifierAsFunction(null, out result);

            Assert.True(success);
            Assert.Equal(2, result.ShouldBeFunctionCallToken("func").Arguments.Count());
        }
Example #7
0
        public void FunctionWithOneArgument()
        {
            FunctionCallParser tokenizer = GetFunctionCallParser("func(1)");
            QueryToken         result;
            bool success = tokenizer.TryParseIdentifierAsFunction(null, out result);

            Assert.True(success);
            Assert.Single(result.ShouldBeFunctionCallToken("func").Arguments);
        }
        public void ArgsMustBeDelimitedByParens()
        {
            FunctionCallParser tokenizerWithoutClosingParen = GetFunctionCallParser("(stuff, stuff");
            FunctionCallParser tokenizerWithoutOpeningParen = GetFunctionCallParser("stuff, stuff)");
            Action             createWithoutClosingParen    = () => tokenizerWithoutClosingParen.ParseArgumentListOrEntityKeyList();
            Action             createWithoutOpeningParen    = () => tokenizerWithoutOpeningParen.ParseArgumentListOrEntityKeyList();

            createWithoutClosingParen.ShouldThrow <ODataException>().WithMessage(ODataErrorStrings.UriQueryExpressionParser_CloseParenOrCommaExpected(13, "(stuff, stuff"));
            createWithoutOpeningParen.ShouldThrow <ODataException>().WithMessage(ODataErrorStrings.UriQueryExpressionParser_OpenParenExpected(0, "stuff, stuff)"));
        }
        public void ParsedFunctionWithAParent()
        {
            FunctionCallParser tokenizer = GetFunctionCallParser("func()");
            InnerPathToken     parent    = new InnerPathToken("Customer", null, null);
            QueryToken         result;
            bool success = tokenizer.TryParseIdentifierAsFunction(parent, out result);

            success.Should().BeTrue();
            result.ShouldBeFunctionCallToken("func").And.Source.Should().BeSameAs(parent);
        }
        public void FunctionCallWithNamedArguments()
        {
            FunctionCallParser tokenizer = GetFunctionCallParser("func(stuff=1, morestuff=2)");
            QueryToken         result;
            bool success = tokenizer.TryParseIdentifierAsFunction(null, out result);

            success.Should().BeTrue();
            result.ShouldBeFunctionCallToken("func")
            .And.Arguments.Should().HaveCount(2);
        }
Example #11
0
        public void FunctionWithOneArgument()
        {
            FunctionCallParser tokenizer = GetFunctionCallParser("func(1)");
            QueryToken         result;
            bool success = tokenizer.TryParseIdentifierAsFunction(null, out result);

            success.Should().BeTrue();
            result.ShouldBeFunctionCallToken("func")
            .Arguments.Should().HaveCount(1);
        }
        public void ParsedFunctionWithAParentAndArgs()
        {
            FunctionCallParser tokenizer = GetFunctionCallParser("func(x='blah')");
            InnerPathToken     parent    = new InnerPathToken("Customer", null, null);
            QueryToken         result;
            bool success = tokenizer.TryParseIdentifierAsFunction(parent, out result);

            success.Should().BeTrue();
            FunctionCallToken functionCallToken = result.ShouldBeFunctionCallToken("func").And;

            functionCallToken.Source.Should().BeSameAs(parent);
            functionCallToken.Arguments.Should().HaveCount(1);
        }
Example #13
0
        public void ParsedFunctionWithAParentAndArgs()
        {
            FunctionCallParser tokenizer = GetFunctionCallParser("func(x='blah')");
            InnerPathToken     parent    = new InnerPathToken("Customer", null, null);
            QueryToken         result;
            bool success = tokenizer.TryParseIdentifierAsFunction(parent, out result);

            Assert.True(success);
            FunctionCallToken functionCallToken = result.ShouldBeFunctionCallToken("func");

            Assert.Same(parent, functionCallToken.Source);
            Assert.Single(functionCallToken.Arguments);
        }
        public void SetStartPoint(FunctionCallParser.Token token, bool includeToken)
        {
            System.Drawing.Point temporary = new System.Drawing.Point(token.col - 1, token.line - 1);

            if (false == includeToken)
            {
                temporary.X = token.col + token.val.Length - 1;
                temporary.Y = token.line - 1;
            }

            SetStartPoint(temporary);
        }
 public void AppendIdentifier(FunctionCallParser.Token token)
 {
     if (null != token && (!string.IsNullOrEmpty(token.val)))
         this.Identifier = this.Identifier + token.val;
 }