Exemplo n.º 1
0
        private void btnRetrieve_Click(object sender, EventArgs e)
        {
            this.lstFileList.Items.Clear();

            StandardParser parser = new StandardParser();

            parser.RuleList.AddRange(ChinaVoluntaryStandardRule.Rules);
            parser.RuleList.AddRange(ChinaCompulsoryStandardRule.Rules);
            parser.RuleList.AddRange(AmericanStandardRule.Rules);
            parser.RuleList.AddRange(JapanStandardRule.Rules);
            parser.RuleList.AddRange(GermanyStandardRule.Rules);
            parser.RuleList.AddRange(EuropeStandardRule.Rules);
            parser.RuleList.AddRange(IsoStandardRule.Rules);
            parser.RuleList.AddRange(UicStandardRule.Rules);
            parser.RuleList.AddRange(IecStandardRule.Rules);

            StandardFileEnumerator fileEnumerator = new StandardFileEnumerator(this.txtPath.Text);

            foreach (var file in fileEnumerator)
            {
                ListViewItem item = this.CreateItem(file);
                this.lstFileList.Items.Add(item);

                string         fileName = Path.GetFileNameWithoutExtension(file);
                StandardStruct standard = parser.Parse(fileName);
                if (standard != null)
                {
                    item.SubItems[1].Text = standard.StandardNumber;
                    item.SubItems[2].Text = standard.StandardName;
                }
            }
        }
Exemplo n.º 2
0
        public void IfTest()
        {
            StandardParser formula = new StandardParser("if(7==8,0,1)");
            decimal        result  = formula.Solve <decimal>(new StandardVariableCollection());

            Assert.AreEqual(result, Convert.ToDecimal(1));
        }
Exemplo n.º 3
0
 public Desk(string deskId, string groupName = "DefaultGroupName")
 {
     DeskId          = deskId;
     GroupName       = groupName;
     _currentParser  = new WaitingParser();
     _standardParser = new StandardParser();
 }
Exemplo n.º 4
0
        public void TestNestedTernaryExpression()
        {
            var template = "{2 > 1 ? (3 > 2 ? 'super true' : 'super false') : 'false'}";

            var parser = new StandardParser();

            var rootNode = parser.Parse(new StandardLexer(template));

            var branchNode = rootNode.Children.First() as BranchAstNode;

            Assert.True(branchNode != null);

            var firstConditionNode = (branchNode.Condition as BinaryOperationAstNode);

            Assert.True(firstConditionNode != null);
            Assert.True((firstConditionNode.Left as TerminalAstNode <int>).Value == 2);
            Assert.True(firstConditionNode.Operation.Type == TokenType.GT);
            Assert.True((firstConditionNode.Right as TerminalAstNode <int>).Value == 1);

            var secondBranchNode    = branchNode.IfBody as BranchAstNode;
            var secondConditionNode = secondBranchNode.Condition as BinaryOperationAstNode;

            Assert.True(secondConditionNode != null);
            Assert.True((secondConditionNode.Left as TerminalAstNode <int>).Value == 3);
            Assert.True(secondConditionNode.Operation.Type == TokenType.GT);
            Assert.True((secondConditionNode.Right as TerminalAstNode <int>).Value == 2);

            Assert.True((secondBranchNode.IfBody as TerminalAstNode <string>).Value == "super true");
            Assert.True((secondBranchNode.ElseBody as TerminalAstNode <string>).Value == "super false");

            Assert.True((branchNode.ElseBody as TerminalAstNode <string>).Value == "false");
        }
