move last_chunk flag into HInputStream
This commit is contained in:
parent
28fa93d4cc
commit
d4f933b2d3
3 changed files with 14 additions and 9 deletions
|
|
@ -298,7 +298,7 @@ static HLLkState *llk_parse_start_(HAllocator* mm__, const HParser* parser)
|
||||||
|
|
||||||
// returns partial result or NULL
|
// returns partial result or NULL
|
||||||
static HCountedArray *llk_parse_chunk_(HLLkState *s, const HParser* parser,
|
static HCountedArray *llk_parse_chunk_(HLLkState *s, const HParser* parser,
|
||||||
HInputStream* stream, bool last_chunk)
|
HInputStream* stream)
|
||||||
{
|
{
|
||||||
HParsedToken *tok = NULL; // will hold result token
|
HParsedToken *tok = NULL; // will hold result token
|
||||||
HCFChoice *x = NULL; // current symbol (from top of stack)
|
HCFChoice *x = NULL; // current symbol (from top of stack)
|
||||||
|
|
@ -373,7 +373,7 @@ static HCountedArray *llk_parse_chunk_(HLLkState *s, const HParser* parser,
|
||||||
case HCF_END:
|
case HCF_END:
|
||||||
if(!stream->overrun)
|
if(!stream->overrun)
|
||||||
goto no_parse;
|
goto no_parse;
|
||||||
if(!last_chunk)
|
if(!stream->last_chunk)
|
||||||
goto need_input;
|
goto need_input;
|
||||||
h_arena_free(arena, tok);
|
h_arena_free(arena, tok);
|
||||||
tok = NULL;
|
tok = NULL;
|
||||||
|
|
@ -431,7 +431,7 @@ static HCountedArray *llk_parse_chunk_(HLLkState *s, const HParser* parser,
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
need_input:
|
need_input:
|
||||||
if(last_chunk)
|
if(stream->last_chunk)
|
||||||
goto no_parse;
|
goto no_parse;
|
||||||
h_arena_free(arena, tok); // no result, yet
|
h_arena_free(arena, tok); // no result, yet
|
||||||
h_slist_push(stack, x); // try this symbol again next time
|
h_slist_push(stack, x); // try this symbol again next time
|
||||||
|
|
@ -456,7 +456,8 @@ HParseResult *h_llk_parse(HAllocator* mm__, const HParser* parser, HInputStream*
|
||||||
{
|
{
|
||||||
HLLkState *s = llk_parse_start_(mm__, parser);
|
HLLkState *s = llk_parse_start_(mm__, parser);
|
||||||
|
|
||||||
s->seq = llk_parse_chunk_(s, parser, stream, true /* last chunk */);
|
assert(stream->last_chunk);
|
||||||
|
s->seq = llk_parse_chunk_(s, parser, stream);
|
||||||
|
|
||||||
return llk_parse_finish_(mm__, s);
|
return llk_parse_finish_(mm__, s);
|
||||||
}
|
}
|
||||||
|
|
@ -470,7 +471,7 @@ void h_llk_parse_chunk(HSuspendedParser *s, HInputStream *input)
|
||||||
{
|
{
|
||||||
HLLkState *state = s->backend_state;
|
HLLkState *state = s->backend_state;
|
||||||
|
|
||||||
state->seq = llk_parse_chunk_(state, s->parser, input, false);
|
state->seq = llk_parse_chunk_(state, s->parser, input);
|
||||||
}
|
}
|
||||||
|
|
||||||
HParseResult *h_llk_parse_finish(HSuspendedParser *s)
|
HParseResult *h_llk_parse_finish(HSuspendedParser *s)
|
||||||
|
|
@ -482,11 +483,12 @@ HParseResult *h_llk_parse_finish(HSuspendedParser *s)
|
||||||
.overrun = 0,
|
.overrun = 0,
|
||||||
.endianness = s->endianness,
|
.endianness = s->endianness,
|
||||||
.length = 0,
|
.length = 0,
|
||||||
.input = NULL
|
.input = NULL,
|
||||||
|
.last_chunk = true
|
||||||
};
|
};
|
||||||
|
|
||||||
// signal end of input (no-op parse already done)
|
// signal end of input (no-op parse already done)
|
||||||
state->seq = llk_parse_chunk_(state, s->parser, &empty, true);
|
state->seq = llk_parse_chunk_(state, s->parser, &empty);
|
||||||
|
|
||||||
return llk_parse_finish_(s->mm__, s->backend_state);
|
return llk_parse_finish_(s->mm__, s->backend_state);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -56,7 +56,8 @@ HParseResult* h_parse__m(HAllocator* mm__, const HParser* parser, const uint8_t*
|
||||||
.overrun = 0,
|
.overrun = 0,
|
||||||
.endianness = DEFAULT_ENDIANNESS,
|
.endianness = DEFAULT_ENDIANNESS,
|
||||||
.length = length,
|
.length = length,
|
||||||
.input = input
|
.input = input,
|
||||||
|
.last_chunk = true
|
||||||
};
|
};
|
||||||
|
|
||||||
return backends[parser->backend]->parse(mm__, parser, &input_stream);
|
return backends[parser->backend]->parse(mm__, parser, &input_stream);
|
||||||
|
|
@ -132,7 +133,8 @@ bool h_parse_chunk(HSuspendedParser* s, const uint8_t* input, size_t length) {
|
||||||
.overrun = 0,
|
.overrun = 0,
|
||||||
.endianness = s->endianness,
|
.endianness = s->endianness,
|
||||||
.length = length,
|
.length = length,
|
||||||
.input = input
|
.input = input,
|
||||||
|
.last_chunk = false
|
||||||
};
|
};
|
||||||
|
|
||||||
// process chunk
|
// process chunk
|
||||||
|
|
|
||||||
|
|
@ -79,6 +79,7 @@ typedef struct HInputStream_ {
|
||||||
// towards that should be ignored.
|
// towards that should be ignored.
|
||||||
char endianness;
|
char endianness;
|
||||||
bool overrun;
|
bool overrun;
|
||||||
|
bool last_chunk;
|
||||||
} HInputStream;
|
} HInputStream;
|
||||||
|
|
||||||
typedef struct HSlistNode_ {
|
typedef struct HSlistNode_ {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue