[antlr-interest] Confused about type of edges attribute in stg files

Niemeijer, R.A. r.a.niemeijer at tue.nl
Thu Sep 4 08:05:02 PDT 2008


Hello everyone,

 

In the stg files in the org\antlr\codegen\templates\your_language folder
there are two functions where NoViableAltExceptions are generated:
dfaState and sfaStateSwitch. Both of these have an edges attribute,
which contain the if/switch statements that precede the
NoViableAltException. What I want to do (see also the "How to get a list
of all valid options for the next token?" discussion) is to get a list
of the numbers in those statements.

My approach of including <edges> in @" " (C#'s syntax for a string
literal) and applying a regular expression to it works for simple cases,
but if two of these sections are nested C# chokes on the nested quotes.
So I need to preprocess the edges variable somehow.

>From what I've been able to find it's not possible to use programming
code inside a stringtemplate, so something like
edges.toString().replace(...) is impossible (if it is possible I'd love
to hear how). So that leaves me with using the properties and such that
stringtemplate allows. To do this I need to know what type it is though.


According to the code in ACyclicDFACodeGenerator.java in
org\antlr\codegen its type should be StringTemplate, because of

dfaST.setAttribute("edges", edgeST);

and

StringTemplate edgeST = templates.getInstanceOf(dfaEdgeName);

 

However, if I put for instance <edges.version> in the stg file and try
to compile my grammar file with AntlrWorks I get an error that
STAttributeList doesn't have that property. Ok, apparently edges is an
STAttributeList (though how that follows from a StringTemplate is still
a mystery to me), which inherits from ArrayList, so I can access the
elements in edges with something like <edges:{e|<e>}>. But then what
type are the elements in edge?

 

So can anyone tell me the type of the elements in edges (or how to use a
replace/regex function on attributes in stg files)?

 

Thanks in advance.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080904/114b0961/attachment.html 


More information about the antlr-interest mailing list