[stringtemplate-interest] Syntax problems
Johannes Luber
jaluber at gmx.de
Mon Aug 20 07:02:21 PDT 2007
Hello!
I have the following template file:
group ANTLR3ToRelaxNG;
/** The start template. Call only this template from a program. */
Grammar(Name, StartRule, Elements) ::= <<
# Grammar <Name>
grammar{
start = element <StartRule> { <StartRule>Content }
<Elements:CreateContent(); separator="\n">
}
>>
/** This rule generates the content elements. */
CreateContent(element) ::= <<
<if(element.IsRootElement)>
<element.Name>Content =
<element.Children:CreateContent()>
<endif>
<if(element.IsAndElement)>(<element.Children:CreateContent();
separator=",\n">)<endif>
<if(element.IsOrElement)>(<element.Children:CreateContent();
separator="|\n">)<endif>
<if(element.IsOptionalElement)><element.Children:CreateContent()>?<endif>
<if(element.IsZeroOrMoreElement)><element.Children:CreateContent()>*<endif>
<if(element.IsOneOrMoreElement)><element.Children:CreateContent()>+<endif>
<if(element.IsEmptyElement)><element.Name>Content = empty<endif>
<if(element.IsTextElement)><element.Name>Content = text<endif>
<if(element.IsAnyElement)><element.Name>Content = *<endif>
<if(element.IsLeafElement)>element <element.Name> {
<element.Name>Content }<endif>
>>
While this seems to work in general, I'd like to want some adjustments.
It may be difficult to see, but Children of IsAndElement-s and
IsOrElement-s are always enclosed with parentheses. In general it is
necessary, but I know that calling the CreateContent template from the
Grammar rule has only one direct child and doesn't need the parentheses
there.
My plan was to add an encloseElements parameter to the parameter list of
CreateContent, but I can't get the template calls work correctly with:
<Elements:{e|<CreateContent(e, "false")>}; separator="\n">
Testing the template group with STST (Standalone Sring Template) results in:
"Error: action parse error in group ANTLR3ToRelaxNG line 7; template
context is [Grammar anonymous] at line 1, column 1:
unexpected token: CreateContent
Error: action parse error in group ANTLR3ToRelaxNG line 7; template
context is [Grammar anonymous] at line 1, column 16:
unexpected token: ,
Error: problem parsing template 'anonymous nested in Grammar': null"
How do I write it correctly? For testing purposes I've attached my JSON
file. The object with the name "CompilationUnit" doesn't work correctly,
but if this is a JSON syntax error, I can't find it. :(
Thanks in advance,
Johannes Luber
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test.js
Type: application/x-javascript
Size: 4717 bytes
Desc: not available
Url : http://www.antlr.org:8080/pipermail/stringtemplate-interest/attachments/20070820/95abfc22/attachment.js
More information about the stringtemplate-interest
mailing list