[rules-users] DSL how to define recursive expression

Wolfgang Laun wolfgang.laun at gmail.com
Mon Oct 15 07:56:30 EDT 2012


Converting a left-to-right DSL phrase into a right-to-left Java-style
method call isn't something a regular expression can do, not for the
general (i.e., unlimited) case.

You'll probably require this for a limited number of steps, though.

Untested proposal:
Precede the single step phrase in your DSLR with this double-step:

[keyword][]{attr2:[A-Za-z0-9]+} property of
           {attr1:[A-Za-z0-9]+} property of {obj:[A-Za-z0-9]+}=
    {obj}.get{attr1!ucfirst}().get{attr2!ucfirst}()

and precede it with a three-step phrase, and so on.

And I don't think you need the \s+.

-W

On 15/10/2012, prashantmirajkar at gmail.com <prashantmirajkar at gmail.com> wrote:
> A simple statement like
>
> id of organization
>
> with DSL rule
>
> [keyword][]{attr:[A-Za-z0-9]+}\s+property\s+of\s+{obj:[A-Za-z0-9]+}={obj}.get{attr!ucfirst}()
>
> works just fine with result organization.getId().
>
> If I want to use statements like
>
> id property of organization property of department
>
> which should result in to department.getOrganization().getId().
>
> OR
>
> id property of organization property of department property of employee
>
> which should result in to
> employee.getDepartment().getOrganization().getId().
>
> How do I achieve this?
>
> cheers,
>
> Prashant
>
>
>
> --
> View this message in context:
> http://drools.46999.n3.nabble.com/DSL-how-to-define-recursive-expression-tp4020283.html
> Sent from the Drools: User forum mailing list archive at Nabble.com.
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>


More information about the rules-users mailing list