mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-05-28 05:52:53 +00:00
JSSpecCompiler: Split Parser/SpecParser.cpp into 8 files
This SpecParser.cpp had an ever increasing number of lines and contained an implementation of 8 different classes. So I figured out it's about the time to split it. No behavior change.
This commit is contained in:
parent
b9cfb50f71
commit
7ea2138b6c
Notes:
sideshowbarker
2024-07-17 09:41:18 +09:00
Author: https://github.com/DanShaders
Commit: 7ea2138b6c
Pull-request: https://github.com/SerenityOS/serenity/pull/23522
Reviewed-by: https://github.com/ADKaster ✅
11 changed files with 606 additions and 513 deletions
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
* Copyright (c) 2023-2024, Dan Klishch <danilklishch@gmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "Parser/Lexer.h"
|
||||
#include "Parser/SpecParser.h"
|
||||
#include "Parser/XMLUtils.h"
|
||||
|
||||
namespace JSSpecCompiler {
|
||||
|
||||
NonnullOwnPtr<Specification> Specification::create(SpecificationParsingContext& ctx, XML::Node const* element)
|
||||
{
|
||||
VERIFY(element->as_element().name == tag_specification);
|
||||
|
||||
auto specification = make<Specification>();
|
||||
specification->parse(ctx, element);
|
||||
return specification;
|
||||
}
|
||||
|
||||
void Specification::collect_into(TranslationUnitRef translation_unit)
|
||||
{
|
||||
for (auto& clause : m_clauses)
|
||||
clause->collect_into(translation_unit);
|
||||
}
|
||||
|
||||
void Specification::parse(SpecificationParsingContext& ctx, XML::Node const* element)
|
||||
{
|
||||
for (auto const& child : element->as_element().children) {
|
||||
child->content.visit(
|
||||
[&](XML::Node::Element const& element) {
|
||||
if (element.name == tag_emu_intro) {
|
||||
// Introductory comments are ignored.
|
||||
} else if (element.name == tag_emu_clause) {
|
||||
m_clauses.append(SpecificationClause::create(ctx, child));
|
||||
} else if (element.name == tag_emu_import) {
|
||||
parse(ctx, child);
|
||||
} else {
|
||||
ctx.diag().error(ctx.location_from_xml_offset(child->offset),
|
||||
"<{}> should not be a child of <specification>", element.name);
|
||||
}
|
||||
},
|
||||
[&](XML::Node::Text const&) {
|
||||
if (!contains_empty_text(child)) {
|
||||
ctx.diag().error(ctx.location_from_xml_offset(child->offset),
|
||||
"non-empty text node should not be a child of <specification>");
|
||||
}
|
||||
},
|
||||
[&](auto) {});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue