mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 22:54:57 +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
11 changed files with 606 additions and 513 deletions
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
* 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 {
|
||||
|
||||
Optional<Algorithm> Algorithm::create(SpecificationParsingContext& ctx, XML::Node const* element)
|
||||
{
|
||||
VERIFY(element->as_element().name == tag_emu_alg);
|
||||
|
||||
Vector<XML::Node const*> steps_list;
|
||||
for (auto const& child : element->as_element().children) {
|
||||
child->content.visit(
|
||||
[&](XML::Node::Element const& element) {
|
||||
if (element.name == tag_ol) {
|
||||
steps_list.append(child);
|
||||
return;
|
||||
}
|
||||
|
||||
ctx.diag().error(ctx.location_from_xml_offset(child->offset),
|
||||
"<{}> should not be a child of <emu-alg>"sv, 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 <emu-alg>");
|
||||
}
|
||||
},
|
||||
[&](auto const&) {});
|
||||
}
|
||||
|
||||
if (steps_list.size() != 1) {
|
||||
ctx.diag().error(ctx.location_from_xml_offset(element->offset),
|
||||
"<emu-alg> should have exactly one <ol> child"sv);
|
||||
return {};
|
||||
}
|
||||
|
||||
auto steps_creation_result = AlgorithmStepList::create(ctx, steps_list[0]);
|
||||
if (steps_creation_result.has_value()) {
|
||||
Algorithm algorithm;
|
||||
algorithm.m_tree = steps_creation_result.release_value().tree();
|
||||
return algorithm;
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue