Ejemplo n.º 1
0
        // This one will need some more looking at since we gotta parse the expression
        public AttributeManager DeserializeAttributes(YamlMappingNode yamlNode)
        {
            var am = new AttributeManager();

            foreach (KeyValuePair <YamlNode, YamlNode> kvp in yamlNode.Children)
            {
                if (kvp.Key.Equals(new YamlScalarNode("onlyIf")))
                {
                    // TODO add expression parsing here
                    string expression = kvp.Value.ToString();
                    am.Expression = BrigitExpressionParser.Parse(expression);
                }
                else if (kvp.Key.Equals(new YamlScalarNode("setTrue")))
                {
                    SetFlagMapping((YamlSequenceNode)kvp.Value, Flag.True, am.SetFlags);
                }
                else if (kvp.Key.Equals(new YamlScalarNode("setFalse")))
                {
                    SetFlagMapping((YamlSequenceNode)kvp.Value, Flag.False, am.SetFlags);
                }
                else if (kvp.Key.Equals(new YamlScalarNode("setDontCare")))
                {
                    SetFlagMapping((YamlSequenceNode)kvp.Value, Flag.DontCare, am.SetFlags);
                }
                else
                {
                    // I should probably not be doing this
                    am.ExtraAttributes[kvp.Key.ToString()] = kvp.Value.ToString();
                }
            }
            return(am);
        }
Ejemplo n.º 2
0
        public BrigitGraph CreateFork(YamlMappingNode yamlNode)
        {
            var forkingGraph           = new BrigitGraph();
            var nonInteractiveDecision = new Decision();

            nonInteractiveDecision.Interactive = false;
            var baseNode = new Node(nonInteractiveDecision);

            forkingGraph.AddNode(baseNode);

            foreach (YamlMappingNode node in (YamlSequenceNode)yamlNode.Children[new YamlScalarNode("fork")])
            {
                var choice = new Choice();
                choice.NextNode = -1;
                string expression = GetScalarYamlNodeValue("path", node);
                choice.Attributes.Expression = BrigitExpressionParser.Parse(expression);

                if (node.Children.ContainsKey(new YamlScalarNode("graph")))
                {
                    var subGraph = CreateGraph((YamlSequenceNode)node.Children[new YamlScalarNode("graph")]);
                    forkingGraph.AddBranch(baseNode, subGraph);
                    choice.NextNode = baseNode.Next.Count - 1;
                }

                nonInteractiveDecision.Choices.Add(choice);
            }

            foreach (Choice choice in nonInteractiveDecision.Choices.Where(x => x.NextNode == -1))
            {
                choice.NextNode = baseNode.Next.Count;
            }

            return(forkingGraph);
        }
Ejemplo n.º 3
0
        public void Parse_TwoVariableExpresssionWithNoOperator_Fails()
        {
            // arrange
            string expression = "var1 var2";

            // act
            bool parsed = BrigitExpressionParser.Preprocess(expression);

            Assert.Throws <Exception>(() => BrigitExpressionParser.Parse(expression));
        }
Ejemplo n.º 4
0
        public void Parse_SingleVaribaleExpression()
        {
            // arrange
            string expression = "var1";

            //act
            bool parsedWell = BrigitExpressionParser.Preprocess(expression);
            var  exp        = BrigitExpressionParser.Parse(expression);
            var  expected   = new Variable("var1");

            // assert
            bool checker = parsedWell && expected.Equals(exp);

            Assert.AreEqual(true, checker);
        }
Ejemplo n.º 5
0
 private static IExpression ParseRequiredFlags(string str)
 {
     return(BrigitExpressionParser.Parse(str));
 }
Ejemplo n.º 6
0
        // this will select a branch from a set given to it
        // this looks really similar to chioce with some smaller but important changes
        public BrigitGraph ParseBranchSelector(Dictionary <string, OpenChoice> branchEndings)
        {
            AssertChar(Stream, '{');
            // the loop consists of parsing expression, parsing branch
            // then check for a new expression or the end

            // TODO replace this fix with a more elegant solution
            // hot fix used for resetting the open choices
            List <string> branches = new List <string>();
            Decision      selector = new Decision();

            selector.Interactive = false;
            BrigitGraph graph = new BrigitGraph();
            Node        root  = new Node()
            {
                Data = selector
            };

            graph.AddNode(root);

            while (Stream.PeekChar() != '}')
            {
                // gets chars up to the *
                string      expression = FetchNonStarSubString();
                IExpression exp;
                if (expression == "_")
                {
                    //exp = new Tautalogy();
                    exp = new Variable("TRUE");
                }
                else
                {
                    exp = BrigitExpressionParser.Parse(expression);
                }
                // eat the star that ends the expresssion
                AssertChar(Stream, '*');
                Choice ch = new Choice();
                ch.Attributes.Expression = exp;
                ch.Text     = string.Empty;
                ch.NextNode = -1;

                EatWhitespace(Stream);

                // if there is no arrow then it should be considered a
                // "pass"
                // there can be multiple passes, but there can only be one default which is "_"
                if (Stream.PeekChar() == '-')
                {
                    // parse either a sub graph or parse a branchname
                    ParseArrow(Stream);
                    EatWhitespace(Stream);

                    if (Stream.PeekChar() == '{')
                    {
                        AssertChar(Stream, '{');
                        BrigitGraph subGraph = ParseBrigitGraph(Stream);
                        graph.AddBranch(root, subGraph);
                        ch.NextNode = root.Next.Count - 1;
                    }
                    else if (Char.IsLetterOrDigit(Stream.PeekChar()))
                    {
                        string BranchName = ParseOnlyTextNoEscape(Stream);
                        branches.Add(BranchName);
                        OpenChoice open = new OpenChoice(root, ch);
                        branchEndings.Add(BranchName, open);
                    }
                    else
                    {
                        // throw not recognized
                        string msg = String.Format("Expected beginning of branch name or sub graph but found {0} at {1}", Stream.PeekChar(), Stream.Position);
                        throw new Exception(msg);
                    }
                }
                // a pass
                else
                {
                }
                selector.Choices.Add(ch);
                EatWhitespace(Stream);
            }

            // to end this off
            AssertChar(Stream, '}');

            foreach (Choice ch in selector.Choices)
            {
                if (ch.NextNode == -1)
                {
                    ch.NextNode = root.Next.Count;
                }
            }

            foreach (string s in branches)
            {
                branchEndings[s].TailNode = null;
            }

            return(graph);
        }