Beispiel #1
0
        public void TestGroupFileInDirImportsAnotherGroupFile()
        {
            // /randomdir/group.stg with a() imports /randomdir/imported.stg with b()
            // can't have groupdir then groupfile inside that imports
            string dir       = tmpdir;
            string groupFile =
                "import \"imported.stg\"\n" +
                "a() ::= \"a: <b()>\"\n";

            writeFile(dir, "group.stg", groupFile);
            string importedFile =
                "b() ::= \"b\"\n";

            writeFile(dir, "imported.stg", importedFile);
            ITemplateErrorListener errors = new ErrorBuffer();
            TemplateGroup          group  = new TemplateGroupDirectory(dir);

            group.Listener = errors;
            group.GetInstanceOf("/group/a");
            string result    = errors.ToString();
            string substring =
                "import illegal in group files embedded in TemplateGroupDirectory; import \"imported.stg\" in TemplateGroupDirectory";

            StringAssert.Contains(result, substring);
        }
Beispiel #2
0
        /** The format gets reset either from the Tool if the user supplied a command line option to that effect
         *  Otherwise we just use the default "antlr".
         */
        public virtual void SetFormat(string formatName)
        {
            this.formatName = formatName;
            string fileName = Path.Combine(FORMATS_DIR, formatName + TemplateGroup.GroupFileExtension);

            if (!File.Exists(fileName) && formatName != "antlr")
            {
                SetFormat("antlr");
                return;
            }

            //format.EnableCache = AntlrTool.EnableTemplateCache;
            if (!File.Exists(fileName))
            {
                RawError("ANTLR installation corrupted; cannot find ANTLR messages format file " + fileName);
                Panic();
            }
            //else if (url == null)
            //{
            //    RawError("no such message format file " + fileName + " retrying with default ANTLR format");
            //    SetFormat("antlr"); // recurse on this rule, trying the default message format
            //    return;
            //}

            format = new TemplateGroupFile(
                Path.Combine(
                    Path.GetDirectoryName(typeof(AntlrTool).GetTypeInfo().Assembly.Location),
                    fileName),
                Encoding.UTF8);
            format.Load();

            if (initSTListener.Errors.Count > 0)
            {
                RawError("ANTLR installation corrupted; can't load messages format file:\n" +
                         initSTListener.ToString());
                Panic();
            }

            bool formatOK = VerifyFormat();

            if (!formatOK && formatName.Equals("antlr"))
            {
                RawError("ANTLR installation corrupted; ANTLR messages format file " + formatName + ".stg incomplete");
                Panic();
            }
            else if (!formatOK)
            {
                SetFormat("antlr"); // recurse on this rule, trying the default message format
            }
        }
 public void TestIndirectCallWithPassThru()
 {
     // pass-through for dynamic template invocation is not supported by the
     // bytecode representation
     writeFile(tmpdir, "t.stg",
         "t1(x) ::= \"<x>\"\n" +
         "main(x=\"hello\",t=\"t1\") ::= <<\n" +
         "<(t)(...)>\n" +
         ">>");
     TemplateGroup group = new TemplateGroupFile(tmpdir + "/t.stg");
     ErrorBuffer errors = new ErrorBuffer();
     group.Listener = errors;
     Template st = group.GetInstanceOf("main");
     Assert.AreEqual("t.stg 2:34: mismatched input '...' expecting RPAREN" + newline, errors.ToString());
     Assert.IsNull(st);
 }
Beispiel #4
0
        /** The format gets reset either from the Tool if the user supplied a command line option to that effect
         *  Otherwise we just use the default "antlr".
         */
        public virtual void SetFormat(string formatName)
        {
            this.formatName = formatName;
            string fileName = Path.Combine(FormatsDir, formatName + TemplateGroup.GroupFileExtension);

            if (!File.Exists(fileName) && formatName != "antlr")
            {
                SetFormat("antlr");
                return;
            }

            //format.EnableCache = AntlrTool.EnableTemplateCache;
            if (!File.Exists(fileName))
            {
                var embedded = new Uri($"pack://application:,,,antlr.stg");
                format = new TemplateGroupFile(embedded, Encoding.UTF8, '<', '>');
            }
            //else if (url == null)
            //{
            //    RawError("no such message format file " + fileName + " retrying with default ANTLR format");
            //    SetFormat("antlr"); // recurse on this rule, trying the default message format
            //    return;
            //}

            format = new TemplateGroupFile(fileName, Encoding.UTF8);
            format.Load();

            if (initSTListener.Errors.Count > 0)
            {
                RawError("ANTLR installation corrupted; can't load messages format file:\n" +
                         initSTListener.ToString());
                Panic();
            }

            bool formatOK = VerifyFormat();

            if (!formatOK && formatName.Equals("antlr"))
            {
                RawError("ANTLR installation corrupted; ANTLR messages format file " + formatName + ".stg incomplete");
                Panic();
            }
            else if (!formatOK)
            {
                SetFormat("antlr"); // recurse on this rule, trying the default message format
            }
        }
        public void TestIndirectCallWithPassThru()
        {
            // pass-through for dynamic template invocation is not supported by the
            // bytecode representation
            writeFile(tmpdir, "t.stg",
                      "t1(x) ::= \"<x>\"\n" +
                      "main(x=\"hello\",t=\"t1\") ::= <<\n" +
                      "<(t)(...)>\n" +
                      ">>");
            TemplateGroup group  = new TemplateGroupFile(tmpdir + "/t.stg");
            ErrorBuffer   errors = new ErrorBuffer();

            group.Listener = errors;
            Template st = group.GetInstanceOf("main");

            Assert.AreEqual("t.stg 2:34: mismatched input '...' expecting RPAREN" + newline, errors.ToString());
            Assert.IsNull(st);
        }
Beispiel #6
0
 public void TestGroupFileInDirImportsAnotherGroupFile()
 {
     // /randomdir/group.stg with a() imports /randomdir/imported.stg with b()
     // can't have groupdir then groupfile inside that imports
     string dir = tmpdir;
     string groupFile =
         "import \"imported.stg\"\n" +
         "a() ::= \"a: <b()>\"\n";
     writeFile(dir, "group.stg", groupFile);
     string importedFile =
         "b() ::= \"b\"\n";
     writeFile(dir, "imported.stg", importedFile);
     ITemplateErrorListener errors = new ErrorBuffer();
     TemplateGroup group = new TemplateGroupDirectory(dir);
     group.Listener = errors;
     group.GetInstanceOf("/group/a");
     string result = errors.ToString();
     string substring =
         "import illegal in group files embedded in TemplateGroupDirectory; import \"imported.stg\" in TemplateGroupDirectory";
     StringAssert.Contains(result, substring);
 }