[antlr-interest] end of file

Robin Debreuil robin at debreuil.com
Sun Jul 11 20:41:03 PDT 2004


I was at one point tempted to just add a newline to the source ; ). Eventually making the last newline (optional)? worked, but iirc that required adding newlines elsewhere. The code below may or may not be a helpful reference...

Cheers,
Robin


protected
NEW_LINE
 : ( // carriage return character followed by possible line feed character 
   { LA(2)=='\u000A' }? '\u000D' '\u000A'   
  | '\u000D'   // line feed character       
  | '\u000A'   // line feed character       
  | '\u2028'   // line separator character
  | '\u2029'   // paragraph separator character
  )
  {newline();}
 ;
 
protected
NEW_LINE_CHARACTER
 : ('\u000D' | '\u000A' | '\u2028' | '\u2029')
 ;
 
protected
NOT_NEW_LINE
 : ~( '\u000D' | '\u000A' | '\u2028' | '\u2029')
 ; 
 
// ***** A.1.2 WHITESPACE *****
WHITESPACE
 : ( ' '
  | '\u0009' // horizontal tab character
  | '\u000B' // vertical tab character
  | '\u000C' // form feed character 
  | NEW_LINE 
  )+
  { _ttype = Token.SKIP; }
 ;  
 
// ***** A.1.3 COMMENTS *****
SINGLE_LINE_COMMENT
 : "//" 
  (NOT_NEW_LINE)* 
  (NEW_LINE)? // may be eof
  {_ttype = Token.SKIP;}
 ;

 DELIMITED_COMMENT
 : "/*"  
  ( { LA(2)!='/' }? '*'
  | NEW_LINE  
  | ~('*'|'\u000D'|'\u000A'|'\u2028'|'\u2029')
  )*
  "*/"
  { _ttype = Token.SKIP; }
 ; 
  ----- Original Message ----- 
  From: clocKwize 
  To: antlr-interest at yahoogroups.com 
  Sent: Sunday, July 11, 2004 5:56 PM
  Subject: [antlr-interest] end of file


  Hi there, I'm trying to implement single line comments, which is fine, I use:

   

  SL_COMMENT: "//" (~EOL)* EOL;

   

  protected

  EOL:                 '\n' | '\r' | ('\r' '\n') | ('\n' '\r');

   

  Which works for me - but then, what if there is no EOL, what if there is a single line comment on the last line of the file, how can I add that kind of thing into my grammar?

   

   

  Thanks.

   

  Mike

   



------------------------------------------------------------------------------
  Yahoo! Groups Links

    a.. To visit your group on the web, go to:
    http://groups.yahoo.com/group/antlr-interest/
      
    b.. To unsubscribe from this group, send an email to:
    antlr-interest-unsubscribe at yahoogroups.com
      
    c.. Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service. 


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20040711/366b1508/attachment.html


More information about the antlr-interest mailing list