Exemplo n.º 1
0
 protected TemplateGroup GetTemplateGroupFromResource(string templateName)
 {
     var tg = new TemplateGroupString(templateName.Replace("_", "."), Resource.ResourceManager.GetString(templateName));
     tg.ErrorManager = new ErrorManager(ERROR_LISTENER);
     tg.Load();
     return tg;
 }
Exemplo n.º 2
0
 public void TestDontTrimJustSpaceBeforeAfterInTemplate()
 {
     string templates =
         "a(x) ::= << foo >>\n";
     TemplateGroupString group = new TemplateGroupString(templates);
     Template st = group.GetInstanceOf("a");
     string expected = " foo ";
     string result = st.Render();
     Assert.AreEqual(expected, result);
 }
Exemplo n.º 3
0
 public void TestEmptyNoNewlineTemplate()
 {
     string template =
         "t(x) ::= <%%>" + newline;
     TemplateGroup g = new TemplateGroupString(template);
     Template st = g.GetInstanceOf("t");
     st.Add("x", 99);
     string expected = "";
     string result = st.Render();
     Assert.AreEqual(expected, result);
 }
Exemplo n.º 4
0
 public void TestIgnoreIndent()
 {
     string template =
         "t(x) ::= <%" + newline +
         "	foo" + newline +
         "	<x>" + newline +
         "%>" + newline;
     TemplateGroup g = new TemplateGroupString(template);
     Template st = g.GetInstanceOf("t");
     st.Add("x", 99);
     string expected = "foo99";
     string result = st.Render();
     Assert.AreEqual(expected, result);
 }
Exemplo n.º 5
0
 public void TestEvalExprEventForSpecialCharacter()
 {
     string templates = "t() ::= <<[<\\n>]>>\n";
     //                            012 345
     TemplateGroupString g = new TemplateGroupString(templates);
     Template st = g.GetInstanceOf("t");
     st.impl.Dump();
     StringWriter writer = new StringWriter();
     List<InterpEvent> events = st.GetEvents(new AutoIndentWriter(writer, "\n"));
     string expected =
         "[EvalExprEvent{self=/t(), expr='[', source=[0..1), output=[0..1)}, " +
         "EvalExprEvent{self=/t(), expr='\\n', source=[2..4), output=[1..2)}, " +
         "EvalExprEvent{self=/t(), expr=']', source=[5..6), output=[2..3)}, " +
         "EvalTemplateEvent{self=/t(), output=[0..3)}]";
     string result = events.ToListString();
     Assert.AreEqual(expected, result);
 }
        CodeGenerationResult Generate(ITaskDefinitionSymbol taskDefinition) {

            // TODO Diagnostic check

            var result = new CodeGenerationResult(taskDefinition);

            if (_options.GenerateIBeginWfsInterface) {

                var model = new BeginWfsCodeModel(taskDefinition);
                var group = new TemplateGroupString(Resources.IBeginWFS);
                var st    = group.GetInstanceOf("IBeginWFS");

                st.Add("model", model);
                // TODO Add Context?

                result.BeginWfsInterface = st.Render();
            }

            return result;
        }
Exemplo n.º 7
0
 public void TestComplicatedIndirectTemplateApplication()
 {
     string templates =
         "group Java;" + newline +
         "" + newline +
         "file(variables) ::= <<" +
         "<variables:{ v | <v.decl:(v.format)()>}; separator=\"\\n\">" + newline +
         ">>" + newline +
         "intdecl(decl) ::= \"int <decl.name> = 0;\"" + newline +
         "intarray(decl) ::= \"int[] <decl.name> = null;\"" + newline
         ;
     TemplateGroup group = new TemplateGroupString(templates);
     Template f = group.GetInstanceOf("file");
     f.AddMany("variables.{ decl,format }", new Decl("i", "int"), "intdecl");
     f.AddMany("variables.{decl ,  format}", new Decl("a", "int-array"), "intarray");
     //System.out.println("f='"+f+"'");
     string expecting = "int i = 0;" + newline +
                        "int[] a = null;";
     Assert.AreEqual(expecting, f.Render());
 }
Exemplo n.º 8
0
 public void TestPassThruWithDefaultValueThatLacksDefinitionAbove()
 {
     string templates =
         "a(x) ::= \"<b(...)>\"\n" + // should not set y when it sees "no definition" from above
         "b(x,y={99}) ::= \"<x><y>\"\n";
     TemplateGroup group = new TemplateGroupString(templates);
     Template a = group.GetInstanceOf("a");
     a.Add("x", "x");
     string expected = "x99";
     string result = a.Render();
     Assert.AreEqual(expected, result);
 }
