Here's my set of ANTLR grammars for the ANTLR tool itself. :)

Sam

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Hendrik Maryns
Sent: Wednesday, November 26, 2008 7:53 AM
To: [EMAIL PROTECTED]
Subject: Re: [antlr-interest] ANTLR Source Formatting

Edgar Espina schreef:
> Hi all,
> 
> I would like to include a source formatter in ANTLR IDE.
> 
> Can anyone suggest a default format?

Since nobody of the more experienced people here has answered, let me present 
what I have come up with in my short history with ANTLR:

/**
 * There are 6 kinds of formulas.
 */
body returns [Formula result]
        : labelFormula
                { $result = $labelFormula.result; }
        | atomic
                { $result = $atomic.result; }
        | unary
                { $result = $unary.result; }
        | binary
                { $result = $binary.result; }
        | n_ary
                { $result = $n_ary.result; }
        | quantor
                { $result = $quantor.result; }
        ;

That is: the rulename and returns statement on one line, the colon on the next, 
then each alternative on its own line with the pipes aligned to the colon.  
Code blocks in a separate line, with an additional indent.  (This will not 
always be possible, see below.)  Then the semicolon aligned with the colon and 
pipes on its own line.  I use tabs for indentation because I like them, there 
should of course be an option to use spaces.

n_aryArguments returns [List<Formula> result] @init{ $result = new 
ArrayList<Formula>(); }
        : ( WHITESPACE arg=formula { $result.add(arg); } )+
        ;

@init and other such stuff on a separate line, without indentation.
Here you see that it is difficult to put code blocks on a separate line, since 
it is inside the ()+.  You could however do

        : (
            WHITESPACE arg=formula
                 { $result.add(arg); }
          )+
        ;

for consistency.

Another one with parens:

equality returns [Formula result]
        : EQUALITY WHITESPACE
                  ( firstfirst=firstOrderVariable WHITESPACE 
secondfirst=firstOrderVariable
                        { $result = new FirstOrderEquality($firstfirst.result,
$secondfirst.result); } )
                | ( firstsecond=secondOrderVariable WHITESPACE 
secondsecond=secondOrderVariable
                        { $result = new SecondOrderEquality($firstsecond.result,
$secondsecond.result); } )
        ;

Note the parens are aligned, the pipe is before it.  Maybe here it would make 
sense to have the parens on their own line as well.

And of course all of this should be configurable, similar to the Java 
formatter.  Have fun :-)

Cheers, H.
--
Hendrik Maryns
http://tcl.sfs.uni-tuebingen.de/~hendrik/
==================
Ask smart questions, get good answers:
http://www.catb.org/~esr/faqs/smart-questions.html


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en
-~----------~----~----~----~------~----~------~--~---

Attachment: Grammars.7z
Description: Grammars.7z

List: http://www.antlr.org:8080/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org:8080/mailman/options/antlr-interest/your-email-address

Reply via email to