[stringtemplate-interest] Capturing evaluated attributes

Terence Parr parrt at cs.usfca.edu
Tue May 3 17:05:05 PDT 2011


If you are debugging, that is your past in the debug flag to the interpreter, it will pass you a list of events that tells you exactly what's happened. That is how the STViz inspector works. I think that you might be missing a number of events going on inside the interpreter.
Ter
On Nov 20, 2009, at 2:48 PM, Scott Waye wrote:

> Hi,
> 
> I want to capture all evaluated attributes, and some summary about how 
> they expanded (null, empty string, or not null).  So I subclassed 
> StringTemplate with this:
> 
>    public class HostTemplate : StringTemplate
>    {
>        public class AttributeExpansion    
>        {
>            public string Name { get; set; }
>            public object Result { get; set; }
>        }
> 
>        public List<string> NullAttributes = new List<string>();
>        public List<string> EmptyStringAttributes = new List<string>();
>        public List<AttributeExpansion> ExpandedAttributes = new 
> List<AttributeExpansion>();
> 
>        public HostTemplate(string template) : base(template)
>        {
>        }
> 
>        public override object GetAttribute(string name)
>        {
>            var res = base.GetAttribute(name);
>            if(res == null)
>            {
>                NullAttributes.Add(name);
>            }
>            else if(res is string && ((string)res) == "")
>            {
>                EmptyStringAttributes.Add(name);
>            }
>            else
>            {
>                ExpandedAttributes.Add(new AttributeExpansion {Name = 
> name, Result = res});
>            }
>            return res;
>        }
>    }
> 
> Seems to work, at least on simple templates.  Does this look OK, or have 
> I reinvented a wheel that I've missed?
> 
> --
> Scott
> _______________________________________________
> stringtemplate-interest mailing list
> stringtemplate-interest at antlr.org
> http://www.antlr.org/mailman/listinfo/stringtemplate-interest



More information about the stringtemplate-interest mailing list