[stringtemplate-interest] Attribute not found exception?

Miha Valencic miha.valencic at gmail.com
Tue Jul 4 13:08:04 PDT 2006


Terence,

I to would like to know which attributes are needed in a given template.
Either by catching exception messages or by getting  a list of "used"
attributes in the list. I kind of though that Attributes property would
contain those, but found out that this collection is populated after the
SetAttribute method calls.

So, for now, I am using the block pasted below. Is there a better way to
achieve this? (I hope I am missing something :)). Good work though, thanks!
(I am using the C# version)

  Miha.

code to get all the required properties:

            StringTemplate st = new StringTemplate("I like $colour$ colour
and $temperature$ beer.");

            foreach (object o in st.Chunks) {
                if (o.GetType().ToString() == "
Antlr.StringTemplate.Language.ASTExpr") {
                    // do something with the attribute
                    st.SetAttribute(o.ToString().Trim(), "[value]");
                    // or
                    requiredAttributes.Add(o.ToString().Trim());
                }
            }

Terence wrote:
>On Mar 28, 2006, at 12:59 PM, David Moshal wrote:

>> Ter - I think the question was a little different. In actual use,
>> the system doesn't complain if you set an attribute which
>> doesn't exist, which becomes very hard to debug. One needs to look
>> at the generated code.

>Oh!  Right, Yes, that is a very big problem!  You are right. the
>problem is, how do you know what the complete set of attributes is?

>Ter
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org:8080/pipermail/stringtemplate-interest/attachments/20060704/1b016f4a/attachment.html


More information about the stringtemplate-interest mailing list