Drools 5.4.0- Error with a DSL consequence containinig three captures with combination of integers and strings - dsl

I'm trying to write a DSL for handling messages. I have several constructs working with the below one causing errors -
from the DSL -
[consequence][]on validation failure of field {bit} set field {bit2} to "{field_value}"=System.out.println("Test");
In the DSLR -
on validation failure of field 2 set field 39 to "181"
Strangely enough, the following works OK
from the DSL -
[consequence][]on validation failure of field {bit} set field {bit2} to {field_value}=System.out.println("Test");
In the DSLR -
on validation failure of field 2 set field 39 to 181
(Please note the dropped double quotes on "field_value")
Am I doing something wrong? . I'm using Drools 5.4.0 Final.
Thanks!
Rule Compilation error : [Rule name='handle authorization transactions for validation failures']
defaultpkg/Rule_handle_authorization_transactions_for_validation_failures_bea353bc1d7c4114aa7fb7548bcc7b83.java (21:1344) : on cannot be resolved to a type
defaultpkg/Rule_handle_authorization_transactions_for_validation_failures_bea353bc1d7c4114aa7fb7548bcc7b83.java (21:1358) : Syntax error on token "failure", ; expected
defaultpkg/Rule_handle_authorization_transactions_for_validation_failures_bea353bc1d7c4114aa7fb7548bcc7b83.java (21:1366) : of cannot be resolved to a type
defaultpkg/Rule_handle_authorization_transactions_for_validation_failures_bea353bc1d7c4114aa7fb7548bcc7b83.java (21:1369) : Duplicate local variable field
defaultpkg/Rule_handle_authorization_transactions_for_validation_failures_bea353bc1d7c4114aa7fb7548bcc7b83.java (21:1375) : Syntax error on token "2", ; expected
defaultpkg/Rule_handle_authorization_transactions_for_validation_failures_bea353bc1d7c4114aa7fb7548bcc7b83.java (22:1450) : on cannot be resolved to a type
defaultpkg/Rule_handle_authorization_transactions_for_validation_failures_bea353bc1d7c4114aa7fb7548bcc7b83.java (22:1453) : Duplicate local variable validation
defaultpkg/Rule_handle_authorization_transactions_for_validation_failures_bea353bc1d7c4114aa7fb7548bcc7b83.java (22:1464) : Syntax error on token "failure", ; expected
defaultpkg/Rule_handle_authorization_transactions_for_validation_failures_bea353bc1d7c4114aa7fb7548bcc7b83.java (22:1472) : of cannot be resolved to a type
defaultpkg/Rule_handle_authorization_transactions_for_validation_failures_bea353bc1d7c4114aa7fb7548bcc7b83.java (22:1475) : Duplicate local variable field
defaultpkg/Rule_handle_authorization_transactions_for_validation_failures_bea353bc1d7c4114aa7fb7548bcc7b83.java (22:1481) : Syntax error on token "3", ; expected
defaultpkg/Rule_handle_authorization_transactions_for_validation_failures_bea353bc1d7c4114aa7fb7548bcc7b83.java (23:1556) : on cannot be resolved to a type
defaultpkg/Rule_handle_authorization_transactions_for_validation_failures_bea353bc1d7c4114aa7fb7548bcc7b83.java (23:1559) : Duplicate local variable validation
defaultpkg/Rule_handle_authorization_transactions_for_validation_failures_bea353bc1d7c4114aa7fb7548bcc7b83.java (23:1570) : Syntax error on token "failure", ; expected
defaultpkg/Rule_handle_authorization_transactions_for_validation_failures_bea353bc1d7c4114aa7fb7548bcc7b83.java (23:1578) : of cannot be resolved to a type
defaultpkg/Rule_handle_authorization_transactions_for_validation_failures_bea353bc1d7c4114aa7fb7548bcc7b83.java (23:1581) : Duplicate local variable field
defaultpkg/Rule_handle_authorization_transactions_for_validation_failures_bea353bc1d7c4114aa7fb7548bcc7b83.java (23:1587) : Syntax error on token "4", ; expected

It looks like drools applies rules in a recursive manner!
I had the entry in DSL as
[consequence][]on validation failure of field {bit} set field {second_bit} to "{val}"=...
but there was also another one like this -
[consequence][]set field {bit} to "{field_value}"= ...
so drools matched the last portion of the first entry to the RHS of the second!. Thanks to the drools.dump.dir option and I could see what was happenning!

Related

What is the problem with the following antlr4 grammar

