mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-05-21 10:32:51 +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,69 @@
|
|||
/*
|
||||
* Copyright (c) 2023, Dan Klishch <danilklishch@gmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <AK/NonnullOwnPtr.h>
|
||||
#include <LibCore/File.h>
|
||||
#include <LibXML/Parser/Parser.h>
|
||||
|
||||
#include "Function.h"
|
||||
#include "Parser/Lexer.h"
|
||||
#include "Parser/SpecParser.h"
|
||||
#include "Parser/TextParser.h"
|
||||
#include "Parser/XMLUtils.h"
|
||||
|
||||
namespace JSSpecCompiler {
|
||||
|
||||
SpecParsingStep::SpecParsingStep()
|
||||
: CompilationStep("parser"sv)
|
||||
{
|
||||
}
|
||||
|
||||
SpecParsingStep::~SpecParsingStep() = default;
|
||||
|
||||
void SpecParsingStep::run(TranslationUnitRef translation_unit)
|
||||
{
|
||||
SpecificationParsingContext ctx(translation_unit);
|
||||
auto filename = translation_unit->filename();
|
||||
|
||||
auto file_or_error = Core::File::open_file_or_standard_stream(filename, Core::File::OpenMode::Read);
|
||||
if (file_or_error.is_error()) {
|
||||
ctx.diag().fatal_error(Location::global_scope(),
|
||||
"unable to open '{}': {}", filename, file_or_error.error());
|
||||
return;
|
||||
}
|
||||
|
||||
auto input_or_error = file_or_error.value()->read_until_eof();
|
||||
if (input_or_error.is_error()) {
|
||||
ctx.diag().fatal_error(Location::global_scope(),
|
||||
"unable to read '{}': {}", filename, input_or_error.error());
|
||||
return;
|
||||
}
|
||||
m_input = input_or_error.release_value();
|
||||
|
||||
XML::Parser parser { m_input };
|
||||
auto document_or_error = parser.parse();
|
||||
if (document_or_error.is_error()) {
|
||||
ctx.diag().fatal_error(ctx.file_scope(),
|
||||
"XML::Parser failed to parse input: {}", document_or_error.error());
|
||||
ctx.diag().note(ctx.file_scope(),
|
||||
"since XML::Parser backtracks on error, the message above is likely to point to the "
|
||||
"first tag in the input - use external XML verifier to find out the exact cause of error");
|
||||
return;
|
||||
}
|
||||
m_document = make<XML::Document>(document_or_error.release_value());
|
||||
|
||||
auto const& root = m_document->root();
|
||||
if (!root.is_element() || root.as_element().name != tag_specification) {
|
||||
ctx.diag().fatal_error(ctx.location_from_xml_offset(root.offset),
|
||||
"document root must be <specification> tag");
|
||||
return;
|
||||
}
|
||||
|
||||
m_specification = Specification::create(ctx, &root);
|
||||
m_specification->collect_into(translation_unit);
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue