public ImportDescr importStatement(PackageDescrBuilder pkg) throws RecognitionException {
try {
String kwd;
if (helper.validateLT(2, kwd = DroolsSoftKeywords.ACC) ||
helper.validateLT(2, kwd = DroolsSoftKeywords.ACCUMULATE)) {
AccumulateImportDescrBuilder imp = helper.start(pkg,
AccumulateImportDescrBuilder.class,
null);
try {
// import
match(input,
DRL6Lexer.ID,
DroolsSoftKeywords.IMPORT,
null,
DroolsEditorType.KEYWORD);
if (state.failed)
return null;
// import accumulate
match(input,
DRL6Lexer.ID,
kwd,
null,
DroolsEditorType.KEYWORD);
if (state.failed)
return null;
// qualifiedIdentifier
String target = qualifiedIdentifier();
if (state.failed)
return null;
// function name
Token id = match(input,
DRL6Lexer.ID,
null,
null,
DroolsEditorType.IDENTIFIER);
if (state.failed)
return null;
if (state.backtracking == 0) {
imp.target(target).functionName(id.getText());
}
return (imp != null) ? imp.getDescr() : null;
} finally {
helper.end(AccumulateImportDescrBuilder.class,
imp);
}
} else {
ImportDescrBuilder imp = helper.start(pkg,
ImportDescrBuilder.class,
null);
try {
// import
match(input,
DRL6Lexer.ID,
DroolsSoftKeywords.IMPORT,
null,
DroolsEditorType.KEYWORD);
if (state.failed)
return null;
if (helper.validateIdentifierKey(kwd = DroolsSoftKeywords.FUNCTION) ||
helper.validateIdentifierKey(kwd = DroolsSoftKeywords.STATIC)) {
// function
match(input,
DRL6Lexer.ID,
kwd,
null,
DroolsEditorType.KEYWORD);
if (state.failed)
return null;
}
// qualifiedIdentifier
String target = qualifiedIdentifier();
if (state.failed)
return null;
if (input.LA(1) == DRL6Lexer.DOT && input.LA(2) == DRL6Lexer.STAR) {
// .*
match(input,
DRL6Lexer.DOT,
null,
null,
DroolsEditorType.IDENTIFIER);
if (state.failed)
return null;
match(input,
DRL6Lexer.STAR,
null,
null,
DroolsEditorType.IDENTIFIER);
if (state.failed)
return null;
target += ".*";
}
if (state.backtracking == 0)
imp.target(target);
return (imp != null) ? imp.getDescr() : null;
} finally {
helper.end(ImportDescrBuilder.class,
imp);
}
}