Exemplo n.º 5
0
        public void TestExpressionParameterList()
        {
            const string template = "{Method(3 + 4 * 5)}";

            var parser = new StandardParser();

            var rootNode = parser.Parse(new StandardLexer(template));

            var procNode = rootNode.Children.First() as IdentifierProcedureCallAstNode;

            Assert.True(procNode != null);
            Assert.Equal("Method", procNode.Name);
            Assert.Single(procNode.Params);

            var paramNode = procNode.Params.First() as BinaryOperationAstNode;

            Assert.True(paramNode != null);
            Assert.Equal(TokenType.PLUS, paramNode.Operation.Type);
            Assert.Equal(3, (paramNode.Left as TerminalAstNode <int>).Value);

            var secondOp = paramNode.Right as BinaryOperationAstNode;

            Assert.Equal(TokenType.MUL, secondOp.Operation.Type);
            Assert.Equal(4, (secondOp.Left as TerminalAstNode <int>).Value);
            Assert.Equal(5, (secondOp.Right as TerminalAstNode <int>).Value);
        }
Exemplo n.º 6
0
        private void btnOpenFile_Click(object sender, EventArgs e)
        {
            OpenFileDialog standardDialog = this.CreateOpenStandardFileDialog();

            if (standardDialog.ShowDialog() == DialogResult.OK)
            {
                string fullName = standardDialog.FileName;
                string fileName = Path.GetFileName(fullName);

                this.txtFilePath.Text = fullName;
                this.txtFileName.Text = fileName;

                StandardParser parser   = this.CreateStandardParserWithAllRules();
                StandardStruct standard = parser.Parse(Path.GetFileNameWithoutExtension(fileName));
                if (standard != null)
                {
                    this.txtExtractiveStandardNo.Text   = standard.StandardNumber;
                    this.txtExtractiveStandardName.Text = standard.StandardName;

                    if (this.database != null)
                    {
                        DataTable table = this.database.QueryStandardsInfo(standard.StandardNumber, string.Empty);
                        this.ShowTableRowsToListView(this.lvMatched, table, null);
                    }
                }
            }
        }
Exemplo n.º 7
0
        public void DoubleSubtractionTest()
        {
            StandardParser formula = new StandardParser("10-0-200");
            decimal        compare = Convert.ToDecimal(10) - Convert.ToDecimal(0) - Convert.ToDecimal(200);
            decimal        result  = formula.Solve <decimal>(new StandardVariableCollection());

            Assert.AreEqual(compare, result);
        }
Exemplo n.º 8
0
        public void BasicNegativeTest()
        {
            StandardParser formula = new StandardParser("(7+6)+-4");
            decimal        compare = (Convert.ToDecimal(7) + Convert.ToDecimal(6)) + Convert.ToDecimal(-4);
            decimal        result  = formula.Solve <decimal>(new StandardVariableCollection());

            Assert.AreEqual(compare, result);
        }
Exemplo n.º 9
0
        public void TestVariable()
        {
            StandardParser             parser = new StandardParser("so91");
            decimal                    val    = 453.444m;
            StandardVariableCollection vars   = new StandardVariableCollection();

            vars.Add("so91", val);

            Assert.AreEqual(val, parser.Solve <decimal>(vars));
        }
Exemplo n.º 10
0
        public void ConditionNegativeTest()
        {
            StandardParser formula = new StandardParser("a<=-0.12");
            decimal        compare = Convert.ToDecimal(10) - Convert.ToDecimal(0) - Convert.ToDecimal(200);

            StandardVariableCollection vars = new StandardVariableCollection();

            vars.Add("a", -111m);

            Assert.IsTrue(formula.Solve <bool>(vars));
        }
Exemplo n.º 11
0
        public void EqualsNullTest()
        {
            StandardParser formula = new StandardParser("a==null");
            decimal        compare = Convert.ToDecimal(10) - Convert.ToDecimal(0) - Convert.ToDecimal(200);

            StandardVariableCollection vars = new StandardVariableCollection();

            vars.Add("a", null);

            Assert.IsTrue(formula.Solve <bool>(vars));
        }
Exemplo n.º 12
0
        public void TestLiteralsWithoutProgram()
        {
            var template = "this is a test template!";

            var parser = new StandardParser();

            var rootNode = parser.Parse(new StandardLexer(template));

            Assert.Single(rootNode.Children);
            Assert.True(rootNode.Children.All(c => c is TerminalAstNode <string>));
            Assert.True(((TerminalAstNode <string>)rootNode.Children.Single()).Value == "this is a test template!");
        }
