Make the lexer not depend on locale

... by not using isalpha() and isspace(). While at it, fix some other
minor things.
This commit is contained in:
Petri Lehtinen 2009-07-09 21:48:04 +03:00
parent 68e948f567
commit 13c7ad3219

View File

@ -88,7 +88,7 @@ static void json_scan_string(json_lex *lex)
goto out; goto out;
} }
if(0 <= *p && *p <= 31) { if(0 <= *p && *p <= 0x1F) {
/* control character */ /* control character */
goto out; goto out;
} }
@ -101,8 +101,8 @@ static void json_scan_string(json_lex *lex)
goto out; goto out;
} }
} }
if(*p == '"' || *p == '\\' || *p == '/' || *p == 'b' || else if(*p == '"' || *p == '\\' || *p == '/' || *p == 'b' ||
*p == 'f' || *p == 'n' || *p == 'r' || *p == 't') *p == 'f' || *p == 'n' || *p == 'r' || *p == 't')
p++; p++;
else else
goto out; goto out;
@ -231,11 +231,14 @@ static int json_lex_scan(json_lex *lex)
lex->value.string = NULL; lex->value.string = NULL;
} }
while(isspace(*lex->input)) { c = *lex->input;
if(*lex->input == '\n') while(c == ' ' || c == '\t' || c == '\n' || c == '\r')
{
if(c == '\n')
lex->line++; lex->line++;
lex->input++; lex->input++;
c = *lex->input;
} }
lex->start = lex->input; lex->start = lex->input;
@ -245,7 +248,8 @@ static int json_lex_scan(json_lex *lex)
lex->token = JSON_TOKEN_EOF; lex->token = JSON_TOKEN_EOF;
else if(c == '{' || c == '}' || c == '[' || c == ']' || else if(c == '{' || c == '}' || c == '[' || c == ']' ||
c == ':' || c == ',') { c == ':' || c == ',')
{
lex->token = c; lex->token = c;
lex->input++; lex->input++;
} }
@ -256,11 +260,11 @@ static int json_lex_scan(json_lex *lex)
else if(isdigit(c) || c == '-') else if(isdigit(c) || c == '-')
json_scan_number(lex); json_scan_number(lex);
else if(isalpha(c)) { else if(isupper(c) || islower(c)) {
/* eat up the whole identifier for clearer error messages */ /* eat up the whole identifier for clearer error messages */
int len; int len;
while(isalpha(*lex->input)) while(isupper(*lex->input) || islower(*lex->input))
lex->input++; lex->input++;
len = lex->input - lex->start; len = lex->input - lex->start;