c# - StringTemplate vs. StringTemplateGroup -
i'm using stringtemplate 4 code generation in visual studio. i've installed extensions stringtemplate , antlr , great.
in testing, can figure out how use *.st4 (stringtemplate) file, how use *.stg (stringtemplategroup) file escapes me. collection of definitions can embedded stringtemplate? if so, code generate *.stg rather *.st4?
a stringtemplate group file collection of templates stored within single file. antlr project on github contains many examples; e.g. java.stg contains of code generation templates java target antlr 4.
you can find several examples using stringtemplate 3 in c# in stringtemplatetests.cs file stringtemplate c# project itself. it's not friendly documentation, include examples covering wide range of st3 features. here 1 example using stringtemplategroup
:
string templates = "group dork;" + newline + "" + newline + "test(name) ::= <<" + "<(name)()>" + newline + ">>" + newline + "first() ::= \"the first\"" + newline + "second() ::= \"the second\"" + newline ; stringtemplategroup group = new stringtemplategroup( new stringreader( templates ) ); stringtemplate f = group.getinstanceof( "test" ); f.setattribute( "name", "first" ); string expecting = "the first"; assert.areequal( expecting, f.tostring() );
so it's easier read, template group file code test looks without escape characters.
group dork; test(name) ::= <<<(name)()> >> first() ::= "the first" second() ::= "the second"
Comments
Post a Comment