petitparser2 icon indicating copy to clipboard operation
petitparser2 copied to clipboard

Cannot run on Zinc streams

Open jecisc opened this issue 4 years ago • 5 comments

In the doc it is written that PP now works on stream. I tried to parse a file but it failed. I suppose it is because file stream implementation of Pharo changed to use Zinc now.

ZnCharacterReadStream(Object)>>doesNotUnderstand: #asPetit2Stream
Message>>sentTo:
ZnCharacterReadStream(Object)>>doesNotUnderstand: #asPetit2Stream
PP2ActionNode(PP2Node)>>parseAdaptable:
PP2ActionNode(PP2Node)>>parseContext:
PP2ActionNode(PP2Node)>>parse:

jecisc avatar Mar 16 '20 11:03 jecisc

This should definitely work, I will look into this asap.

kursjan avatar Mar 17 '20 08:03 kursjan

Indeed, there is no extension for ZnCharacaterStream. But you can build your own stream on top of ZincStream:

| byteStream stream |
byteStream := ZnClient new
	url: 'http://pharo.org';
	streaming: true;
	get.
stream := PP2CharacterStream on: byteStream encoder: ZnUTF8Encoder new.

^ PP2HtmlHeaderGrammar new optimize parse: stream

See PP2HtmlHeader class>>example

kursjan avatar Mar 17 '20 09:03 kursjan

Which version of Pharo are you using? It seems there is an implementation of asPetit2Stream in Pharo 6.1:

ZnCharacterReadStream>>asPetit2Stream
	^ PP2BufferStream on: self

As a workaround, consider creating your own PP2BufferStream on ZnCharacterReadStream by simply wrapping to PP2BufferStream.

kursjan avatar Mar 17 '20 09:03 kursjan

I also improved the documentation of PP2 related streams in https://github.com/kursjan/petitparser2/commit/1e20acad0febb34a798e9ac44404a83d300b17c9

kursjan avatar Mar 17 '20 09:03 kursjan

I am on Pharo 8.

In the end I cannot use this feature but I was repporting it in case you want to add syntactic suggar.

jecisc avatar Mar 17 '20 11:03 jecisc