[antlr-interest] Re: CLI with ANTLR - best practice

idontwantanidwith2000init idontwantanidwith2000init at yahoo.com
Fri Apr 9 15:31:12 PDT 2004


about multiple lines,
I would have want the following to work:
addIssueDescription "bla bla blablablablablabla bla bla blabla bla 
blablablablablablablablablabla"

that is a token might be spread on two lines 
I don't think your example will answer to it

To handle multiple lines I would use a  such as
protected
PNEWLINE:  
       '\r' '\n'   // DOS
   |  '\r'        // Macintosh
   |  '\n'       // UNIX
   ;
NEWLINE:PNEWLINE 
{
   if (!flag) {
     $setType(Token.SKIP);
     //here should be printing of a newline maybe newline();
   }
};

the flag should be set after a command is parsed
and unset after newline is met.



--- In antlr-interest at yahoogroups.com, "thierryj8" <thierryj8 at y...> 
wrote:
> I tried the (command NEWLINE)+ and it worked as long as there was 
no
> error.
> 
> Also, since the RETURN does not mean the end of file, I naturally 
had
> commands that could spawn in several lines:
> 
> >list *
> Processing list
> 
> Same as
> >list
> >*
> Processing list
> 
> After thinking further, it seemed that each line should be it's own
> file (thinking of a java paser), and the / to continue a line 
should
> be handled as a special case.
> 
> I would like feedback on this format (probably not best practice, 
but
> it seems to work so far).
> 
> The java main looks like:
> 
>   public static void main(String[] args)
>   {
>     try
>     {
>       ConsoleLexer consoleLexer = new ConsoleLexer(new
> DataInputStream(System.in));
>       ConsoleParser consoleParser = new ConsoleParser
(consoleLexer);
>       
>       boolean parserException = false;
>       while (parserException == false) // Each line is considered a
> full file
>       {
>         try
>         {
>           System.out.print(consoleLexer.getMode() + ">");
>   			  consoleParser.parse_prompt_command();
>         }
>         catch (Exception e)
>         {
>           parserException = true; // Exception caught in .g
>         }
>       }
>     }
>     catch (Exception e)
>     {
>       System.err.println("main exception: " + e); // really bad 
exception
>     }
>   }
> 
> And the paser command looks like:
> command
>   : (cmd1 | ... | cmd)
>     exception
>     catch [RecognitionException ex]
>     {
>       System.out.println("command exception " + ex.getMessage());
>     }
>   ;
> 
> Then new line is made an EOF type:
> 
> NEWLINE
>   :  '\r' '\n'   // DOS
>   |  '\r'        // Macintosh
>   |  '\n'       // UNIX
>   {
>     $setType(Token.EOF_TYPE);
>   }



 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
     http://groups.yahoo.com/group/antlr-interest/

<*> To unsubscribe from this group, send an email to:
     antlr-interest-unsubscribe at yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
     http://docs.yahoo.com/info/terms/
 



More information about the antlr-interest mailing list