[antlr-interest] Post: Grammars and StringTemplates‏

Claudia Navarro Gonzalez navarro_clau56 at yahoo.com.mx
Fri Mar 20 03:33:18 PDT 2009


Dear Antlr-Interest,

I'm
looking for orientation and help on String Templates and Grammars. I'll
try to give you some description of my problem, hope you can help me...

My
project is to use grammars and templates to generate a DocBook template
output and I have some questions about it. I'm new in using ANTLR and
StringTemplates, but I already made a lot of reading and examples, so
I'm already familiarized with the concept and the ANTLRWorks tool. 

The
thing I need to do is to create a DocBookTemplate.stg, based on the
Creole10.g, but I have a hard time thinking on how to do that. I
understand that for every rule in a grammar there will be a template,
as describe in the example of chapter 9 in the book "The Definitive
ANTLR Reference". 

(this is the example)
s    :    ID '=' INT ';' -> assign(x={$ID.text},y={$INT.text});

The
examples given in your book, are very simple for the project I'm
developing. My idea was to ask you for some help and orientation in
more complex examples. Like in the grammar of Creole10.g from Riehle,
we have several rules to create different stuff. As a first step, I
tried to start with the LIST section and wanted to output some DocBook
List tags such as:

<itemizedlist mark='opencircle'>
<listitem><para>Claudia</para>
<para>Leticia</para>
<para>Linda</para>
<para>Susy</para>
<para>Cecy</para>
<para>Adriana</para>
</listitem>
</itemizedlist>

I have my .stg file:

group list;

list(listContent) ::= <<
\<itemizedlist mark='opencircle'>
<listItem(listContent=listContent)>
\</item izedlist>
>>

listItem(listContent) ::= <<
\<listitem><listContent:{l|\<para><l>\</para><\n>}>\</listitem>
>>

This .stg will work in Java.

public static void CreateList() throws IOException 
    {
   
    final FileReader readerSuper = new FileReader("C:\\Documents and
Settings\\Admin\\My
Documents\\WORK\\Examples\\CreoleAttributes-ST\\List.stg");
        StringTemplateGroup groupFileSuper = new StringTemplateGroup(readerSuper);
        r eaderSuper.close();
        
        final StringTemplate template = groupFileSuper.getInstanceOf("list");
        
        ArrayList<String> myList = new ArrayList<String>();
        myList.add("Claudia");
        myList.add("Leticia");
         myList.add("Linda");
        myList.add("Susy");
        myList.add("Cecy");
        myList.add("Adriana");
        
        template.setAttribute("listContent", myList);
        System.out.println(template.toString());
&nbs p;       
    }


But
I want to integrate it into the grammar "Creole10.g" like in the
examples given in your book, but I'm a little bit lost, on how to do it.

http://www.riehle.org/wp-content/uploads/2008/01/creole10_with_extension.g
/////////////////////////////////   L I S T   /////////////////////////////////

list_ord
	:	( list_ordelem )+  ( end_of_list )?
	;
list_ordelem
	:	list_ordelem_markup  list_elem
	;
list_unord
	:	( list_unordelem )+  ( end_of_list )?
	;
list_unordelem
	:	list_unordelem_markup  list_elem
	;
list_elem
	:	( list_elem_markup )*  list_elemcontent  list_elemseparator
	;
list_elem_markup
	:	list_ordelem_markup
	|	list_unordelem_markup
	;
list_elemcontent
	:	onestar  ( list_elemcontentpart  onestar )*
	;
list_elemcontentpart
	:	text_unformattedelement
	|	list_formatted_elem
	;
list_formatted_elem
	:	bold_markup  onestar  ( list_boldcontentpart  onestar )*
		( bold_markup )?
	|	ital_markup  onestar  ( list_italcontentpart  onestar )*
		( ital_markup )?
	;
list_boldcontentpart
	:	ital_markup  list_boldita
 lcontent  ( ital_markup )?
	|	( text_unformattedelement )+
	;
list_italcontentpart
	:	bold_markup  list_bolditalcontent  ( bold_markup )?
	|	( text_unformattedelement )+
	;
list_bolditalcontent
	:	( text_unformattedelement )+
	;

Perhaps I am on the wrong track
 , hope you could give a hint on how to begin creating my templates based on Creole10.g.
Or is there any other book, you recommend that I could read, and which contains more complex examples??

Any help will be appreciated, since I'm a little bit stuck... =S

Thanks in advance!!!!

Claudia Navarro Glz


__________________________________________________
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ¡gratis! 
Regístrate ya - http://correo.yahoo.com.mx/ 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20090320/1471341b/attachment.html 


More information about the antlr-interest mailing list