number parsing and control characters skipping
This commit is contained in:
parent
f69b498caf
commit
17981347f4
@ -19,7 +19,7 @@ public class Parser
|
||||
protected enum TokenType : byte
|
||||
{
|
||||
Invalid,
|
||||
String,
|
||||
StringOrNumber,
|
||||
Equals,
|
||||
BracketOpen,
|
||||
BracketClose,
|
||||
@ -40,7 +40,7 @@ public class Parser
|
||||
case TokenType.Invalid:
|
||||
s = "INVALID_TOKEN";
|
||||
break;
|
||||
case TokenType.String:
|
||||
case TokenType.StringOrNumber:
|
||||
s = value ?? "NULL";
|
||||
break;
|
||||
case TokenType.Equals:
|
||||
@ -86,7 +86,7 @@ public class Parser
|
||||
return;
|
||||
_tokens.Add(new Token
|
||||
{
|
||||
type = TokenType.String,
|
||||
type = TokenType.StringOrNumber,
|
||||
column = (short)(column - str.Length),
|
||||
line = line,
|
||||
value = str.ToString()
|
||||
@ -143,7 +143,10 @@ public class Parser
|
||||
});
|
||||
break;
|
||||
default:
|
||||
str.Append((char)c);
|
||||
// Skip control characters, which are invisible and causing frontend bugs.
|
||||
// I dont know why there are so many of them in strings.
|
||||
if(c >= 0x20)
|
||||
str.Append((char)c);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -162,8 +165,16 @@ public class Parser
|
||||
Token tok = _tokens[_tokenIndex++];
|
||||
switch (tok.type)
|
||||
{
|
||||
case TokenType.String:
|
||||
return tok.value!;
|
||||
case TokenType.StringOrNumber:
|
||||
if(string.IsNullOrEmpty(tok.value))
|
||||
return string.Empty;
|
||||
if (tok.value[0] != '-' && !char.IsDigit(tok.value[0]))
|
||||
return tok.value;
|
||||
if(tok.value.Contains('.') && Double.TryParse(tok.value, out double d))
|
||||
return d;
|
||||
if (Int64.TryParse(tok.value, out long l))
|
||||
return l;
|
||||
return tok.value;
|
||||
case TokenType.BracketOpen:
|
||||
return ParseListOrDict();
|
||||
case TokenType.BracketClose:
|
||||
@ -177,7 +188,7 @@ public class Parser
|
||||
{
|
||||
Token first = _tokens[_tokenIndex];
|
||||
Token second = _tokens[_tokenIndex + 1];
|
||||
if (first.type == TokenType.String && second.type == TokenType.Equals)
|
||||
if (first.type == TokenType.StringOrNumber && second.type == TokenType.Equals)
|
||||
return ParseDict();
|
||||
|
||||
return ParseList();
|
||||
@ -227,7 +238,7 @@ public class Parser
|
||||
continue;
|
||||
}
|
||||
|
||||
if(tok.type != TokenType.String)
|
||||
if(tok.type != TokenType.StringOrNumber)
|
||||
throw new UnexpectedTokenException(tok, _tokenIndex - 1);
|
||||
|
||||
string key = tok.value!;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user