Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[incubator-kie-drools-5982] [new-parser] Enable alternative attribute… #5983

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1970,9 +1970,8 @@ public void parse_Timer() throws Exception {
assertThat(at.getValue()).isEqualTo("true");
}

@Disabled("Priority : Low | Not written in docs nor other unit tests. Drop the support?")
@Test
public void parse_Attributes_alternateSyntax() throws Exception {
public void parse_Attributes_alternateSyntax() {
final RuleDescr rule = parseAndGetFirstRuleDescrFromFile(
"rule_attributes_alt.drl" );
assertThat(rule.getName()).isEqualTo("simple_rule");
Expand All @@ -1981,27 +1980,27 @@ public void parse_Attributes_alternateSyntax() throws Exception {
final Map<String, AttributeDescr> attrs = rule.getAttributes();
assertThat(attrs.size()).isEqualTo(6);

AttributeDescr at = (AttributeDescr) attrs.get( "salience" );
AttributeDescr at = attrs.get( "salience" );
assertThat(at.getName()).isEqualTo("salience");
assertThat(at.getValue()).isEqualTo("42");

at = (AttributeDescr) attrs.get( "agenda-group" );
at = attrs.get( "agenda-group" );
assertThat(at.getName()).isEqualTo("agenda-group");
assertThat(at.getValue()).isEqualTo("my_group");

at = (AttributeDescr) attrs.get( "no-loop" );
at = attrs.get( "no-loop" );
assertThat(at.getName()).isEqualTo("no-loop");
assertThat(at.getValue()).isEqualTo("true");

at = (AttributeDescr) attrs.get( "lock-on-active" );
at = attrs.get( "lock-on-active" );
assertThat(at.getName()).isEqualTo("lock-on-active");
assertThat(at.getValue()).isEqualTo("true");

at = (AttributeDescr) attrs.get( "duration" );
at = attrs.get( "duration" );
assertThat(at.getName()).isEqualTo("duration");
assertThat(at.getValue()).isEqualTo("42");

at = (AttributeDescr) attrs.get( "activation-group" );
at = attrs.get( "activation-group" );
assertThat(at.getName()).isEqualTo("activation-group");
assertThat(at.getValue()).isEqualTo("my_activation_group");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ drlKeywords returns [Token token]
| DRL_EVAL
| DRL_FORALL
| DRL_OVER
| DRL_ATTRIBUTES
| DRL_SALIENCE
| DRL_ENABLED
| DRL_NO_LOOP
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ DRL_STARTED_BY : 'startedby';
DRL_WINDOW : 'window';

// attributes
DRL_ATTRIBUTES : 'attributes';
DRL_SALIENCE : 'salience';
DRL_ENABLED : 'enabled';
DRL_NO_LOOP : 'no-loop';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -440,13 +440,14 @@ drlAnnotation
: {boolean buildState = buildDescr; buildDescr = true;} anno=fullAnnotation[null] {buildDescr = buildState;} // either standard Java annotation
| AT name=drlQualifiedName (LPAREN chunk RPAREN)? ; // or support @watch(!*, age) etc.

attributes : attribute ( COMMA? attribute )* ;
attribute : name=( 'salience' | 'enabled' ) conditionalAttributeValue #expressionAttribute
| name=( 'no-loop' | 'auto-focus' | 'lock-on-active' | 'refract' | 'direct' ) BOOL_LITERAL? #booleanAttribute
| name=( 'agenda-group' | 'activation-group' | 'ruleflow-group' | 'date-effective' | 'date-expires' | 'dialect' ) DRL_STRING_LITERAL #stringAttribute
| name='calendars' DRL_STRING_LITERAL ( COMMA DRL_STRING_LITERAL )* #stringListAttribute
| name='timer' ( DECIMAL_LITERAL | LPAREN chunk RPAREN ) #intOrChunkAttribute
| name='duration' ( DECIMAL_LITERAL | LPAREN chunk RPAREN ) #intOrChunkAttribute
// attributes := (ATTRIBUTES COLON?)? [ attribute ( COMMA? attribute )* ]
attributes : (DRL_ATTRIBUTES COLON?)? attribute ( COMMA? attribute )* ;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR just allows attributes: label before attributes

rule simple_rule
    attributes:
        salience 42, agenda-group "my_group", no-loop,  lock-on-active, duration 42, activation-group "my_activation_group"
    when

attribute : name=( DRL_SALIENCE | DRL_ENABLED ) conditionalAttributeValue #expressionAttribute
| name=( DRL_NO_LOOP | DRL_AUTO_FOCUS | DRL_LOCK_ON_ACTIVE | DRL_REFRACT | DRL_DIRECT ) BOOL_LITERAL? #booleanAttribute
| name=( DRL_AGENDA_GROUP | DRL_ACTIVATION_GROUP | DRL_RULEFLOW_GROUP | DRL_DATE_EFFECTIVE | DRL_DATE_EXPIRES | DRL_DIALECT ) DRL_STRING_LITERAL #stringAttribute
| name=DRL_CALENDARS DRL_STRING_LITERAL ( COMMA DRL_STRING_LITERAL )* #stringListAttribute
| name=DRL_TIMER ( DECIMAL_LITERAL | LPAREN chunk RPAREN ) #intOrChunkAttribute
| name=DRL_DURATION ( DECIMAL_LITERAL | LPAREN chunk RPAREN ) #intOrChunkAttribute
;

conditionalAttributeValue : ( LPAREN conditionalExpression RPAREN | conditionalExpression ) ;
Expand Down
Loading