Exemplo n.º 13
0
        public void TestLiteralsWithSingleProgram()
        {
            var template = "left{program}right";

            var parser = new StandardParser();

            var rootNode = parser.Parse(new StandardLexer(template));

            Assert.Equal(3, rootNode.Children.Count());
            Assert.True(rootNode.Children.First() is TerminalAstNode <string>);
            Assert.True(rootNode.Children.Last() is TerminalAstNode <string>);
        }
Exemplo n.º 14
0
        public void TestMissingVariable()
        {
            StandardParser parser = new StandardParser("so91>so92");

            parser.OnSolveError += parser_OnSolveError;
            decimal val = 453.444m;
            StandardVariableCollection vars = new StandardVariableCollection();

            vars.Add("so91", val);
            vars.Add("so92", "'a'");

            Assert.AreEqual(val, parser.Solve <decimal>(vars));
        }
Exemplo n.º 15
0
        public void TestNullIdentifier()
        {
            const string template = "{null = null}";

            var parser   = new StandardParser();
            var rootNode = parser.Parse(new StandardLexer(template));

            var binOpNode = rootNode.Children.First() as BinaryOperationAstNode;

            Assert.NotNull(binOpNode);
            Assert.True(binOpNode.Operation.Type == TokenType.EQ);
            Assert.NotNull(binOpNode.Left as NullAstNode);
            Assert.NotNull(binOpNode.Right as NullAstNode);
        }
Exemplo n.º 16
0
        public void TestEachLoop()
        {
            const string template = "{each number in numbers ? number + ', '}";

            var parser = new StandardParser();

            var rootNode = parser.Parse(new StandardLexer(template));

            var eachNode = rootNode.Children.First() as EachLoopAstNode;

            Assert.True(eachNode != null);
            Assert.True(eachNode.LoopVariableNode.Name == "number");
            Assert.True(eachNode.EnumerableVariableNode.Name == "numbers");
        }
Exemplo n.º 17
0
        public void TestProcedureCall()
        {
            const string template = "{variable.Method()}";

            var parser = new StandardParser();

            var rootNode = parser.Parse(new StandardLexer(template));

            var node = rootNode.Children.First() as IdentifierVariableAccessAstNode;

            Assert.True(node != null);
            Assert.Equal("variable", node.Name);
            Assert.Equal("Method", node.MemberIdentifier.Name);
            Assert.Empty((node.MemberIdentifier as IdentifierProcedureCallAstNode).Params);
        }
Exemplo n.º 18
0
        public void TestTernaryOperator()
        {
            var template = "{expression ? 'expression-if' : 'expression-else'}";

            var parser = new StandardParser();

            var rootNode = parser.Parse(new StandardLexer(template));

            var branchNode = rootNode.Children.First() as BranchAstNode;

            Assert.True(branchNode != null);
            Assert.True((branchNode.Condition as IdentifierVariableAccessAstNode).Name == "expression");
            Assert.True((branchNode.IfBody as TerminalAstNode <string>).Value == "expression-if");
            Assert.True((branchNode.ElseBody as TerminalAstNode <string>).Value == "expression-else");
        }
Exemplo n.º 19
0
        private StandardParser CreateStandardParserWithAllRules()
        {
            StandardParser parser = new StandardParser();

            parser.RuleList.AddRange(ChinaVoluntaryStandardRule.Rules);
            parser.RuleList.AddRange(ChinaCompulsoryStandardRule.Rules);
            parser.RuleList.AddRange(AmericanStandardRule.Rules);
            parser.RuleList.AddRange(JapanStandardRule.Rules);
            parser.RuleList.AddRange(GermanyStandardRule.Rules);
            parser.RuleList.AddRange(EuropeStandardRule.Rules);
            parser.RuleList.AddRange(IsoStandardRule.Rules);
            parser.RuleList.AddRange(UicStandardRule.Rules);
            parser.RuleList.AddRange(IecStandardRule.Rules);

            return(parser);
        }
