mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
lib/std/encoding: remove use of pushback_byte in json
Signed-off-by: Pierre Curto <pierre.curto@gmail.com>
This commit is contained in:
committed by
Christoffer Lerno
parent
dc7f8057a3
commit
b894e5be69
@@ -50,9 +50,11 @@ struct JsonContext @local
|
||||
DString last_string;
|
||||
double last_number;
|
||||
char current;
|
||||
anyfault current_err;
|
||||
bool skip_comments;
|
||||
bool reached_end;
|
||||
bitstruct : char {
|
||||
bool skip_comments;
|
||||
bool reached_end;
|
||||
bool pushed_back;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -122,7 +124,7 @@ fn JsonTokenType! lex_number(JsonContext *context, char c) @local
|
||||
c = read_next(context)!;
|
||||
}
|
||||
}
|
||||
pushback(context);
|
||||
pushback(context, c);
|
||||
double! d = t.as_str().to_double() ?? JsonParsingError.INVALID_NUMBER?;
|
||||
context.last_number = d!;
|
||||
return NUMBER;
|
||||
@@ -180,14 +182,24 @@ fn Object*! parse_array(JsonContext* context) @local
|
||||
return list;
|
||||
}
|
||||
|
||||
fn void pushback(JsonContext* context) @local
|
||||
fn void pushback(JsonContext* context, char c) @local
|
||||
{
|
||||
if (!context.reached_end) context.stream.pushback_byte()!!;
|
||||
if (!context.reached_end)
|
||||
{
|
||||
assert(!context.pushed_back);
|
||||
context.pushed_back = true;
|
||||
context.current = c;
|
||||
}
|
||||
}
|
||||
|
||||
fn char! read_next(JsonContext* context) @local
|
||||
{
|
||||
if (context.reached_end) return '\0';
|
||||
if (context.pushed_back)
|
||||
{
|
||||
context.pushed_back = false;
|
||||
return context.current;
|
||||
}
|
||||
char! c = context.stream.read_byte();
|
||||
if (catch err = c)
|
||||
{
|
||||
@@ -225,7 +237,7 @@ fn JsonTokenType! advance(JsonContext* context) @local
|
||||
c = read_next(context)!;
|
||||
if (c != '*')
|
||||
{
|
||||
pushback(context);
|
||||
pushback(context, c);
|
||||
break WS;
|
||||
}
|
||||
while COMMENT: (true)
|
||||
|
||||
Reference in New Issue
Block a user