diff options
author | 0xtechnobabble <0xtechnobabble@protonmail.com> | 2020-03-21 02:29:00 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-03-21 10:08:58 +0100 |
commit | bc002f807a122bcd91498f87b970671a2d38bbb8 (patch) | |
tree | f7ddcffa5176469821647dde1d2f33f2238a4330 /Libraries/LibJS/Parser.cpp | |
parent | c64b5e73f5d78b887c9e9358bccc1524858dbc6f (diff) | |
download | serenity-bc002f807a122bcd91498f87b970671a2d38bbb8.zip |
LibJS: Parse object expressions
Diffstat (limited to 'Libraries/LibJS/Parser.cpp')
-rw-r--r-- | Libraries/LibJS/Parser.cpp | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/Libraries/LibJS/Parser.cpp b/Libraries/LibJS/Parser.cpp index bd02564ad8..badcd97268 100644 --- a/Libraries/LibJS/Parser.cpp +++ b/Libraries/LibJS/Parser.cpp @@ -269,10 +269,27 @@ NonnullRefPtr<Expression> Parser::parse_unary_prefixed_expression() NonnullRefPtr<ObjectExpression> Parser::parse_object_expression() { - // FIXME: Parse actual object expression + HashMap<String, NonnullRefPtr<Expression>> properties; consume(TokenType::CurlyOpen); + + while (!match(TokenType::CurlyClose)) { + auto identifier = create_ast_node<Identifier>(consume(TokenType::Identifier).value()); + + if (match(TokenType::Colon)) { + consume(TokenType::Colon); + properties.set(identifier->string(), parse_expression(0)); + } else { + properties.set(identifier->string(), identifier); + } + + if (!match(TokenType::Comma)) + break; + + consume(TokenType::Comma); + } + consume(TokenType::CurlyClose); - return create_ast_node<ObjectExpression>(); + return create_ast_node<ObjectExpression>(properties); } NonnullRefPtr<ArrayExpression> Parser::parse_array_expression() |