Open DrMiaow opened 10 years ago
Yeah, looks like Peek isn't implemented on Stream or any of the related classes in the bootstrap library.
(IMO, for text parsing, just load the whole file as a string unless it's enormous. Peek/short reads are pretty expensive/slow)
Some of the stories are heading towards several megabytes of text (Liz is prolific) and the core parser uses SteamReader for design reasons.
I could swap for StringReader to change the granularity of the IO but it sounds like that won't have Peek either?
I'll build a StringStreamReader based on StreamReader which will have the minimal impact.
Actually, checking again ReadLine just reads one character a time since that's how StreamReader works, so I guess it doesn't matter. :-)
FYI, Streams appear to already have a '$PeekByte' method, they just don't have Peek. I think I did that because Peek's semantics are incredibly gross and I didn't feel like implementing them. You can probably implement Peek on top of $PeekByte.
On Fri, Aug 1, 2014 at 6:53 PM, DrMiaow notifications@github.com wrote:
Some of the stories are heading towards several megabytes of text (Liz is prolific) and the core parser uses SteamReader for design reasons.
I could swap for StringReader to change the granularity of the IO but it sounds like that won't have Peek either?
I'll build a StringStreamReader based on StreamReader which will have the minimal impact.
— Reply to this email directly or view it on GitHub https://github.com/sq/JSIL/issues/593#issuecomment-50950901.
Another Saturday morning, another hacking session :)
Managed to progress parsing (still testing) by adding these two to System.IO.StreamReader in JSIL.IO.js
$.Method({Static:false, Public:true }, "Peek",
(new JSIL.MethodSignature($.Int32, [], [])),
function Peek () {
var peeked = this.stream.$PeekByte();
if (peeked === -1)
return peeked;
var position = this.stream.Position;
var ch = $jsilio.ReadCharFromStream(this.stream, this.encoding);
this.stream.Position = position;
if (ch)
return ch.charCodeAt(0);
else
return -1;
}
);
$.Method({Static:false, Public:true }, "Read",
(new JSIL.MethodSignature($.Int32, [], [])),
function Read () {
var ch = $jsilio.ReadCharFromStream(this.stream, this.encoding);
if (ch)
return ch.charCodeAt(0);
else
return -1;
}
);
Looks good. Looking at the logs I have managed to parse the entire file, it's the interpreter now that seems to be falling over somewhere with a weird error.
This one at least seems to be resolved :)
Cool, if you don't mind, submit a PR for Peek and Read and I'll merge them. An automated test wouldn't hurt but I can probably write that myself.
Will do.
I'm in the middle of moving house. Got as far as making a branch but then everything went into a truck. Should have my lab back up and running in a few days.
Error while parsing the .twee file.
I'm assuming I need to implement this following the instructions here?
https://github.com/sq/JSIL/wiki/Troubleshooting-FAQ