[stringtemplate-interest] What compiles to : Bytecode.INSTR_LOAD_ATTR ?
Collin Fagan
collin.fagan at gmail.com
Sun Sep 4 05:44:44 PDT 2011
It got me on the right track. I now have a template that will get all it's
attributes from a Spring ApplicationContext.
So now I can do :
main() ::= <<
<springBean.value>
>>
Where springBean is the name of the bean in the ApplicationContext. So now I
can dependency inject a template attribute.
Next is jsr223 (scripting) support I think.
Collin
On Sun, Sep 4, 2011 at 5:05 AM, Udo Borkowski <Udo.Borkowski at gmx.de> wrote:
> Hi Colin,
> little typo:
>
>
>
> instead of
>
> group.defineTemplate("main", "string", "{<string.q>}");
>
>
> just write
>
> group.defineTemplate("main", "{<string.q>}");
>
>
>
> and it will generate an INSTR_LOAD_ATTR
>
> Udo
>
>
> P.S. The relevant ST4 code is located in
> public void refAttr(Token templateToken, CommonTree id)
>
>
>
> On 04.09.2011, at 11:53, Udo Borkowski wrote:
>
> Hi Colin,
>
> instead of
>
> group.defineTemplate("main", "string", "{<string.q>}");
>
>
> just write
>
> group.defineTemplate("main", "{<string.q>}");
>
>
>
> and it will generate an INSTR_LOAD_LOCAL
>
> Udo
>
>
> On 03.09.2011, at 14:30, Collin Fagan wrote:
>
> Hi Everyone,
>
> In my (probably misguided) quest to inject attributes into the scope of a
> template I've overridden the getAttribute method on Interpreter. This method
> call gets invoked when the Interpreter runs into Bytecode.INSTR_LOAD_ATTR.
> My problem is that my simple test never generates this bytecode. It only
> generates Bytecode.INSTR_LOAD_LOCAL.
>
> Does anyone know what I have to do to generate Bytecode.INSTR_LOAD_ATTR?
>
>
> Thanks,
>
> Collin
>
>
> Here is my experimental code:
>
> /**
> *
> * @author collin
> */
> public class Exp {
>
> private class ExtInterpreter extends Interpreter {
>
> public ExtInterpreter(STGroup group, Locale locale,
> ErrorManager errMgr, boolean debug) {
> super(group, locale, errMgr, debug);
> // TODO Auto-generated constructor stub
> }
>
> @Override
> public Object getAttribute(ST self, String name) {
> System.out.println(name);
> return super.getAttribute(self, name);
> }
> }
>
> @Test
> public void testStaticMethodAddForString() {
> STGroup group = new STGroup();
> group.defineTemplate("main", "string", "{<string.q>}");
> ST mainTemplate = group.getInstanceOf("main");
> // mainTemplate.add("string", "this is my test string");
>
> Interpreter interp = new
> ExtInterpreter(group,Locale.getDefault(),group.errMgr,false);
> StringWriter stringWriter = new StringWriter();
> STWriter wr = new AutoIndentWriter(stringWriter);
> wr.setLineWidth(STWriter.NO_WRAP);
> interp.exec(wr, mainTemplate);
> System.out.print(stringWriter.toString());
> }
> }
>
>
>
> _______________________________________________
> stringtemplate-interest mailing list
> stringtemplate-interest at antlr.org
> http://www.antlr.org/mailman/listinfo/stringtemplate-interest
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/stringtemplate-interest/attachments/20110904/e48cf6fb/attachment-0001.html
More information about the stringtemplate-interest
mailing list