Loading ...
Sorry, an error occurred while loading the content.

Re: [antlr-interest] missing loop

Expand Messages
  • Sinan
    ... [...] ... I d expect the rule should read: non-empty list required then list ... END_BRACK! ; empty list allowed then list ... (WS!)*)*)? END_BRACK! ; rule
    Message 1 of 4 , Feb 6, 2001
    • 0 Attachment
      Edison Enterprises Inc wrote:
      >
      > All:
      >
      > Prolog language uses lists that look like "[1, 2, 3 | a]". To parse
      [...]
      > list
      > {cat.debug("Entering list");}
      > : START_BRACK!
      >
      > options {greedy=true;} : (WS!)*
      > term
      > ( options {greedy=true;} :
      > (WS!)* COMMA! (WS!)* term
      > )*
      > ( options {greedy=true;} : list_tail )?
      ^^^^^^^^^^^^^^^^^^^^^^^^^^what is this?
      > )?
      > (WS!)* // Parser does not loop here!
      > END_BRACK!
      > {
      > #list = #([LIST, "LIST"], #list);
      > cat.debug("Leaving list: "+#list.toStringList());
      > }
      > ;

      I'd expect the rule should read:

      non-empty list required then

      list
      : START_BRACK! (WS!)* term (WS!)* (COMMA! (WS!)* term (WS!)*)*
      END_BRACK!
      ;

      empty list allowed then

      list
      : START_BRACK! (WS!)* ((term)=>term (WS!)* (COMMA! (WS!)* term
      (WS!)*)*)? END_BRACK!
      ;

      rule of thumb:

      always consume (WS)* as the last part of an optional clause, that way
      the follow has no WS ambiguity.

      Sinan
    Your message has been successfully submitted and would be delivered to recipients shortly.