STG grammar

63 views
Skip to first unread message

Andrzej Borucki

unread,
Mar 4, 2014, 8:08:13 AM3/4/14
to antlr-di...@googlegroups.com
I search .stg files grammar, it is simple, but for example how to use "<" in template?

Andrzej Borucki

unread,
Mar 4, 2014, 11:14:47 AM3/4/14
to antlr-di...@googlegroups.com

Andrzej Borucki

unread,
Mar 4, 2014, 3:29:08 PM3/4/14
to antlr-di...@googlegroups.com
I am beginner using StringTemplate. 
I use method: 
public static void twoST() {
String result;
STGroup group = new STGroupDir(".");
ST st = group.getInstanceOf("decl"); 
st.add("type", "int");
st.add("name", "x");
st.add("value", 0);
result = st.render(); // yields "int x = 0;"
System.out.println(result);
}..

with decl.st : decl(type, name, value) ::= "<type> <name><if(value)>;"
init.st : init(v) ::= "<if(v)> = <v><endif>"
. 1:54: premature EOF
whereas if I use 
public static void testSTG() {
STGroup group = new STGroupFile("test.stg");
ST st = group.getInstanceOf("decl");
st.add("type", "int");
st.add("name", "x");
st.add("value", 0);
String result = st.render(); // yields "int x = 0;"
System.out.println(result);
}
with test.stg :
decl(type, name, value) ::= "<type> <name><init(value)>;"
init(v) ::= "<if(v)> = <v><endif>"
Is OK :
int x = 0;
but in test.stg I add
 if(v) ::= "if <v>"
then is again 
int x = 0;
instead 
int x if(0)= 0;

Sam Harwell

unread,
Mar 4, 2014, 3:53:40 PM3/4/14
to antlr-di...@googlegroups.com

In your first decl.st, you have an <if(value)> that does not have a matching <endif> tag.

 

Other than that, I’m not sure what your question is.

 

Sam

--
You received this message because you are subscribed to the Google Groups "antlr-discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to antlr-discussi...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Andrzej Borucki

unread,
Mar 4, 2014, 4:10:48 PM3/4/14
to antlr-di...@googlegroups.com
Yes, in first should be "init", not "if"
Reply all
Reply to author
Forward
0 new messages