Quantcast

Rule returning object for matches

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Rule returning object for matches

newbie
This post was updated on .
CONTENTS DELETED
The author has deleted this message.
fge
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Rule returning object for matches

fge
On Tue, Feb 17, 2015 at 10:09 AM, newbie [via parboiled users]
<[hidden email]> wrote:

> Hi,
>
> So I have a rule that is supposed to return an object with certain
> attributes set that tell me stuff about the pattern that I've matched.
>
> So what i did was to create an object at the very start of the Rule.
> I intended to set the attributed inside my Actions but the problem is that i
> have to make the object final to access it inside my rules which causes it
> to be the same object during the entire runtime. What I want is a new object
> for every match.
>
> code:
>
> Rule ParaAbsatzNorm() {
>
>                 final ResultLinkObject result = new ResultLinkObject();
>
>                 return Sequence(
>                                 Sequence(
>                                                 Sequence(Ordnungszeichen(),
> new Action

Well, those are what `Var`s are for; but you can also use the `ValueStack`.

--
Francis Galiegue, [hidden email], https://github.com/fge
JSON Schema in Java: http://json-schema-validator.herokuapp.com
Parsers in pure Java: https://github.com/fge/grappa
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Rule returning object for matches

newbie
This post was updated on .
>Well, those are what `Var`s are for; but you can also use the `ValueStack`.

Sorry but I don't get what you mean. I also can't access 'Var's inside an action unless they are final.
I need to declary Actions like i do to access context or is there another way ?

I understand what you mean but i don't seem to see how it would work.

/Edit:

Hmm...just saw getContext()...Will try.
fge
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Rule returning object for matches

fge
On Tue, Feb 17, 2015 at 10:50 AM, newbie [via parboiled users]
<[hidden email]> wrote:
>>Well, those are what `Var`s are for; but you can also use the `ValueStack`.
>
> Sorry but I don't get what you mean. I also can't access 'Var's inside an
> action unless they are final.
>

This does not matter; a new frame will be created for each Var within
a rule, which means that between two invocations, your Var will be
"reset" so to speak. Think of it as a "mini stack".

--
Francis Galiegue, [hidden email], https://github.com/fge
JSON Schema in Java: http://json-schema-validator.herokuapp.com
Parsers in pure Java: https://github.com/fge/grappa
Loading...