mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-26 01:20:25 +00:00
JSSpecCompiler: Remove ParseError
This commit is contained in:
parent
9a2337f7ad
commit
94f5086b93
Notes:
sideshowbarker
2024-07-17 02:39:10 +09:00
Author: https://github.com/DanShaders Commit: https://github.com/SerenityOS/serenity/commit/94f5086b93 Pull-request: https://github.com/SerenityOS/serenity/pull/22899 Reviewed-by: https://github.com/ADKaster ✅
7 changed files with 1 additions and 107 deletions
|
@ -13,7 +13,6 @@ set(SOURCES
|
|||
Compiler/Passes/SSABuildingPass.cpp
|
||||
Parser/CppASTConverter.cpp
|
||||
Parser/Lexer.cpp
|
||||
Parser/ParseError.cpp
|
||||
Parser/SpecParser.cpp
|
||||
Parser/TextParser.cpp
|
||||
Parser/XMLUtils.cpp
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "Parser/ParseError.h"
|
||||
#include "Parser/Token.h"
|
||||
|
||||
namespace JSSpecCompiler {
|
||||
|
|
|
@ -1,57 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2023, Dan Klishch <danilklishch@gmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "Parser/ParseError.h"
|
||||
#include "DiagnosticEngine.h"
|
||||
|
||||
namespace JSSpecCompiler {
|
||||
|
||||
NonnullRefPtr<ParseError> ParseError::create(String message, XML::Node const* node)
|
||||
{
|
||||
return make_ref_counted<ParseError>(move(message), node);
|
||||
}
|
||||
|
||||
NonnullRefPtr<ParseError> ParseError::create(StringView message, XML::Node const* node)
|
||||
{
|
||||
return create(MUST(String::from_utf8(message)), node);
|
||||
}
|
||||
|
||||
// FIXME: Remove once String::formatted becomes infallible.
|
||||
NonnullRefPtr<ParseError> ParseError::create(ErrorOr<String> message, XML::Node const* node)
|
||||
{
|
||||
return create(MUST(message), node);
|
||||
}
|
||||
|
||||
String ParseError::to_string() const
|
||||
{
|
||||
StringBuilder builder;
|
||||
builder.appendff("{}\n", m_message);
|
||||
|
||||
XML::Node const* current = m_node;
|
||||
while (current != nullptr) {
|
||||
builder.appendff(" at {}:{} ", current->offset.line + 1, current->offset.column + 1);
|
||||
if (current->is_element()) {
|
||||
builder.append("<"sv);
|
||||
builder.append(current->as_element().name);
|
||||
for (auto [key, value] : current->as_element().attributes)
|
||||
builder.appendff(" {}=\"{}\"", key, value);
|
||||
builder.append(">\n"sv);
|
||||
} else if (current->is_text()) {
|
||||
builder.appendff("text \"{}\"\n", current->as_text().builder.string_view().trim_whitespace());
|
||||
} else {
|
||||
builder.appendff("comment");
|
||||
}
|
||||
current = current->parent;
|
||||
}
|
||||
return MUST(builder.to_string());
|
||||
}
|
||||
|
||||
XML::Offset ParseError::offset() const
|
||||
{
|
||||
return m_node->offset;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,38 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2023, Dan Klishch <danilklishch@gmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AK/String.h>
|
||||
#include <LibXML/DOM/Node.h>
|
||||
|
||||
namespace JSSpecCompiler {
|
||||
|
||||
class ParseError : public RefCounted<ParseError> {
|
||||
public:
|
||||
ParseError(String&& message, XML::Node const* node)
|
||||
: m_message(move(message))
|
||||
, m_node(node)
|
||||
{
|
||||
}
|
||||
|
||||
static NonnullRefPtr<ParseError> create(String message, XML::Node const* node);
|
||||
static NonnullRefPtr<ParseError> create(StringView message, XML::Node const* node);
|
||||
static NonnullRefPtr<ParseError> create(ErrorOr<String> message, XML::Node const* node);
|
||||
|
||||
String to_string() const;
|
||||
XML::Offset offset() const;
|
||||
|
||||
private:
|
||||
String m_message;
|
||||
XML::Node const* m_node;
|
||||
// TODO: Support chained parse errors
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
using ParseErrorOr = ErrorOr<T, NonnullRefPtr<ParseError>>;
|
||||
|
||||
}
|
|
@ -11,7 +11,6 @@
|
|||
#include "AST/AST.h"
|
||||
#include "CompilationPipeline.h"
|
||||
#include "Forward.h"
|
||||
#include "Parser/ParseError.h"
|
||||
#include "Parser/TextParser.h"
|
||||
#include "Parser/Token.h"
|
||||
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
|
||||
#include "AST/AST.h"
|
||||
#include "Function.h"
|
||||
#include "Parser/ParseError.h"
|
||||
#include "Parser/Token.h"
|
||||
|
||||
namespace JSSpecCompiler {
|
||||
|
|
|
@ -6,18 +6,11 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <AK/StringView.h>
|
||||
#include <LibXML/Forward.h>
|
||||
|
||||
#include "Parser/ParseError.h"
|
||||
|
||||
namespace JSSpecCompiler {
|
||||
|
||||
struct IgnoreComments {
|
||||
ParseErrorOr<void> operator()(XML::Node::Comment const&) { return {}; }
|
||||
};
|
||||
|
||||
inline constexpr IgnoreComments ignore_comments {};
|
||||
|
||||
bool contains_empty_text(XML::Node const* node);
|
||||
|
||||
Optional<StringView> get_attribute_by_name(XML::Node const* node, StringView attribute_name);
|
||||
|
|
Loading…
Reference in a new issue