Exemplo n.º 20
0
        public void TestOperatorPrecedence()
        {
            var template = "{8 * 4 + 3.1415}";

            var parser = new StandardParser();

            var rootNode = parser.Parse(new StandardLexer(template));

            var firstBinaryOp = rootNode.Children.First() as BinaryOperationAstNode;

            Assert.True(firstBinaryOp != null);
            Assert.True(firstBinaryOp.Operation.Type == TokenType.PLUS);
            Assert.True((firstBinaryOp.Right as TerminalAstNode <double>).Value == 3.1415);

            var secondBinaryOp = firstBinaryOp.Left as BinaryOperationAstNode;

            Assert.True((secondBinaryOp.Left as TerminalAstNode <int>).Value == 8);
            Assert.True((secondBinaryOp.Right as TerminalAstNode <int>).Value == 4);
        }
Exemplo n.º 21
0
        public void TestSimpleParamsList()
        {
            const string template = "{Method(variable)}";

            var parser = new StandardParser();

            var rootNode = parser.Parse(new StandardLexer(template));

            var procNode = rootNode.Children.First() as IdentifierProcedureCallAstNode;

            Assert.True(procNode != null);
            Assert.Equal("Method", procNode.Name);
            Assert.Single(procNode.Params);

            var paramNode = procNode.Params.First() as IdentifierVariableAccessAstNode;

            Assert.True(paramNode != null);
            Assert.Equal("variable", paramNode.Name);
        }
Exemplo n.º 22
0
        public void OneArgument_Verbose()
        {
            var input = "get-history --username \"datum earth\"";

            var expected = new ParseResult <CommandSkeleton>()
            {
                Value = new CommandSkeleton("get-history", new List <KeyValuePair <string, string> >()
                {
                    new KeyValuePair <string, string>("--username", "\"datum earth\"")
                }),
                Successful = true,
                Error      = null
            };

            var parser = new StandardParser();

            var actual = parser.GetCommand(input);

            Assert.IsTrue(ResultsAreEqual(expected, actual));
        }
Exemplo n.º 23
0
        public void SingleArgumentShortForm()
        {
            var input = "get-history -u @datum-earth";

            var expected = new ParseResult <CommandSkeleton>()
            {
                Value = new CommandSkeleton("get-history", new List <KeyValuePair <string, string> >()
                {
                    new KeyValuePair <string, string>("-u", "@datum-earth")
                }),
                Successful = true,
                Error      = null
            };

            var parser = new StandardParser();

            var actual = parser.GetCommand(input);

            Assert.IsTrue(ResultsAreEqual(expected, actual));
        }
Exemplo n.º 24
0
        public void TestProcedureCallInParameterList()
        {
            const string template = "{Method(SecondMethod())}";

            var parser = new StandardParser();

            var rootNode = parser.Parse(new StandardLexer(template));

            var procNode = rootNode.Children.First() as IdentifierProcedureCallAstNode;

            Assert.True(procNode != null);
            Assert.Equal("Method", procNode.Name);
            Assert.Single(procNode.Params);

            var paramNode = procNode.Params.First() as IdentifierProcedureCallAstNode;

            Assert.True(paramNode != null);
            Assert.Equal("SecondMethod", paramNode.Name);
            Assert.Empty(paramNode.Params);
        }
