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

Mikael Petterson mikael.petterson at ericsson.com
Mon Aug 4 22:47:31 PDT 2008


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/7a045458/attachment.html 


More information about the antlr-interest mailing list