[stringtemplate-interest] trouble wth regions
Matthew Foemmel
antlr at foemmel.com
Fri Jan 12 19:42:44 PST 2007
Hi all,
I'm having a bit of trouble getting regions to work, and was wondering if someone could give me a hand. I've created two groups: a parent, which contains the layout for a web page, and a child, which contains the actual content. I'd like use regions to create "holes" in the layout page where the content page can insert values.
For example, the parent group looks like this:
-----
group Super;
main() ::= <<
<html><body>$@body()$</body></html>
>>
-----
and the child group looks like this:
-----
group Sub;
@main.body() ::= "Hello, World!"
-----
However, when I try to get an instance of the "main" template from the child group, I get an exception that says it can't find template "main.st". If I remove the "@main.body()" template from the child group, I don't get that error (but then the content from the child group isn't inserted, obviously).
Here's my JUnit test:
-----
import static org.junit.Assert.*;
import java.io.StringReader;
import org.antlr.stringtemplate.StringTemplateGroup;
import org.antlr.stringtemplate.StringTemplateGroupInterface;
import org.antlr.stringtemplate.StringTemplateGroupLoader;
import org.antlr.stringtemplate.language.DefaultTemplateLexer;
import org.junit.Test;
public class StringTemplateTest {
@Test
public void regionInhertiance() {
String superText = "group Super;\n\nmain() ::= <<\n<html><body>$@body()$</body></html>\n>>";
StringTemplateGroup superGroup = new StringTemplateGroup(new StringReader(superText), DefaultTemplateLexer.class);
String subText = "group Sub;\n\n at main.body() ::= \"Hello, World!\"";
StringTemplateGroup subGroup = new StringTemplateGroup(new StringReader(subText), DefaultTemplateLexer.class);
subGroup.setSuperGroup(superGroup);
String expected = "<html><body>Hello, World!</body></html>";
String actual = subGroup.getInstanceOf("main").toString();
assertEquals(expected, actual);
}
}
-----
Any help would be appreciated (I'm using version 3.0 of stringtemplate). Thanks in advance.
Cheers,
Foemmel
More information about the stringtemplate-interest
mailing list