set index and offset of result tokens in llk driver

This commit is contained in:
Sven M. Hallberg 2013-06-04 21:59:39 +02:00
parent dba9d41eda
commit 3be83c7fa2

View file

@ -339,10 +339,12 @@ HParseResult *h_llk_parse(HAllocator* mm__, const HParser* parser, HInputStream*
// the top of stack is such that there will be a result... // the top of stack is such that there will be a result...
HParsedToken *tok; // will hold result token HParsedToken *tok; // will hold result token
tok = h_arena_malloc(arena, sizeof(HParsedToken));
tok->index = stream->index;
tok->bit_offset = stream->bit_offset;
if(x == mark) { if(x == mark) {
// hit stack frame boundary... // hit stack frame boundary...
// wrap the accumulated parse result, this sequence is finished // wrap the accumulated parse result, this sequence is finished
tok = h_arena_malloc(arena, sizeof(HParsedToken));
tok->token_type = TT_SEQUENCE; tok->token_type = TT_SEQUENCE;
tok->seq = seq; tok->seq = seq;
@ -361,13 +363,13 @@ HParseResult *h_llk_parse(HAllocator* mm__, const HParser* parser, HInputStream*
case HCF_END: case HCF_END:
if(!stream->overrun) if(!stream->overrun)
goto no_parse; goto no_parse;
h_arena_free(arena, tok);
tok = NULL; tok = NULL;
break; break;
case HCF_CHAR: case HCF_CHAR:
if(input != x->chr) if(input != x->chr)
goto no_parse; goto no_parse;
tok = h_arena_malloc(arena, sizeof(HParsedToken));
tok->token_type = TT_UINT; tok->token_type = TT_UINT;
tok->uint = x->chr; tok->uint = x->chr;
break; break;
@ -377,7 +379,6 @@ HParseResult *h_llk_parse(HAllocator* mm__, const HParser* parser, HInputStream*
goto no_parse; goto no_parse;
if(!charset_isset(x->charset, input)) if(!charset_isset(x->charset, input))
goto no_parse; goto no_parse;
tok = h_arena_malloc(arena, sizeof(HParsedToken));
tok->token_type = TT_UINT; tok->token_type = TT_UINT;
tok->uint = input; tok->uint = input;
break; break;
@ -390,8 +391,6 @@ HParseResult *h_llk_parse(HAllocator* mm__, const HParser* parser, HInputStream*
// 'tok' has been parsed; process it // 'tok' has been parsed; process it
// XXX set tok->index and tok->bit_offset (don't take directly from stream, cuz peek!)
// perform token reshape if indicated // perform token reshape if indicated
if(x->reshape) if(x->reshape)
tok = (HParsedToken *)x->reshape(make_result(arena, tok)); tok = (HParsedToken *)x->reshape(make_result(arena, tok));