Problem with quotes

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

Problem with quotes

kojadin
Hi,

I defined rule like this:
Rule Number() {
        return OneOrMore(CharRange('0', '9'));
    }

When I try to use it on this example(input="\"098\""):

String input =  "\"098\"";
MakeParser parser = Parboiled.createParser(MakeParser.class);
ParsingResult<?> result = new RecoveringParseRunner(parser.Number()).run(input);

System.out.println(input + " = " + result.parseTreeRoot.getValue() + '\n');
System.out.println(printNodeTree(result) + '\n');

For this I got good result.
[Number]E '098'
  [0..9] '0'

But next example give me null pointer exception(input="098").
//test Number
input =  "098";
parser = Parboiled.createParser(MakeParser.class);
result = new RecoveringParseRunner(parser.Number()).run(input);

System.out.println(input + " = " + result.parseTreeRoot.getValue() + '\n');//null pointer exception
System.out.println(printNodeTree(result) + '\n');

Is this good behavior?

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

Re: Problem with quotes

mathias
Administrator
The reason you are seeing an NPE in the second case is that in this case the input is _valid_.
When the input is error free the RecoveringParseRunner only creates a parse tree if the parser class carries a @BuildParseTree annotation.

In the first case the input is invalid (contains parse errors).
In these cases the RecoveringParseRunner automatically creates a ParseTree to hold the input corrections.

However, this behavior recently changed... what parboiled version are you running?
Also, do you really need the RecoveringParseRunner?

Cheers,
Mathias

---
[hidden email]
http://www.parboiled.org

On 01.06.2011, at 14:21, kojadin [via parboiled users] wrote:

> Hi,
>
> I defined rule like this:
> Rule Number() {
>         return OneOrMore(CharRange('0', '9'));
>     }
>
> When I try to use it on this example(input="\"098\""):
>
> String input =  "\"098\"";
> MakeParser parser = Parboiled.createParser(MakeParser.class);
> ParsingResult<?> result = new RecoveringParseRunner(parser.Number()).run(input);
>
> System.out.println(input + " = " + result.parseTreeRoot.getValue() + '\n');
> System.out.println(printNodeTree(result) + '\n');
>
> For this I got good result.
> [Number]E '098'
>   [0..9] '0'
>
> But next example give me null pointer exception(input="098").
> //test Number
> input =  "098";
> parser = Parboiled.createParser(MakeParser.class);
> result = new RecoveringParseRunner(parser.Number()).run(input);
>
> System.out.println(input + " = " + result.parseTreeRoot.getValue() + '\n');//null pointer exception
> System.out.println(printNodeTree(result) + '\n');
>
> Is this good behavior?
>
>
>
> If you reply to this email, your message will be added to the discussion below:
> http://users.parboiled.org/Problem-with-quotes-tp3010461p3010461.html
> To start a new topic under parboiled users, email [hidden email]
> To unsubscribe from parboiled users, click here.

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

Re: Problem with quotes

kojadin
Thanks for fast replay.
How I can crate something like: [^']+
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Problem with quotes

mathias
Administrator
oneOrMore(testNot('\''), ANY)

---
[hidden email]
http://www.parboiled.org

On 01.06.2011, at 18:50, kojadin [via parboiled users] wrote:

> Thanks for fast replay.
> How I can crate something like: [^']+
>
> If you reply to this email, your message will be added to the discussion below:
> http://users.parboiled.org/Problem-with-quotes-tp3010461p3011666.html
> To start a new topic under parboiled users, email [hidden email]
> To unsubscribe from parboiled users, click here.

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

Re: Problem with quotes

kojadin
One more question for example from here:
https://github.com/sirthias/parboiled/wiki/Simple-Java-Example

When I run it I get empty string for 'parseTreePrintOut'.

How can I get matched values?
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Problem with quotes

mathias
Administrator
Have you decorated your parser class with @BuildParseTree?

---
[hidden email]
http://www.parboiled.org

On 01.06.2011, at 21:13, kojadin [via parboiled users] wrote:

> One more question for example from here:
> https://github.com/sirthias/parboiled/wiki/Simple-Java-Example
>
> When I run it I get empty string for 'parseTreePrintOut'.
>
> How can I get matched values?
>
> If you reply to this email, your message will be added to the discussion below:
> http://users.parboiled.org/Problem-with-quotes-tp3010461p3012229.html
> To start a new topic under parboiled users, email [hidden email]
> To unsubscribe from parboiled users, click here.


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

Re: Problem with quotes

kojadin
Oh, I skipped that.
Thanks, it work now.
Loading...