* @return a PackageDescr with the content of the whole compilation unit
*
* @throws RecognitionException
*/
public final PackageDescr compilationUnit() throws RecognitionException {
PackageDescrBuilder pkg = DescrFactory.newPackage();
try {
// package declaration?
if ( input.LA( 1 ) != DRLLexer.EOF && helper.validateIdentifierKey( DroolsSoftKeywords.PACKAGE ) ) {
String pkgName = packageStatement( pkg );
pkg.name( pkgName );
if ( state.failed ) return pkg.getDescr();
}
// statements
while ( input.LA( 1 ) != DRLLexer.EOF ) {
int next = input.index();
if ( helper.validateStatement( 1 ) ) {
statement( pkg );
if ( state.failed ) return pkg.getDescr();
if ( next == input.index() ) {
// no token consumed, so, report problem:
resyncToNextStatement();
}
} else {
resyncToNextStatement();
}
if ( input.LA( 1 ) == DRLLexer.SEMICOLON ) {
match( input,
DRLLexer.SEMICOLON,
null,
null,
DroolsEditorType.SYMBOL );
if ( state.failed ) return pkg.getDescr();
}
}
} catch ( RecognitionException e ) {
helper.reportError( e );
} catch ( Exception e ) {
helper.reportError( e );
} finally {
helper.setEnd( pkg );
}
return pkg.getDescr();
}