lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


I am writing a parser for a very simple configuration language. I know
that LPEG is designed for this purpose, but since it is a very simple
language, I would like to use the lua patterns only (please, do not
judge me :) ).

I have a working parser that acts on a single string, but now I would
like to extend it to get the input splitted among several chunks,
without waiting for the whole data unless it is necessary.

We consider, for example, the pattern
^{%a+}
to match against the following input:
{foobar}
We suppose it is splitted in two chunks right in the middle.

On the first chunk the match fails. But it may match if I wait for
another chunk. How I can check for this? [1]

Obviously I can use another pattern. In the example, on a fail I can
just check ^[^{] to know if I need another chunk. But in this way,
each pattern in the application should be treated separately.

Is there a generic way to solve this issue? For example, if the lua
API exposed the point where the matching stops on failure, I could
easly know if I need to wait for another chunk. But that information
is not avaiable (I think)...

pocomane.
Ciao.

[1] And, just to be clear, I want to immediately stop the parsing in
other cases, e.g. when matchin against:
fo}obar