[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Lua 5.2 - How do I resume an interrupted parse?
- From: Pierre-Yves Gérardy <pygy79@...>
- Date: Thu, 2 Feb 2012 15:23:56 +0100
The Lua 5.2 reference for lua_Reader talks about the reader's behaviour in terms of 'chunks'
I've been talking in this thread about a reader that streams data to the parser
... it's not aware of a 'chunk'. In other words I'm not doing the reader correctly.
My context and restrictions are:
- The lua_Reader is serialising discontiguous data for the parser
- The discontiguities are block-ish, 1-byte to say the size of a TCP segment
- reallocations and mem copies should be avoided if at all possible
- single OS thread (Integrity RTOS)
Honestly, patching the parser appears to be the easiest solution. The only way to tell where a statement starts and where it ends is to parse the source. At the moment, the only existing Lua 5.2 parser that I know of is lparser.c, in the Lua sources.
Don't be afraid, the source is very clean, and easy to read and modify.
A first step would be to replace the `statlist(*L)` call in `luaY_parser(...)` with a call to `statement(*L)`, so that the parser returns after one statement instead of one chunk.
I'm not familiar with the reader side of things, nor how to detect where the parser stopped reading the stream, but it should be easier to figure it out (or to add the functionality) than to re-implement a full parser in the reader...