I'm having trouble parsing a simple grammar. I believe the issue is that there are conflicting rules. Here is the text I'm trying to parse:
redis 6.2.6-debian-10-r49 Running
account-migrator 0.83.0 Pending
This represents services that have a name, version and status. Here is the grammar that isn't working:
main : statusLine+;
statusLine : serviceName versionNumber status;
serviceName : SERVICE_NAME;
versionNumber : VERSION_NUMBER;
status : STATUS;
SERVICE_NAME : [a-zA-Z-]+;
VERSION_NUMBER : [a-zA-Z0-9-]+ ('.' [a-zA-Z0-9-]+)*;
STATUS : [a-zA-Z]+;
WS : [ \n\t]+ -> skip;
I believe my grammar confuses the status for a service name because my visitor finds nothing for status on the first visit, but the second visit gets the status of the first line as the service name of the second.
So the question I have is, what can I do to parse these lines correctly?
The problem is that you have multiple rules that match the same input. Everything which STATUS could match, will actually be matched by SERVICE_NAME. Check out this parse tree:
The token STATUS is never produced, but Running became a SERVICE_NAME token.
So, instead of trying to add semantics to the lexer (by using different names, and hence meaning, for the same input) use a common lexer rule:
main : statusLine+;
statusLine : serviceName versionNumber status;
serviceName : IDENTIFIER;
versionNumber : VERSION_NUMBER;
status : IDENTIFIER;
IDENTIFIER: [a-zA-Z-]+;
VERSION_NUMBER: [a-zA-Z0-9-]+ ('.' [a-zA-Z0-9-]+)*;
WHITE_SPACE: [ \u000B\t\r\n] -> skip;
which then gives you the proper parse tree:

Odd ANTLR4 error handling behavior with very simply (trivial) behavior