Exemplo n.º 9
0
 public void TestPassThruPartialArgs()
 {
     string templates =
         "a(x,y) ::= \"<b(y={99},...)>\"\n" +
         "b(x,y) ::= \"<x><y>\"\n";
     TemplateGroup group = new TemplateGroupString(templates);
     Template a = group.GetInstanceOf("a");
     a.Add("x", "x");
     a.Add("y", "y");
     string expected = "x99";
     string result = a.Render();
     Assert.AreEqual(expected, result);
 }
Exemplo n.º 10
0
 public void TestDelimitersClauseInGroupString()
 {
     string templates =
             "delimiters \"$\", \"$\"" + newline +
             "method(name) ::= <<" + newline +
             "$stat(name)$" + newline +
             ">>" + newline +
             "stat(name,value=\"99\") ::= \"x=$value$; // $name$\"" + newline
             ;
     TemplateGroup group = new TemplateGroupString(templates);
     Template b = group.GetInstanceOf("method");
     b.Add("name", "foo");
     string expecting = "x=99; // foo";
     string result = b.Render();
     Assert.AreEqual(expecting, result);
 }
Exemplo n.º 11
0
 public void TestRegion()
 {
     string template =
         "t(x) ::= <%\n" +
         "<@r>\n" +
         "	Ignore\n" +
         "	newlines and indents\n" +
         "<x>\n\n\n" +
         "<@end>\n" +
         "%>\n";
     TemplateGroup g = new TemplateGroupString(template);
     Template st = g.GetInstanceOf("t");
     st.Add("x", 99);
     string expected = "Ignorenewlines and indents99";
     string result = st.Render();
     Assert.AreEqual(expected, result);
 }
Exemplo n.º 12
0
 public void TestSimpleGroupFromString()
 {
     string g =
         "a(x) ::= <<foo>>\n" +
         "b() ::= <<bar>>\n";
     TemplateGroup group = new TemplateGroupString(g);
     Template st = group.GetInstanceOf("a");
     string expected = "foo";
     string result = st.Render();
     Assert.AreEqual(expected, result);
 }
Exemplo n.º 13
0
 public void TestKeepWS()
 {
     string template =
         "t(x) ::= <%" + newline +
         "	<x> <x> hi" + newline +
         "%>" + newline;
     TemplateGroup g = new TemplateGroupString(template);
     Template st = g.GetInstanceOf("t");
     st.Add("x", 99);
     string expected = "99 99 hi";
     string result = st.Render();
     Assert.AreEqual(expected, result);
 }
Exemplo n.º 14
0
 public void TestTrimmedNewlinesBeforeAfterInTemplate()
 {
     string templates =
         "a(x) ::= <<" + newline +
         "foo" + newline +
         ">>" + newline;
     TemplateGroupString group = new TemplateGroupString(templates);
     Template st = group.GetInstanceOf("a");
     string expected = "foo";
     string result = st.Render();
     Assert.AreEqual(expected, result);
 }
Exemplo n.º 15
0
        public void TestRegionOverrideRefSuperRegion2Levels()
        {
            string g =
                    "a() ::= \"X<@r()>Y\"\n" +
                    "@a.r() ::= \"foo\"\n";
            TemplateGroup group = new TemplateGroupString(g);

            string sub =
                    "@a.r() ::= \"<@super.r()>2\"\n";
            TemplateGroup subGroup = new TemplateGroupString(sub);
            subGroup.ImportTemplates(group);

            Template st = subGroup.GetInstanceOf("a");

            string result = st.Render();
            string expecting = "Xfoo2Y";
            Assert.AreEqual(expecting, result);
        }
Exemplo n.º 16
0
 public void TestNoNewlineTemplate()
 {
     string template =
         "t(x) ::= <%" + newline +
         "[  <if(!x)>" +
         "<else>" +
         "<x>" + newline +
         "<endif>" +
         "" + newline +
         "" + newline +
         "]" + newline +
         "" + newline +
         "%>" + newline;
     TemplateGroup g = new TemplateGroupString(template);
     Template st = g.GetInstanceOf("t");
     st.Add("x", 99);
     string expected = "[  99]";
     string result = st.Render();
     Assert.AreEqual(expected, result);
 }
Exemplo n.º 17
0
 public void TestEarlyEvalOfDefaultArgs()
 {
     string templates =
         "s(x,y={<(x)>}) ::= \"<x><y>\"\n"; // should see x in def arg
     TemplateGroup group = new TemplateGroupString(templates);
     Template b = group.GetInstanceOf("s");
     b.Add("x", "a");
     string expecting = "aa";
     string result = b.Render();
     Assert.AreEqual(expecting, result);
 }