mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-05-28 14:02:51 +00:00
JSSpecCompiler: Parse true, false, this, undefined, and null
This commit is contained in:
parent
86d54a8684
commit
b800276347
Notes:
sideshowbarker
2024-07-16 21:45:42 +09:00
Author: https://github.com/DanShaders
Commit: b800276347
Pull-request: https://github.com/SerenityOS/serenity/pull/23123
Reviewed-by: https://github.com/ADKaster ✅
7 changed files with 70 additions and 3 deletions
|
@ -298,6 +298,24 @@ TextParseErrorOr<Tree> TextParser::parse_expression()
|
|||
NullableTree expression;
|
||||
if (token.type == TokenType::Identifier) {
|
||||
expression = make_ref_counted<UnresolvedReference>(token.data);
|
||||
} else if (token.type == TokenType::WellKnownValue) {
|
||||
static constexpr struct {
|
||||
StringView name;
|
||||
WellKnownNode::Type type;
|
||||
} translations[] = {
|
||||
{ "false"sv, WellKnownNode::Type::False },
|
||||
{ "null"sv, WellKnownNode::Type::Null },
|
||||
{ "this"sv, WellKnownNode::Type::This },
|
||||
{ "true"sv, WellKnownNode::Type::True },
|
||||
{ "undefined"sv, WellKnownNode::Type::Undefined },
|
||||
};
|
||||
for (auto [name, type] : translations) {
|
||||
if (token.data == name) {
|
||||
expression = make_ref_counted<WellKnownNode>(type);
|
||||
break;
|
||||
}
|
||||
}
|
||||
VERIFY(expression);
|
||||
} else if (token.type == TokenType::Number) {
|
||||
expression = make_ref_counted<MathematicalConstant>(MUST(Crypto::BigFraction::from_string(token.data)));
|
||||
} else if (token.type == TokenType::String) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue