Пример #1
0
        public void BasicTerm()
        {
            Event root = new RootEvent()
                         .AddChildEvent(new OutputEvent("A")
                                        .AddChildEvent(new OutputEvent("B")))
                         .AddChildEvent(new OutputEvent("C"))
                         .AddChildEvent(new OutputEvent("A")
                                        .AddChildEvent(new OutputEvent("F"))
                                        .AddChildEvent(new OutputEvent("B"))
                                        );

            PathExpression p = new Root().Extend(new Name("A").Extend(new All()));


            String expected = @"/
/A/
/A/B/
/C/
/A/
/A/F/
/A/B/
";

            Assert.AreEqual(expected, root.PrintTree());

            //int i = 0;
            Assert.AreEqual("/A/*", p.ToString());

            String s = "";

            foreach (Event e in p.Eval(root, root))
            {
                s += e.name;
            }
            Assert.AreEqual("BFB", s);
        }
Пример #2
0
        static void Main(string[] args)
        {
            parser = new ResedaParser();
            var exit = false;

            while (exit == false)
            {
                Console.WriteLine();
                Console.WriteLine("Enter command (help to display help): ");
                var commandParts = Console.ReadLine().Split(' ').ToList();
                var commandName  = commandParts[0];
                var commandArgs  = commandParts.Skip(1).ToList(); // the arguments is after the command
                try
                {
                    switch (commandName)
                    {
                    // Create command based on CommandName (and maybe arguments)
                    case "exit": exit = true; break;

                    case "parse":
                        String s = "";
                        foreach (var i in commandArgs)
                        {
                            s += i + " ";
                        }
                        Parse(s);
                        break;

                    case "load":
                        Load(commandArgs[0]);
                        break;

                    case "term": Console.WriteLine(term.ToSource()); break;

                    case "auto": autoCompute = !autoCompute;  Console.WriteLine(autoCompute); break;

                    case "tree": Console.WriteLine(term.PrintTree(true)); break;

                    case "live": Console.WriteLine(term.ProcessIsLive()); break;

                    case "inseq": term = term.MakeInSeq(); break;

                    case "glitchfree": term = term.MakeGlitchFree(); break;

                    case "list":
                        foreach (var pe in term.GetAllEnabledEvents())
                        {
                            Console.WriteLine(pe.ToSource());
                        }
                        break;

                    case "execute":
                        if (commandArgs.Count > 1)
                        {
                            Execute(commandArgs[0], commandArgs[1]);
                        }
                        else
                        {
                            Execute(commandArgs[0]);
                        }
                        break;

                    default:
                        if (commandArgs.Count > 0)
                        {
                            Execute(commandName, commandArgs[0]);
                        }
                        else
                        {
                            Execute(commandName);
                        }

                        break;
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine("Command " + commandName + "failed, because:");
                    Console.WriteLine(e.Message);
                }
            }
        }