Using lexer (development) [#CLICKHOUSE-2].

This commit is contained in:
Alexey Milovidov 2017-07-13 00:45:47 +03:00 committed by alexey-milovidov
parent cd8d8bf972
commit a8b6920eab
2 changed files with 16 additions and 4 deletions

View File

@ -71,7 +71,7 @@ std::string getOrdinalSuffix(T n)
}
}
/// More efficient than libc, because doesn't respect locale.
/// More efficient than libc, because doesn't respect locale. But for some functions table implementation could be better.
inline bool isASCII(char c)
{
@ -89,6 +89,13 @@ inline bool isNumericASCII(char c)
return (c >= '0' && c <= '9');
}
inline bool isHexDigit(char c)
{
return isNumericASCII(c)
|| (c >= 'a' && c <= 'f')
|| (c >= 'A' && c <= 'F');
}
inline bool isAlphaNumericASCII(char c)
{
return isAlphaASCII(c)

View File

@ -88,19 +88,24 @@ Token Lexer::nextToken()
case '0'...'9':
{
/// 0x, 0b
bool allow_hex = false;
if (pos < end - 2 && *pos == '0' && (pos[1] == 'x' || pos[1] == 'b'))
{
if (pos[1] == 'x')
allow_hex = true;
pos += 2;
}
else
++pos;
while (pos < end && isNumericASCII(*pos))
while (pos < end && (allow_hex ? isHexDigit(*pos) : isNumericASCII(*pos)))
++pos;
/// decimal point
if (pos < end && *pos == '.')
{
++pos;
while (pos < end && isNumericASCII(*pos))
while (pos < end && (allow_hex ? isHexDigit(*pos) : isNumericASCII(*pos)))
++pos;
}
@ -113,7 +118,7 @@ Token Lexer::nextToken()
if (pos < end - 1 && (*pos == '-' || *pos == '+'))
++pos;
while (pos < end && isNumericASCII(*pos))
while (pos < end && (allow_hex ? isHexDigit(*pos) : isNumericASCII(*pos)))
++pos;
}