Given the below super simple grammar:
ddlStatement
: defineStatement
;
defineStatement
: 'define' tableNameToken=Identifier ';'?
;
and the input "add 1 to bob"
I would expect to get an error. However, the parser matches the "defineStatement" rule with a missing "define" token. The following Listener will fire
#Override
public void exitDefineStatement(DDLParser.DefineStatementContext ctx) {
log.info(MessageFormat.format("Defining {0}", ctx.tableNameToken.getText()));
}
and log "Defining add".
I can assign 'define' to a variable and test that variable for NULL but that seems like work I shouldn't have to do.
BTW if the grammar becomes more complete - specifically with the addition of alternatives to the ddlStatement rule - error handling works as I would expect.
This ANTLR's error recovery in action.
In many cases, it's VERY beneficial for ANTLR to assume either a missing token, or ignore a token, if it allows parsing to continue. The missing "define" token should have been reported as an error.
Without this capability, ANTLR would frequently get "stumped" at the first sign of problems. With this, ANTLR is saying "Well, if I assume X, then I can make sense of your input. So I'm assuming X and reporting that as an error so I can continue on.
(Filling a few details to get this to build)
grammar Test
;
ddlStatement: defineStatement;
defineStatement: 'define' tableNameToken = Identifier ';'?;
Identifier: [a-zA-Z]+;
Number: [0-9]+;
WS: [ \r\n\t]+ -> skip;
if I run antlr on this and compile the Java output. The following command:
echo "add 1 to bob" | grun Test ddlStatement -gui
yields the error:
line 1:0 missing 'define' at 'add'
and produces the parse tree:
The highlighted node is the error node in the tree.
The reason it stops after "add" is that input (assuming a missing "define", would be a ddlStatement
ANTLR will stop processing input once it has recognized your stop rule.
To get it to "pay attention" to the entire input, add an EOF token to your start rule:
grammar Test
;
ddlStatement: defineStatement EOF;
defineStatement: 'define' tableNameToken = Identifier ';'?;
Identifier: [a-zA-Z]+;
Number: [0-9]+;
WS: [ \r\n\t]+ -> skip;
gives these errors:
line 1:0 missing 'define' at 'add'
line 1:4 mismatched input '1' expecting {<EOF>, ';'}
and this tree:

Expected string literal in condition express in Jenkins pipeline

I am using ?: to determine the build agent of Jenkins shared library groovy script like this:
def call(String type, Map map) {
if (type == "gradle") {
pipeline {
agent "${map.agent == null}" ? "any" : "${map.agent}"
}
}
}
but it gives me the following error:
org.jenkinsci.plugins.workflow.cps.CpsCompilationErrorsException: startup failed:
/Users/dabaidabai/.jenkins/jobs/soa-robot/builds/154/libs/pipeline-shared-library/vars/ci.groovy: 6: Expected string literal # line 6, column 42.
agent "${map.agent == null}" ? "any" :
^
/Users/dabaidabai/.jenkins/jobs/soa-robot/builds/154/libs/pipeline-shared-library/vars/ci.groovy: 6: Only "agent none", "agent any" or "agent {...}" are allowed. # line 6, column 13.
agent "${map.agent == null}" ? "any" : "${map.agent}"
^
/Users/dabaidabai/.jenkins/jobs/soa-robot/builds/154/libs/pipeline-shared-library/vars/ci.groovy: 6: No agent type specified. Must be one of [any, docker, dockerfile, label, none] # line 6, column 13.
agent "${map.agent == null}" ? "any" : "${map.agent}"
What am I doing wrong?
This error is thrown by the pipeline syntax validator that runs before your pipeline code gets executed. The reason you see this error is the following:
Only "agent none", "agent any" or "agent {...}" are allowed. # line 6, column 13.
This is the constraint for the label section. It means that the following values are valid:
agent any
agent none
agent "constant string value here"
agent { ... }
When you pass something like:
agent "${map.agent ?: 'any'}
agent(map.agent ?: 'any')
you are getting Expected string literal because any form of an expression is not allowed in this place, including interpolated GStrings of any form.
Solution
There is a way to define pipeline agent dynamically however. All you have to do is to use a closure block with the label set to either expression or empty string (an equivalent of agent any in this case.)
pipeline {
agent {
label map.agent ?: ''
}
stages {
...
}
}
The label section allows you to use any expression, so map.agent is a valid construction here. Just remember to use an empty string instead of "any" - otherwise Jenkins will search for a node labeled as "any".
Don't use string replacments everyhwhere:
agent(map.agent==null ? "any" : map.agent)
Or get groovy:
agent(map.agent?:"any")
The actual problem is most likely the "ternary operator" battling against the "parens are maybe optional"-rule.
It seems to me that agent is a method taking a string argument and the way your code is written is ambiguous. Try surrounding the argument expression with parens:
agent(map.agent == null ? "any" : "${map.agent}")
I removed the quotes around map.agent == null as they seemed extraneous.
Also this could probably be rewritten using the groovy "elvis operator" (:?) as:
agent(map.agent ?: "any")
Which essentially means "use map.agent if it has a value, otherwise use 'any'". "If it has a value" is in this context being defined using groovy truth where both empty string and null represent "no value".

Visual Paradigm: Invalid Syntax Highlighting without acutal syntax mistake (as far as I can see)

I think I have encountered an error message that is not necessarily valid or helpful. If it is valid, please tell me what the mistake I encounter is triggered by.
You do not follows UML notation and you exchanged the parameter and its type, your operations must be
create(entity : E) : Result<E>
create(entities : iterable<E>) : ResultCollection<E>
Your create(E : entity) : Result<E> was accepted 'syntactically' because the var can be E and its type entity, but in the second case the var name iterable<E> is illegal and the tool refuses that.
From formal/2017-12-05 §9.6.4 page 117 and 118 :
If shown in a diagram, an Operation is shown as a text string of the form:
[<visibility>] <name> ‘(‘ [<parameter-list>] ‘)’
[‘:’ [<return-type>] [‘[‘ <multiplicity-range> ‘]’]
[‘{‘ <oper-property> [‘,’ <oper-property>]* ‘}’]]
and <parameter-list> is a list of Parameters of the Operation in the following format:
<parameter-list> ::= <parameter> [‘,’<parameter>]*
and § 9.4.4 page 110 :
<parameter> ::= [<direction>] <parameter-name> ’:’ <type-expression>
[’[’<multiplicity-range>’]’] [’=’ <default>]
[’{’ <parm-property> [’,’ <parm-property>]* ’}’]
So it must be <parameter-name> ’:’ <type-expression> rather than <type-expression> ’:’ <parameter-name> as you did

'id' in where clause is ambiguous

I have a table with some fields and some relations with others.
I get the list view with no problem, but when I try to filter the results (using the search feature in flexigrid table) I get:
A Database Error Occurred Error Number:
1052Column 'id' in where clause is ambiguousSELECT
gee_job_boards.*, j32e2cb0f.dp_name AS s32e2cb0f FROM
gee_job_boards LEFT JOIN gee_distribution_partner as j32e2cb0f
ON j32e2cb0f.id = gee_job_boards.dp_id WHERE id LIKE '%27%'
ESCAPE '!' LIMIT 25Filename:
models/Grocery_crud_model.phpLine Number: 87
Error Number: 1052Column 'id' in where clause is
ambiguous
how could i solve this ?
thanks
You should qualify your id in where clause, for example like this
j32e2cb0f.id LIKE ...

Resources