Rule seems to match overly often

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

Rule seems to match overly often

mr. s
Hi fellow parboilers,


I just got started with parboiled and I'm seeing some weird behaviour that I hope someone can shine some light on.

I have a rule that matches a simple pattern. That rule has some sub-rules but nothing too fancy.
Currently - just for testing - i have an action at the end that simply prints the match().

Now when I run my Rule on a String that matches the pattern exactly I see that my rule seems to be matched 3 times as I see 3 lines on stdout.

There are some other Rules in Play but I'm providing an exact match for one rule and it seems to be executed 3 times.

Oddly enough I have another action after the one that prints the match() which pushes an object onto the stack. In the stack there is only 1 object after the run. So it prints 3 times but only seems to push 1 time.

Can anyone explain this behaviour to me ?

greeting
fge
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Rule seems to match overly often

fge
mr. s wrote
Hi fellow parboilers,


I just got started with parboiled and I'm seeing some weird behaviour that I hope someone can shine some light on.

I have a rule that matches a simple pattern. That rule has some sub-rules but nothing too fancy.
Currently - just for testing - i have an action at the end that simply prints the match().

Now when I run my Rule on a String that matches the pattern exactly I see that my rule seems to be matched 3 times as I see 3 lines on stdout.

There are some other Rules in Play but I'm providing an exact match for one rule and it seems to be executed 3 times.

Oddly enough I have another action after the one that prints the match() which pushes an object onto the stack. In the stack there is only 1 object after the run. So it prints 3 times but only seems to push 1 time.

Can anyone explain this behaviour to me ?

greeting
You don't give your grammar so it is difficult to answer you.

Note: I am the maintainer of grappa, which is a fork of parboiled since parboiled proper is now unmaintained, so you may want to give this one a go, and especially to the debugger which can trace a parser run for you (see grappa-tracer-backport; note that since the latter depends on grappa 1.0.x you can have this as a dependency instead of parboiled and you'll have the tracer collector for "free").
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Rule seems to match overly often

mr. s
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 seems to match overly often

fge
mr. s wrote
Thank you for your rapid response. I may give grappa a go when I find the time.
For now here is the Rule I'm talking about:

Rule NormParaAbsatz() {

                Var<String> ordnungszeichen = new Var<String>();
                Var<Integer> einzelvorschrift = new Var<Integer>(0);
                Var<Integer> jurabsatz = new Var<Integer>(0);
                Var<String> norm = new Var<String>();

                return Sequence(
                                Sequence(
                                                Sequence(Norm(), norm.set(match())),
                                                Optional(Ch(':')),
                                                Optional(OneOrMore(WhiteSpace())),
[...]
First things first: instead of optional(oneOrMore(whiteSpace())) you can just use zeroOrMore(whiteSpace()) (and yeah, in grappa, all rules begin with a lower case letter; what is more you have ws() at your disposal).

Try and run the tracer on your grammar and give the debugger a go, it will probably help you point out where the problem is. As it is, I can't really tell what's wrong without an input text; but with a trace file I may tell more, and so can you ;)
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Rule seems to match overly often

mr. s
I'll switch to grappa then, as soon as I'm able to.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Rule seems to match overly often

mr. s
Ist there anyway to install grappa without using maven ?
For parboiled i just downloaded the jars and put them into my Build Path.
fge
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Rule seems to match overly often

fge
mr. s wrote
Ist there anyway to install grappa without using maven ?
For parboiled i just downloaded the jars and put them into my Build Path.
Well, you can download the jar from bintray here:

https://bintray.com/fge/maven/grappa/view

Unfortunately however I don't provide a "full" jar. You'll therefore have to download dependencies individually; here is the list:

    compile(group: "org.ow2.asm", name: "asm-debug-all", version: "5.0.3");
    compile(group: "com.google.guava", name: "guava", version: "18.0");
    compile(group: "me.qmx.jitescript", name: "jitescript", version: "0.4.0");

But you should be using gradle, not maven, really ;)
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Rule seems to match overly often

mr. s
[quote]
Well, you can download the jar from bintray here:

https://bintray.com/fge/maven/grappa/view

Unfortunately however I don't provide a "full" jar. You'll therefore have to download dependencies individually; here is the list:

    compile(group: "org.ow2.asm", name: "asm-debug-all", version: "5.0.3");
    compile(group: "com.google.guava", name: "guava", version: "18.0");
    compile(group: "me.qmx.jitescript", name: "jitescript", version: "0.4.0");

But you should be using gradle, not maven, really ;)
[/quote]

Thanks a lot for that.
Unfrotunately I get:
Exception in thread "main" java.lang.NoClassDefFoundError: org/objectweb/asm/tree/AbstractInsnNode

I have asm5 in my buildpath though.

Any ideas ?
fge
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Rule seems to match overly often

fge
mr. s wrote
Thanks a lot for that.
Unfrotunately I get:
Exception in thread "main" java.lang.NoClassDefFoundError: org/objectweb/asm/tree/AbstractInsnNode

I have asm5 in my buildpath though.

Any ideas ?
Well, I doubt that you have, really, since those are all the depedencies (this is the result of ./gradlew dependencies):

compile - Compile classpath for source set 'main'.
+--- org.ow2.asm:asm-debug-all:5.0.3
+--- com.google.guava:guava:18.0
+--- me.qmx.jitescript:jitescript:0.4.0


I don't know what your build system is etc but AbstractInsnNode is in asm-debug-all...
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Rule seems to match overly often

mr. s
[quote]
Well, I doubt that you have, really, since those are all the depedencies (this is the result of ./gradlew dependencies):

compile - Compile classpath for source set 'main'.
+--- org.ow2.asm:asm-debug-all:5.0.3
+--- com.google.guava:guava:18.0
+--- me.qmx.jitescript:jitescript:0.4.0


I don't know what your build system is etc but AbstractInsnNode is in asm-debug-all...
[/quote]

Right. I downlaoded asm instead of asm-debug-all. Silly me. Now it works :) Thank you !
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Rule seems to match overly often

mr. s
Okay so here is my trace.
The rule that seemingly matches too often is PraAbsatzNorm.

The debugger seems very usefull but I can't make much of it as I'm still pretty new to grappa.

Help would be much appreciated.

http://wikisend.com/download/553030/trace.zip
fge
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Rule seems to match overly often

fge
mr. s wrote
Okay so here is my trace.
The rule that seemingly matches too often is PraAbsatzNorm.

The debugger seems very usefull but I can't make much of it as I'm still pretty new to grappa.

Help would be much appreciated.

http://wikisend.com/download/553030/trace.zip
The trace without the grammar itself will not really help pinpoint the problem ;)

If you want you can join channel #grappa on FreeNode, I lurk in there (nickname idletask), we can then see about analyzing your grammar itself.

Cheers!
Loading...