PetitParser ignorable parsers

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

PetitParser ignorable parsers

Peter Uhnak
Hi,

is it possible to add such a parser that would consume input, but wouldn't return anything?

Right now I do things like...

MyParser>>rule
    ^ ($[ asParser, anotherRule, $] asParser) ==> [ :nodes | nodes second ]

Of course when the rules are more complex, so is the block; however it seems that this is how it's done in the example parsers...

So, would it be possible to add some kind of Null/Void/Ignore/Throwaway parser, that would consume the input, but would be omitted from the result?

so the above method could be written as

MyParser>>rule
    ^ $[ asNullPaser, anotherRule, $] asNullParser

or

MyParser>>rule
    ^ $[ asParser ignore, anotherRule, $[ asParser ignore

or something else.

Thanks,
Peter

_______________________________________________
Moose-dev mailing list
[hidden email]
https://www.iam.unibe.ch/mailman/listinfo/moose-dev
Reply | Threaded
Open this post in threaded view
|

Re: PetitParser ignorable parsers

Nicolas Anquetil

not sure what is the probleme exactly.

if you don't put any semantic action "==> [....]"

then the parser does not produce anything, no?

nicolas


On 22/06/2015 10:42, Peter Uhnák wrote:
Hi,

is it possible to add such a parser that would consume input, but wouldn't return anything?

Right now I do things like...

MyParser>>rule
    ^ ($[ asParser, anotherRule, $] asParser) ==> [ :nodes | nodes second ]

Of course when the rules are more complex, so is the block; however it seems that this is how it's done in the example parsers...

So, would it be possible to add some kind of Null/Void/Ignore/Throwaway parser, that would consume the input, but would be omitted from the result?

so the above method could be written as

MyParser>>rule
    ^ $[ asNullPaser, anotherRule, $] asNullParser

or

MyParser>>rule
    ^ $[ asParser ignore, anotherRule, $[ asParser ignore

or something else.

Thanks,
Peter


_______________________________________________
Moose-dev mailing list
[hidden email]
https://www.iam.unibe.ch/mailman/listinfo/moose-dev


_______________________________________________
Moose-dev mailing list
[hidden email]
https://www.iam.unibe.ch/mailman/listinfo/moose-dev
Reply | Threaded
Open this post in threaded view
|

Re: PetitParser ignorable parsers

Peter Uhnak
The problem is, that in syntax there are often many symbols that are no longer needed once the string is parsed so I want to get rid of them.

For example imagine a string representation of an JSON array:

'[ 1, 2, 3 ]'

Once the string is parsed, the brackets are no longer needed so I can get rid of them with a block

MyJsonParser>>array
    ^ ($[ asParser, arrayElements, $] asParser) ==> [ :nodes | nodes second ]

This way the result of the array will not contain those $[ $] symbols because I am not interested in them after the parsing.

So, I would prefer to explicitly state that I am not interested in certain parser after it has done its job.

MyJsonParser>>array
    ^ $[ asParser ignore, arrayElements, $] asParser ignore

(or the other alternative mentioned in the first post)

Is what I am trying to accomplish clearer?

Peter

_______________________________________________
Moose-dev mailing list
[hidden email]
https://www.iam.unibe.ch/mailman/listinfo/moose-dev
Reply | Threaded
Open this post in threaded view
|

Re: PetitParser ignorable parsers

Jan Kurš
Hey, you can achieve your goal by extending the petit parser API as follows;

PPParser>>nullParser
   " transforms whatever result to null "
    ^ self ==> [:e | NullResult instance ]

PPParser>>ignoreNulls
   " removes NullResults from result "
   ^ self ==> [:e | e isCollection
         ifTrue: [ e reject: [ :item | item isNullResult ]
         ifFalse: [ e ] ]

Cheers,
Jan

On Mon, Jun 22, 2015 at 1:27 PM Peter Uhnák <[hidden email]> wrote:
The problem is, that in syntax there are often many symbols that are no longer needed once the string is parsed so I want to get rid of them.

For example imagine a string representation of an JSON array:

'[ 1, 2, 3 ]'

Once the string is parsed, the brackets are no longer needed so I can get rid of them with a block

MyJsonParser>>array
    ^ ($[ asParser, arrayElements, $] asParser) ==> [ :nodes | nodes second ]

This way the result of the array will not contain those $[ $] symbols because I am not interested in them after the parsing.

So, I would prefer to explicitly state that I am not interested in certain parser after it has done its job.

MyJsonParser>>array
    ^ $[ asParser ignore, arrayElements, $] asParser ignore

(or the other alternative mentioned in the first post)

Is what I am trying to accomplish clearer?

Peter
_______________________________________________
Moose-dev mailing list
[hidden email]
https://www.iam.unibe.ch/mailman/listinfo/moose-dev

_______________________________________________
Moose-dev mailing list
[hidden email]
https://www.iam.unibe.ch/mailman/listinfo/moose-dev