[stringtemplate-interest] What compiles to : Bytecode.INSTR_LOAD_ATTR ?
Collin Fagan
collin.fagan at gmail.com
Sun Sep 4 04:38:52 PDT 2011
Thanks Udo, that worked.
On Sun, Sep 4, 2011 at 4:53 AM, Udo Borkowski <ub at abego-software.de> 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/aeceab42/attachment.html
More information about the stringtemplate-interest
mailing list