Exemplo n.º 25
0
        public void TestTernaryWithoutElseBody()
        {
            const string template = "{blah > 3 ? 'some text'}";

            var parser = new StandardParser();

            var rootNode = parser.Parse(new StandardLexer(template));

            var branchNode = rootNode.Children.First() as BranchAstNode;

            Assert.True(branchNode != null);
            Assert.True((branchNode.IfBody as TerminalAstNode <string>).Value == "some text");
            Assert.True((branchNode.ElseBody as NoOpAstNode) != null);

            var conditionNode = (branchNode.Condition as BinaryOperationAstNode);

            Assert.True(conditionNode != null);
            Assert.True(conditionNode.Operation.Type == TokenType.GT);
            Assert.True((conditionNode.Left as IdentifierVariableAccessAstNode).Name == "blah");
            Assert.True((conditionNode.Right as TerminalAstNode <int>).Value == 3);
        }
Exemplo n.º 26
0
        private static unsafe void Main(string[] args)
        {
            var parser = new StandardParser();

            parser.LoadScript(XDocument.Load(".\\vramscript.xml").ToString());

            foreach (var token in parser.Initialize().GetTokens("( ( 11.1+ 17.5++) * 23) / --4"))
            {
                Console.WriteLine("{0}[{1}]={2}", token.Name, token.Match?.Index, token.Text);
            }



            var tmp = NativeUnicodeString.FromManaged("hello");

            Console.WriteLine(tmp.Length);
            Console.WriteLine(tmp.MaximumLength);
            for (short i = 0; i < tmp.Length; i++)
            {
                Console.WriteLine(tmp[i]);
            }
        }
Exemplo n.º 27
0
        public void TestMultiSimpleParamsList()
        {
            const string template = "{Method(variable, 'text')}";

            var parser = new StandardParser();

            var rootNode = parser.Parse(new StandardLexer(template));

            var procNode = rootNode.Children.First() as IdentifierProcedureCallAstNode;

            Assert.True(procNode != null);
            Assert.Equal("Method", procNode.Name);
            Assert.Equal(2, procNode.Params.Count());

            var paramNode = procNode.Params.First() as IdentifierVariableAccessAstNode;

            Assert.True(paramNode != null);
            Assert.Equal("variable", paramNode.Name);

            var paramNode2 = procNode.Params.Last() as TerminalAstNode <string>;

            Assert.True(paramNode2 != null);
            Assert.Equal("text", paramNode2.Value);
        }
Exemplo n.º 28
0
        public string Run()
        {
            var cardParser   = new StandardParser();
            var handComparer = new PokerHandComparer();

            int winningHands = 0;

            var reader = FileHelper.ForProblem(54).OpenFile("poker.txt");

            while (!reader.EndOfStream)
            {
                var line  = reader.ReadLine();
                var cards = line.Split(' ');
                var hand1 = new PokerHand(cards.Take(5).Select(str => new PokerCard(cardParser.Parse(str))));
                var hand2 = new PokerHand(cards.Skip(5).Select(str => new PokerCard(cardParser.Parse(str))));
                if (handComparer.Compare(hand1, hand2) > 0)
                {
                    winningHands++;
                }
            }
            reader.Close();

            return(winningHands.ToString());
        }
        public JsonNetResult ValidateCustomRuleSyntax(int modelID, string customRule)
        {
            var sp = new StandardParser();
            var cs = new ConfiguratorSession(null, null, null);

            try
            {
                sp.ParseString(ref cs, customRule);
            }
            catch
            {
                return new JsonNetResult { Data = false };
            }

            return new JsonNetResult { Data = true };
        }
Exemplo n.º 30
0
        //
        #endregion

        #region Ctor
        public LoopCommand()
        {
            Parser = new StandardParser(PARSE_PARAMETERS_PATTERN);
        }
Exemplo n.º 31
0
 /// <summary>
 /// Set offset error offset.
 /// </summary>
 /// <param name="LengthToSum">Count of removed chars from the <paramref name="commandLineText"/>.</param>
 /// <param name="i">Iteration index.</param>
 /// <param name="commandLineText">Line to parse.</param>
 /// <returns>Error offset.</returns>
 private void SetErrorOffset(ref int LengthToSum, int i, ref string commandLineText)
 {
     StandardParser.SetOffset(Parameters[i].Error, Parameters[i].Value, ref commandLineText, ref LengthToSum);
 }