[antlr-interest] Antlr V3 string template creation

Mark Venbrux mark.venbrux at gmail.com
Mon Jun 26 04:29:54 PDT 2006


Antlr Works! ... is wonderful. Would you call this a Domain Specific
Language for creation ... domain specific languages?

Anyway, I created the grammar below as a finger-exercise, and it works. It
was trial and error to get the Stringtemplate screated. So now I wonder: is
this the way to do it, or can it be done in a more elegant, concise way?

==============================================================
grammar RpcIdlParser;

options {
  output=template;
}

rpcinterface : 'interface' name '{' (s+=struct)* (m+=method)* '}'
    -> rpcinterface(name={$name.text}, structs={toTemplates($s)},
methods={toTemplates($m)})
    ;
struct: 'struct' name '{' (v+=variable)+ '}'
    -> struct(name={$name.text}, variables={toTemplates($v)})
    ;
variable: type name ';'
    -> variable(name={$name.text}, type={$type.text})
    ;
parameter: direction type name
    -> parameter(name={$name.text}, direction={$direction.text},
type={$type.text})
    ;
direction: ('in' | 'out' | 'inout')
    ;
method  : name '(' p+=parameter (',' p+=parameter)* ')' ';'
    -> method(name={$name.text}, parameters={toTemplates($p)})
    ;
type    : 'string' | 'int' | ID
        ;
name    : id=ID
    ;

ID    :    ('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'_'|'0'..'9')*
    ;
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20060626/ee6d7bbc/attachment.html


More information about the antlr-interest mailing list