Soren Holstebroe wrote:
> Thank you for your answer,
> 
> As i understand it, your suggestion considers the whole template line as a
> single token, but I don't want the template token to eat up the rest of the
> line, since this is where my template wrapping grammar would be.
> 
> My grammar will have rules like this:
> 
> wrap_option
>     : WRAP_OPTION_BEGIN
>     (  'WRAP'
>     | 'TEMPLATE' '<' type_specifier (',' type_specifier)* '>'
>     )
>     ;
> 
> so I need something to match '//' WS* '@' as my WRAP_OPTION_BEGIN.

The tricky part here is that the parser should ideally report an error
if the template line does not end with a newline, but newline would
normally be a hidden token. Here's a possible solution (untested):


@lexer::members {
  private int newlineChannel = HIDDEN;
}

fragment WRAP_OPTION_BEGIN : ;

SLCOMMENT
  : '//' WS? ( '@' { $type = WRAP_OPTION_BEGIN;
                     newlineChannel = DEFAULT_CHANNEL; }
             | ( ~('@' | '\r' | '\n' | ' ' | '\t') (~('\r' | '\n'))* )? EOL
                   { $channel = HIDDEN; }
             )
  ;

NEWLINE
  : ('\r' '\n'? | '\n')
      { $channel = newlineChannel;
        newlineChannel = HIDDEN; }
  ;

fragment EOL
  : NEWLINE
  // allow single-line comment without newline at end of file
  | { input.LA(1) == EOF }?
  ;

WS : (' ' | '\t')+ { $channel = HIDDEN; } ;

// parser

wrap_option
  : WRAP_OPTION_BEGIN
  ( 'WRAP'
  | 'TEMPLATE' '<' type_specifier (',' type_specifier)* '>'
  )
  NEWLINE
  ;

-- 
David-Sarah Hopwood  ⚥  http://davidsarah.livejournal.com


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

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to