Quantcast

Getting text when using TestNot

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

Getting text when using TestNot

manish.in.java
I am trying to write a parser for the following grammar:


Markup     <- ((Text)?(Expression)?(Text)?)*
Expression <- '##'Block'##'
Text         <- !Expression

Given the following snippet:

        Rule Expression() {
                return Sequence(String("##"), Block(), String("##"));
        }

        Rule Text() {
                return Sequence(TestNot(Expression()), push(new TextNode(match())));
        }

I find that TextNode contains blank string ("").  I know this is because TestNot does not actually match any characters, thereby leading to match() returning "".  In this case, I need the text (that is not an expression).

Is there a way to get the text for TextNode?
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Getting text when using TestNot

tsuckow

Try moving the match outside of the sequence and consume any one char after the test not. Oh, you will also need to put the sequence in a one or more.

I don't think that will give too much of a performance hit since usually pound will not be present.

Sort of odd grammar though.

On May 16, 2013 7:21 AM, "manish.in.java [via parboiled users]" <[hidden email]> wrote:
I am trying to write a parser for the following grammar:


Markup     <- ((Text)?(Expression)?(Text)?)*
Expression <- '##'Block'##'
Text         <- !Expression

Given the following snippet:

        Rule Expression() {
                return Sequence(String("##"), Block(), String("##"));
        }

        Rule Text() {
                return Sequence(TestNot(Expression()), push(new TextNode(match())));
        }

I find that TextNode contains blank string ("").  I know this is because TestNot does not actually match any characters, thereby leading to match() returning "".  In this case, I need the text (that is not an expression).

Is there a way to get the text for TextNode?


If you reply to this email, your message will be added to the discussion below:
http://users.parboiled.org/Getting-text-when-using-TestNot-tp4024197.html
To start a new topic under parboiled users, email [hidden email]
To unsubscribe from parboiled users, click here.
NAML
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Getting text when using TestNot

manish.in.java
Hi Thomas

Thanks for your reply.  It has solved the problem I was facing but introduced a new one.  For our application, I am trying to create a simple markup language that detects certain patterns in user messages and converts them into HTML links.

A user message can contain zero or more expressions of interest, each expression looks like:

    ##post:<post ID>:<post label>:(<post title>)##


Please consider the examples below:


    ##post:12345:Learning Scala##

should get translated to:

    Learning Scala


    ##post:12345:Learning Scala:Scala##

should get translated to:

    Learning Scala


    Hi Tom, I wanted to let you know that these days I am ##post:12345:Learning Scala##.

should get translated to:

    Hi Tom, I wanted to let you know that these days I am Learning Scala.


    Hi Tom, I wanted to let you know that these days I am Learning Scala.

should remain:

    Hi Tom, I wanted to let you know that these days I am Learning Scala.


    Hi Tom, I wanted to let you know that these days I am ##post:12345:Learning Scala##.  I also wanted to draw your attention to the excellent ##post:67890:Scalate framework##.

should get translated to:

    Hi Tom, I wanted to let you know that these days I am Learning Scala.  I also wanted to draw your attention to the excellent Scalate framework.


Hence, the grammar in my original post.

For this, I have created a Parser and a Processor class, as shown in the Gist https://gist.github.com/manish-in-java/5596882.

Before I made the change suggested by you, I was getting the MarkupNode correctly in the MarkupProcessor.process() method.  After making the change, MarkupParser is somehow returning null.  The only change made is localized to the MarkupParser.Text() method.

Any suggestions on diagnosing and fixing the problem will be appreciated.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Getting text when using TestNot

tsuckow
This is really really delayed and I hope you already figured it out.

From looking through it, I don't see the issue. If it is successfully
processing the input then it SHOULD be making a MarkupNode.

I use parboiled Scala and find the Java one to be suicide.
Thomas Suckow


On Thu, May 16, 2013 at 9:28 PM, manish.in.java [via parboiled users]
<[hidden email]> wrote:

> Hi Thomas
>
> Thanks for your reply.  It has solved the problem I was facing but
> introduced a new one.  For our application, I am trying to create a simple
> markup language that detects certain patterns in user messages and converts
> them into HTML links.
>
> A user message can contain zero or more expressions of interest, each
> expression looks like:
>
>     ##post:<post ID>:<post label>:(<post title>)##
>
>
> Please consider the examples below:
>
>
>     ##post:12345:Learning Scala##
>
> should get translated to:
>
>     Learning Scala
>
>
>     ##post:12345:Learning Scala:Scala##
>
> should get translated to:
>
>     Learning Scala
>
>
>     Hi Tom, I wanted to let you know that these days I am
> ##post:12345:Learning Scala##.
>
> should get translated to:
>
>     Hi Tom, I wanted to let you know that these days I am Learning Scala.
>
>
>     Hi Tom, I wanted to let you know that these days I am Learning Scala.
>
> should remain:
>
>     Hi Tom, I wanted to let you know that these days I am Learning Scala.
>
>
>     Hi Tom, I wanted to let you know that these days I am
> ##post:12345:Learning Scala##.  I also wanted to draw your attention to the
> excellent ##post:67890:Scalate framework##.
>
> should get translated to:
>
>     Hi Tom, I wanted to let you know that these days I am Learning Scala.  I
> also wanted to draw your attention to the excellent Scalate framework.
>
>
> Hence, the grammar in my original post.
>
> For this, I have created a Parser and a Processor class, as shown in the
> Gist https://gist.github.com/manish-in-java/5596882.
>
> Before I made the change suggested by you, I was getting the MarkupNode
> correctly in the MarkupProcessor.process() method.  After making the change,
> MarkupParser is somehow returning null.  The only change made is localized
> to the MarkupParser.Text() method.
>
> Any suggestions on diagnosing and fixing the problem will be appreciated.
>
> ________________________________
> If you reply to this email, your message will be added to the discussion
> below:
> http://users.parboiled.org/Getting-text-when-using-TestNot-tp4024197p4024199.html
> To start a new topic under parboiled users, email
> [hidden email]
> To unsubscribe from parboiled users, click here.
> NAML
Loading...