Example #1
0
        public void TestScope2()
        {
            MemoryStream   ms   = Content.GenerateContent2();
            MiniZincLexer  scnr = new MiniZincLexer(ms);
            MiniZincParser pars = new MiniZincParser(scnr);

            pars.Parse();
            ZincModel model = pars.Result;

            Assert.IsNotNull(model);
            model.CloseScope(null);
            ZincIdentNameRegister zinr     = model.NameRegister;
            List <IZincIdent>     iz       = zinr.Elements().ToList();
            List <string>         result   = iz.Select(x => x.Name).ToList();
            List <string>         expected = new List <string> (new string[] { "size", "d", "total", "end" });

            Assert.AreEqual(expected.Count, result.Count);
            foreach (string si in expected)
            {
                Assert.Contains(si, result);
            }
            Assert.AreEqual(6, model.Items.Count());
            Assert.AreEqual(5, model.Items.OfType <ZincVarDeclItem> ().Count());
            Assert.AreEqual(1, model.Items.OfType <ZincSolveItem> ().Count());
            List <ZincVarDeclItem> zvd = new List <ZincVarDeclItem> ();

            foreach (string si in expected)
            {
                ZincVarDeclItem zvdi = model.Items.OfType <ZincVarDeclItem> ().Where(x => x.DeclaredIdentifier.Name == si).FirstOrDefault();
                Assert.NotNull(zvdi);
                Assert.Contains(zvdi.DeclaredIdentifier, iz);
                zvd.Add(zvdi);
            }
        }
Example #2
0
 public void TestParser0()
 {
     using (MemoryStream ms = Content.GenerateContent0()) {
         MiniZincLexer  scnr = new MiniZincLexer(ms);
         MiniZincParser pars = new MiniZincParser(scnr);
         pars.Parse();
         ZincModel model = pars.Result;
         Assert.IsNotNull(model);
         IZincItem[] items = model.Items.ToArray();
         Assert.AreEqual(Content.NItems0, items.Length);
     }
 }
Example #3
0
        public void TestScope0()
        {
            MemoryStream   ms   = Content.GenerateContent0();
            MiniZincLexer  scnr = new MiniZincLexer(ms);
            MiniZincParser pars = new MiniZincParser(scnr);

            pars.Parse();
            ZincModel model = pars.Result;

            Assert.IsNotNull(model);
            model.CloseScope(null);
            //TODO: finish test
        }
Example #4
0
        /// <summary>
        /// The entry point of the program, where the program control starts and ends.
        /// </summary>
        /// <param name="args">The command-line arguments.</param>
        /// <returns>The exit code that is given to the operating system after the program ends.</returns>
        public static int Main(string[] args)
        {
            bool show_help         = false;
            ProgramEnvironment env = new ProgramEnvironment();
            var p = new OptionSet()
            {
                {
                    "t|task=",
                    "The task to be executed (validate-model,validate-data,match,generate-data,generate-heuristics,assume).",
                    env.SetTask
                },
                { "v|verbosity=", "The level of verbosity (error,warning,assumption,remark).", env.SetVerbosity },
                { "h|help", "Show this help message and exit.", x => show_help = x != null }
            };

            List <string> files = new List <string> ();

            try {
                files = p.Parse(args);
                Interaction.VerbosityLevel = env.Verbosity;
            } catch (OptionException e) {
                Console.Error.Write("zincoxide: ");
                Console.Error.WriteLine(e.Message);
                Console.Error.WriteLine("Try 'zincoxide --help' for more information.");
                return((int)ProgramResult.StaticError);
            } catch (ZincOxideException e) {
                Interaction.Error(e.Message);
                return((int)ProgramResult.StaticError);
            }

            if (show_help)
            {
                Console.Error.WriteLine("Usage: zincoxide [Options]+ files");
                Console.Error.WriteLine();
                Console.Error.WriteLine("Options: ");
                p.WriteOptionDescriptions(Console.Error);
            }
            else
            {
                DirectoryInfo dirInfo = new DirectoryInfo(".");
                foreach (string name in files)
                {
                    FileInfo[] fInfo = dirInfo.GetFiles(name);
                    foreach (FileInfo info in fInfo)
                    {
                        try {
                            using (FileStream file = new FileStream(info.FullName, FileMode.Open)) {
                                MiniZincLexer  scnr = new MiniZincLexer(file);
                                MiniZincParser pars = new MiniZincParser(scnr);

                                Interaction.ActiveFile = info.Name;

                                Console.Error.WriteLine("File: " + info.Name);
#if PARSE
                                pars.Parse();
#else
                                foreach (Token tok in scnr.Tokenize())
                                {
                                    Console.Error.Write(tok);
                                    Console.Error.Write(' ');
                                }
#endif
                                if (pars.Result != null)
                                {
                                    Console.Error.WriteLine("echo: ");
                                    pars.Result.Write(Console.Out);
                                }
                                else
                                {
                                    Interaction.Warning("File \"{0}\" is not a valid MiniZinc file.");
                                }
                            }
                        } catch (IOException) {
                            Interaction.Warning("File \"{0}\" not found.", info.Name);
                        }
                    }
                }
            }
            return((int)ProgramResult.Succes);
        }