[antlr-interest] Solution to " How to have strings enclosed in " and/or ""

matthew ford Matthew.Ford at forward.com.au
Sun Dec 12 00:28:31 PST 2004


Not sure I will try it.
But I have an other problem

The docs say
" Disambiguating predicates are always the first element in a production
because they cannot be hoisted over actions, token, or rule references. For
example, the first production of the following rule has a disambiguating
predicate that would be hoisted into the prediction expression for the first
alternative: "

But the in the following lexer the Disambiguating predicate
 ( (LA(1) == '"')
           || ( (LA(1) == '&')
              && (LA(2) == 'q')
              && (LA(3) == 'u')
              && (LA(4) == 'o')
              && (LA(5) == 't')
              && (LA(6) == ';'))
        ) }?
is not being hoisted to protect access to the rule STRING_PART  or am I
missing some thing


header {
package au.com.forward.webstringtemplate.language;
import java.util.*;
}
class LanguageLexer extends Lexer;


options {
 exportVocab=WEBSTRINGTEMPLATE_LEXER;

 caseSensitiveLiterals=false;
 caseSensitive=false;
   k=2;
 charVocabulary = '\003'..'\377';
  testLiterals=false;
}



UNDEFINED_TOKEN
options {
  paraphrase="MISCELANEOUS_CHARACTERS"; }
 :
  ~('a'..'z'|'_'|'/'|'\\'|':'|'-'|'0'..'9'|'#'|'.'|'"'|']'|'('|')'|'
'|'\t'|'\n'|'\r')
 ;


STRING
options {
    paraphrase="STRING";
}
  :STRING_PART
 (STRING_PART)*
 ;

protected
STRING_PART
 : {  ( (LA(1) == '"')
           || ( (LA(1) == '&')
              && (LA(2) == 'q')
              && (LA(3) == 'u')
              && (LA(4) == 'o')
              && (LA(5) == 't')
              && (LA(6) == ';'))
        ) }?
        ('"'
         | ('&' 'q' 'u' 'o' 't' ';')
        ) (
   options {
    generateAmbigWarnings=false;
   }
  : '\r' '\n'  {newline();}
  | '\r'   {newline();}
  | '\n'   {newline();}
  | ~('\n'|'\r')
        { if ( (LA(1) == '"')
           || ( (LA(1) == '&')
              && (LA(2) == 'q')
              && (LA(3) == 'u')
              && (LA(4) == 'o')
              && (LA(5) == 't')
              && (LA(6) == ';'))
        ) {break;} }
  )*
 ('"' !
    | ('&' ! 'q' ! 'u' ! 'o' ! 't' ! ';' !)
   )
 ;


----- Original Message ----- 
From: "Terence Parr" <parrt at cs.usfca.edu>
To: <antlr-interest at yahoogroups.com>
Sent: Sunday, December 12, 2004 5:14 PM
Subject: Re: [antlr-interest] Solution to " How to have strings enclosed in
" and/or &quot;"


>
>
> On Dec 11, 2004, at 10:08 PM, matthew ford wrote:
> > This is what I came up with which seems to work
> >
> > The interesting bit is
> >   | ~('\n'|'\r')
> >         { if ( (LA(1) == '"') || ( (LA(1) == '&')
> >               && (LA(2) == 'q')
> >               && (LA(3) == 'u')
> >               && (LA(4) == 'o')
> >               && (LA(5) == 't')
> >               && (LA(6) == ';'))
> >         ) {break;} }
> > where the break; is used to break out of antlr' ( )* block
>
> Won't a greedy=false loop do the same thing?
>
> Ter
>
>
>
>
>
>
> Yahoo! Groups Links
>
>
>
>
>
>
>



 
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