* intOrChunkAttribute := attributeKey (DECIMAL | parenChunk)
* @param key
* @throws RecognitionException
*/
private AttributeDescr intOrChunkAttribute( String[] key ) throws RecognitionException {
AttributeDescrBuilder attribute = null;
try {
StringBuilder builder = new StringBuilder();
for ( String k : key ) {
if ( "-".equals( k ) ) {
match( input,
DRLLexer.MINUS,
k,
null,
DroolsEditorType.KEYWORD ); // part of the keyword
if ( state.failed ) return null;
} else {
match( input,
DRLLexer.ID,
k,
null,
DroolsEditorType.KEYWORD );
if ( state.failed ) return null;
}
builder.append( k );
}
if ( state.backtracking == 0 ) {
attribute = helper.start( AttributeDescrBuilder.class,
builder.toString(),
null );
}
if ( input.LA( 1 ) == DRLLexer.LEFT_PAREN ) {
String value = chunk( DRLLexer.LEFT_PAREN,
DRLLexer.RIGHT_PAREN,
-1 );
if ( state.failed ) return null;
if ( state.backtracking == 0 ) {
attribute.value( safeStripDelimiters( value, "(", ")" ) );
attribute.type( AttributeDescr.Type.EXPRESSION );
}
} else {
String value = "";
if ( input.LA( 1 ) == DRLLexer.PLUS ) {
Token sign = match( input,
DRLLexer.PLUS,
null,
null,
DroolsEditorType.NUMERIC_CONST );
if ( state.failed ) return null;
value += sign.getText();
} else if ( input.LA( 1 ) == DRLLexer.MINUS ) {
Token sign = match( input,
DRLLexer.MINUS,
null,
null,
DroolsEditorType.NUMERIC_CONST );
if ( state.failed ) return null;
value += sign.getText();
}
Token nbr = match( input,
DRLLexer.DECIMAL,
null,
null,
DroolsEditorType.NUMERIC_CONST );
if ( state.failed ) return null;
value += nbr.getText();
if ( state.backtracking == 0 ) {
attribute.value( value );
attribute.type( AttributeDescr.Type.NUMBER );
}
}
} finally {
if ( attribute != null ) {
helper.end( AttributeDescrBuilder.class,
null );
}
}
return attribute != null ? attribute.getDescr() : null;
}