diff options
author | Itamar <itamar8910@gmail.com> | 2021-03-28 10:40:20 +0300 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-04-06 21:51:58 +0200 |
commit | 9954a1837ff5eadf674de197092c4eb000574fa3 (patch) | |
tree | 365230d7fe80a2dbe76960410ac25e5787767874 /Userland/Libraries/LibCpp | |
parent | cbb49f26d9b9029c38afe6951bb7c42823e3ac8b (diff) | |
download | serenity-9954a1837ff5eadf674de197092c4eb000574fa3.zip |
LibCpp: Parse nullptr literal
Diffstat (limited to 'Userland/Libraries/LibCpp')
-rw-r--r-- | Userland/Libraries/LibCpp/AST.cpp | 5 | ||||
-rw-r--r-- | Userland/Libraries/LibCpp/AST.h | 14 | ||||
-rw-r--r-- | Userland/Libraries/LibCpp/Parser.cpp | 12 |
3 files changed, 27 insertions, 4 deletions
diff --git a/Userland/Libraries/LibCpp/AST.cpp b/Userland/Libraries/LibCpp/AST.cpp index 4cef2dd177..f44499be1a 100644 --- a/Userland/Libraries/LibCpp/AST.cpp +++ b/Userland/Libraries/LibCpp/AST.cpp @@ -437,4 +437,9 @@ void NamespaceDeclaration::dump(size_t indent) const decl.dump(indent + 1); } +void NullPointerLiteral::dump(size_t indent) const +{ + ASTNode::dump(indent); +} + } diff --git a/Userland/Libraries/LibCpp/AST.h b/Userland/Libraries/LibCpp/AST.h index 0941b3b993..f1fea9d47e 100644 --- a/Userland/Libraries/LibCpp/AST.h +++ b/Userland/Libraries/LibCpp/AST.h @@ -341,6 +341,20 @@ public: StringView m_value; }; +class NullPointerLiteral : public Expression { +public: + virtual ~NullPointerLiteral() override = default; + virtual const char* class_name() const override { return "NullPointerLiteral"; } + virtual void dump(size_t indent) const override; + + NullPointerLiteral(ASTNode* parent, Optional<Position> start, Optional<Position> end, const String& filename) + : Expression(parent, start, end, filename) + { + } +}; + + + class BooleanLiteral : public Expression { public: virtual ~BooleanLiteral() override = default; diff --git a/Userland/Libraries/LibCpp/Parser.cpp b/Userland/Libraries/LibCpp/Parser.cpp index b8838335f5..14db37a755 100644 --- a/Userland/Libraries/LibCpp/Parser.cpp +++ b/Userland/Libraries/LibCpp/Parser.cpp @@ -414,8 +414,10 @@ bool Parser::match_literal() return true; case Token::Type::DoubleQuotedString: return true; + case Token::Type::Float: + return true; case Token::Type::Keyword: { - return match_boolean_literal(); + return match_boolean_literal() || peek().text() == "nullptr"; } default: return false; @@ -477,6 +479,10 @@ NonnullRefPtr<Expression> Parser::parse_literal(ASTNode& parent) case Token::Type::Keyword: { if (match_boolean_literal()) return parse_boolean_literal(parent); + if (peek().text() == "nullptr") { + auto token = consume(); + return create_ast_node<NullPointerLiteral>(parent, token.start(), token.end()); + } [[fallthrough]]; } default: { @@ -771,10 +777,8 @@ void Parser::error(StringView message) bool Parser::match_expression() { auto token_type = peek().type(); - return token_type == Token::Type::Integer - || token_type == Token::Type::Float + return match_literal() || token_type == Token::Type::Identifier - || token_type == Token::Type::DoubleQuotedString || match_unary_expression(); } |