JSSpecCompiler: Parse properties list clause title

This commit is contained in:
Dan Klishch 2024-03-08 23:06:32 -05:00 committed by Andrew Kaster
parent ec16556fea
commit 3077e516a2
Notes: sideshowbarker 2024-07-17 18:08:55 +09:00
4 changed files with 68 additions and 1 deletions

View file

@ -26,6 +26,9 @@ NonnullOwnPtr<SpecificationClause> SpecificationClause::create(SpecificationPars
},
[&](OneOf<AbstractOperationDeclaration, AccessorDeclaration, MethodDeclaration> auto const&) {
result = make<SpecificationFunction>(move(specification_clause));
},
[&](ClauseHeader::PropertiesList const&) {
result = make<ObjectProperties>(move(specification_clause));
});
if (!result->post_initialize(element))

View file

@ -150,6 +150,14 @@ private:
Algorithm m_algorithm;
};
class ObjectProperties : public SpecificationClause {
public:
ObjectProperties(SpecificationClause&& clause)
: SpecificationClause(move(clause))
{
}
};
class Specification {
public:
static NonnullOwnPtr<Specification> create(SpecificationParsingContext& ctx, XML::Node const* element);

View file

@ -731,6 +731,47 @@ TextParseErrorOr<AccessorDeclaration> TextParser::parse_accessor_declaration()
return accessor;
}
// <properties_list_declaration> :== | Properties of the <qualified_name> Prototype Object $
// | Properties of the <qualified_name> Constructor $
// | Properties of <qualified_name> Instances $
// | The <qualified_name> Constructor $
TextParseErrorOr<ClauseHeader::PropertiesList> TextParser::parse_properties_list_declaration()
{
auto rollback = rollback_point();
ClauseHeader::PropertiesList properties_list;
if (!consume_word("The"sv).is_error()) {
properties_list.name = TRY(parse_qualified_name());
properties_list.object_type = ClauseHeader::ObjectType::Constructor;
TRY(consume_word("Constructor"sv));
} else {
TRY(consume_words({ "Properties"sv, "of"sv }));
bool has_the = !consume_word("the"sv).is_error();
properties_list.name = TRY(parse_qualified_name());
if (!has_the) {
TRY(consume_word("Instances"sv));
properties_list.object_type = ClauseHeader::ObjectType::Instance;
} else {
if (consume_word("Prototype"sv).is_error()) {
TRY(consume_word("Constructor"sv));
properties_list.object_type = ClauseHeader::ObjectType::Constructor;
} else {
TRY(consume_word("Object"sv));
properties_list.object_type = ClauseHeader::ObjectType::Prototype;
}
}
}
TRY(expect_eof());
rollback.disarm();
return properties_list;
}
TextParseErrorOr<MethodDeclaration> TextParser::parse_method_declaration()
{
auto rollback = rollback_point();
@ -764,6 +805,9 @@ TextParseErrorOr<ClauseHeader> TextParser::parse_clause_header(ClauseHasAoidAttr
} else if (auto method = parse_method_declaration(); !method.is_error()) {
result.header = method.release_value();
return result;
} else if (auto properties_list = parse_properties_list_declaration(); !properties_list.is_error()) {
result.header = properties_list.release_value();
return result;
}
}
return TextParseError {};

View file

@ -13,8 +13,19 @@
namespace JSSpecCompiler {
struct ClauseHeader {
enum class ObjectType {
Constructor,
Prototype,
Instance,
};
struct PropertiesList {
QualifiedName name;
ObjectType object_type;
};
StringView section_number;
Variant<AK::Empty, AbstractOperationDeclaration, AccessorDeclaration, MethodDeclaration> header;
Variant<AK::Empty, AbstractOperationDeclaration, AccessorDeclaration, MethodDeclaration, PropertiesList> header;
};
struct TextParseError { };
@ -93,6 +104,7 @@ private:
TextParseErrorOr<AbstractOperationDeclaration> parse_abstract_operation_declaration();
TextParseErrorOr<MethodDeclaration> parse_method_declaration();
TextParseErrorOr<AccessorDeclaration> parse_accessor_declaration();
TextParseErrorOr<ClauseHeader::PropertiesList> parse_properties_list_declaration();
SpecificationParsingContext& m_ctx;
Vector<Token> const& m_tokens;