【问题标题】:Drools rules in xtext formatxtext 格式的 Drools 规则
【发布时间】:2020-07-29 15:54:36
【问题描述】:

我是 Xtext 的新手,我想用它来为 drools 规则生成一些代码。我有以下问题,我不知道如何编写方言以在 Order() 前面加上 $order。如果有人能告诉我如何处理这个例子,我将不胜感激。

这是我迄今为止尝试过的

Model:
    declarations+=Declaration*;
    
Declaration:
    Rule;

State:
    name=ID
;


    Rule:
        'rule' ruleDescription=STRING
        '@specification'specificationDescription=STRING
        'ruleflow-group' ruleflowDescription=STRING
            'when' when=[State|QualifiedName]
            'then' then=[State|QualifiedName];
    
    QualifiedName: ID ('.' ID)*;
    DolarSign: ('$' ID)*;
    

这里是规则的代码:

    rule "apply 10% discount to all items over US$ 100,00 in an order"
    @specification "101"
    ruleflow-group "All"
    when
        $order : Order(appliedBefore == null)
                 Order($name : /customer/name) from $order
        $item  : OrderItem( value > 100 ) from $order.items
    then
        System.out.println("10% applied" + $name);
    end

【问题讨论】:

    标签: java drools xtext


    【解决方案1】:

    你应该可以简单地使用:

    'when $' when=[State|QualifiedName]
    

    【讨论】:

    • 不,我不想在 Drools 的 when 块中突出显示“$”。 when 块中也可以有多个变量,例如:when $A :A(..) $B:B(..)
    • 我认为您必须创建一个以“$”开头的自定义终端,并通过其 ID 对 State 进行交叉引用。至于多重性,我猜你将不得不创建一个充当容器的中间规则,有点像这样(很久以来我已经做了一些 Xtext):Rule: (...) 'when' when=WhenStatement* WhenStatement= StateReference ':' WhenStatementBody StateReference: '$' referencedState=[State|QualifiedName] WhenStatementBody: ...
    猜你喜欢
    • 1970-01-01
    • 2015-02-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多