Where is the mistake in this parser? [closed]
I have begun on a PEG parser.
The goal is to build a grammar out of trees of combinators using sequence and either. I have some mistake in my sequence implementation, because I get false
as the output from this instead of an empty stream.
10 | if type (e) = = "string" then |
11 | x = function (n) return n = = e end |
13 | return wrap( function (stream) |
14 | if x( stream:first() ) then |
15 | return stream:rest(), stream:first() |
25 | return wrap( function (stream) |
37 | function wrappedCall(w, ...) |
38 | return w [ "function" ] (...) |
44 | local t = { [ "function" ] = f } |
48 | __call = wrappedCall } ) |
53 | function streamFirst(list) |
58 | function streamRest(list) |
59 | local t = { unpack (list) } |
66 | local s = { unpack (list) } |
05 | return s:sub( 1 , 1 ):lower() ~ = s:sub( 1 , 1 ):upper() |
08 | local name = expect(isLetter) |
09 | local open, close = expect( "<" ), expect( ">" ) |
11 | local void = open * name * close |
12 | local tokens = Stream { "<" , "img" , ">" } |
Does anyone else have an idea of where I made a mistake? I regret not testing more incrementally...