support bool literal

This commit is contained in:
MaxWk 2021-11-06 15:19:12 +08:00
parent e264b4dcba
commit dd54b4aa26
2 changed files with 29 additions and 0 deletions

View File

@ -1524,6 +1524,23 @@ bool ParserNull::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
return false;
}
bool ParserBool::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
{
if (ParserKeyword("true").parse(pos, node, expected))
{
node = std::make_shared<ASTLiteral>(true);
return true;
}
else if (ParserKeyword("false").parse(pos, node, expected))
{
node = std::make_shared<ASTLiteral>(false);
return true;
}
else
return false;
}
static bool parseNumber(char * buffer, size_t size, bool negative, int base, Field & res)
{
errno = 0; /// Functions strto* don't clear errno.
@ -1755,6 +1772,7 @@ bool ParserLiteral::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
{
ParserNull null_p;
ParserNumber num_p;
ParserBool bool_p;
ParserStringLiteral str_p;
if (null_p.parse(pos, node, expected))
@ -1763,6 +1781,9 @@ bool ParserLiteral::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
if (num_p.parse(pos, node, expected))
return true;
if (bool_p.parse(pos, node, expected))
return true;
if (str_p.parse(pos, node, expected))
return true;

View File

@ -294,6 +294,14 @@ protected:
bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected) override;
};
/** Bool literal.
*/
class ParserBool : public IParserBase
{
protected:
const char * getName() const override { return "Bool"; }
bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected) override;
};
/** Numeric literal.
*/