[antlr-interest] newbie needs help to define parser grammar

Mikael Petterson mikael.petterson at ericsson.com
Mon Aug 4 23:37:47 PDT 2008


Hi,
 
I tried the following grammar:
 
rror returns [ClearCaseElementState el]
 : {int exceptionCode = 0;}
   {boolean throwException = false;}
 'cleartool: Error:' ('Entry' 'named' elem=STRING 'already' 'exists.'
{throwException = true; exceptionCode |= ClearCase.ERROR_ALREADY_ADDED;}
 | 'Element' elem=STRING 'has' 'checkouts.' {throwException = true;
exceptionCode |= ClearCase.ERROR_ALREADY_CHECKED_OUT;}
 | 'Element' elem=STRING 'is' 'already' 'checked' 'out' 'to' 'view'
STRING DOT {el = new ClearCaseElementState($elem.text,
ClearCase.IS_ELEMENT | ClearCase.ERROR_ALREADY_CHECKED_OUT);}
 | 'Can\u0027t' 'modify' 'directory' elem=STRING 'because' 'it' 'is'
'not' 'checked' 'out.' {throwException = true; exceptionCode |=
ClearCase.ERROR_DIR_IS_NOT_CHECKED_OUT;}
 | 'Unable' 'to' 'access' elem=STRING ':' 'No' 'such' 'file' 'or'
'directory.' {throwException = true; exceptionCode |=
ClearCase.ERROR_NOT_ACCESSIBLE;}
 | 'By' 'default' COMMA 'won\u0027t' 'create' 'version' 'with' 'data'
'identical' 'to' 'predecessor.' NEWLINE 'cleartool: Error:' 'Unable'
'to' 'check' 'in' elem=STRING DOT  {throwException = true; exceptionCode
|= ClearCase.ERROR_PREDECESSOR_IS_IDENTICAL;}
 | (LITERAL | STRING | DOT)+)
 {if (throwException) throw new ClearCaseException(exceptionCode, new
String[]{$elem.text}, null);};
 
 
I get the following error:
 
BR.recoverFromMismatchedToken

line 2:28 mismatched input 'check' expecting 'check'

I cannot quite figure out what is meant.

 

Any ideas?

cheers,

//mikael


________________________________

From: antlr-interest-bounces at antlr.org
[mailto:antlr-interest-bounces at antlr.org] On Behalf Of Mikael Petterson
Sent: den 5 augusti 2008 07:48
To: antlr-interest
Subject: [antlr-interest] newbie needs help to define parser grammar



Hi, 

In my grammar file I have the following parser for handling error
messages from versioning tool ( clearcase). 

error returns [ClearCaseElementState el] 
        : {int exceptionCode = 0;} 
          {boolean throwException = false;} 
        'cleartool: Error:' ('Entry' 'named' elem=STRING 'already'
'exists.' {throwException = true; exceptionCode |=
ClearCase.ERROR_ALREADY_ADDED;}

        | 'Element' elem=STRING 'has' 'checkouts.' {throwException =
true; exceptionCode |= ClearCase.ERROR_ALREADY_CHECKED_OUT;}

        | 'Element' elem=STRING 'is' 'already' 'checked' 'out' 'to'
'view' STRING DOT {el = new ClearCaseElementState($elem.text,
ClearCase.IS_ELEMENT | ClearCase.ERROR_ALREADY_CHECKED_OUT);}

        | 'Can\u0027t' 'modify' 'directory' elem=STRING 'because' 'it'
'is' 'not' 'checked' 'out.' {throwException = true; exceptionCode |=
ClearCase.ERROR_DIR_IS_NOT_CHECKED_OUT;}

        | 'Unable' 'to' 'access' elem=STRING ':' 'No' 'such' 'file' 'or'
'directory.' {throwException = true; exceptionCode |=
ClearCase.ERROR_NOT_ACCESSIBLE;}

        | 'By' 'default' COMMA 'won\u0027t' 'create' 'version' 'with'
'data' 'identical' 'to' 'predecessor.'{throwException = true;
exceptionCode |= ClearCase.ERROR_PREDECESSOR_IS_IDENTICAL;}

        | (LITERAL | STRING | DOT)+) 
        {if (throwException) throw new ClearCaseException(exceptionCode,
new String[]{$elem.text}, null);}; 


The output from clearcase that I need to parse is: 

"cleartool: Error: By default, won't create version with data identical
to predecessor.\r\n"+ 
                                                "cleartool: Error:
Unable to check in
\"M:\\eraonel_testa\\mbv_admin\\testarea\\productsample\\com\\sample\\pr
oduct\\ProductC.java\".\r\n");

As it it is now I am missing parsing of the second line and element name
in the String [] becomes null. 

I cannot only parse the second line since there could be numerous
reasons for unable to check in. So I need help on how to parse both
lines ( as a unit) and then throw the expection).

Any ideas on how I can solve this? 

cheers, 

//mike 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080805/406dcb53/attachment-0001.html 


More information about the antlr-interest mailing list