From 94f5086b93dd39b22d058e5d20175cd681e50b09 Mon Sep 17 00:00:00 2001 From: Dan Klishch Date: Sat, 20 Jan 2024 19:48:32 -0500 Subject: [PATCH] JSSpecCompiler: Remove ParseError --- .../JSSpecCompiler/CMakeLists.txt | 1 - .../JSSpecCompiler/Parser/Lexer.h | 1 - .../JSSpecCompiler/Parser/ParseError.cpp | 57 ------------------- .../JSSpecCompiler/Parser/ParseError.h | 38 ------------- .../JSSpecCompiler/Parser/SpecParser.h | 1 - .../JSSpecCompiler/Parser/TextParser.h | 1 - .../JSSpecCompiler/Parser/XMLUtils.h | 9 +-- 7 files changed, 1 insertion(+), 107 deletions(-) delete mode 100644 Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/Parser/ParseError.cpp delete mode 100644 Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/Parser/ParseError.h diff --git a/Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/CMakeLists.txt b/Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/CMakeLists.txt index 59f4133df8..18f7850404 100644 --- a/Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/CMakeLists.txt +++ b/Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/CMakeLists.txt @@ -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 diff --git a/Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/Parser/Lexer.h b/Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/Parser/Lexer.h index b41e3158d2..469ad32138 100644 --- a/Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/Parser/Lexer.h +++ b/Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/Parser/Lexer.h @@ -6,7 +6,6 @@ #pragma once -#include "Parser/ParseError.h" #include "Parser/Token.h" namespace JSSpecCompiler { diff --git a/Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/Parser/ParseError.cpp b/Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/Parser/ParseError.cpp deleted file mode 100644 index 9d748c845c..0000000000 --- a/Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/Parser/ParseError.cpp +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (c) 2023, Dan Klishch - * - * SPDX-License-Identifier: BSD-2-Clause - */ - -#include "Parser/ParseError.h" -#include "DiagnosticEngine.h" - -namespace JSSpecCompiler { - -NonnullRefPtr ParseError::create(String message, XML::Node const* node) -{ - return make_ref_counted(move(message), node); -} - -NonnullRefPtr 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::create(ErrorOr 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; -} - -} diff --git a/Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/Parser/ParseError.h b/Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/Parser/ParseError.h deleted file mode 100644 index 50abc39700..0000000000 --- a/Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/Parser/ParseError.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2023, Dan Klishch - * - * SPDX-License-Identifier: BSD-2-Clause - */ - -#pragma once - -#include -#include - -namespace JSSpecCompiler { - -class ParseError : public RefCounted { -public: - ParseError(String&& message, XML::Node const* node) - : m_message(move(message)) - , m_node(node) - { - } - - static NonnullRefPtr create(String message, XML::Node const* node); - static NonnullRefPtr create(StringView message, XML::Node const* node); - static NonnullRefPtr create(ErrorOr 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 -using ParseErrorOr = ErrorOr>; - -} diff --git a/Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/Parser/SpecParser.h b/Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/Parser/SpecParser.h index c5802630ca..6431e39426 100644 --- a/Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/Parser/SpecParser.h +++ b/Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/Parser/SpecParser.h @@ -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" diff --git a/Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/Parser/TextParser.h b/Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/Parser/TextParser.h index 0e7c7756dd..41d4d38410 100644 --- a/Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/Parser/TextParser.h +++ b/Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/Parser/TextParser.h @@ -8,7 +8,6 @@ #include "AST/AST.h" #include "Function.h" -#include "Parser/ParseError.h" #include "Parser/Token.h" namespace JSSpecCompiler { diff --git a/Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/Parser/XMLUtils.h b/Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/Parser/XMLUtils.h index b0dd265989..b0cbd5889d 100644 --- a/Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/Parser/XMLUtils.h +++ b/Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/Parser/XMLUtils.h @@ -6,18 +6,11 @@ #pragma once +#include #include -#include "Parser/ParseError.h" - namespace JSSpecCompiler { -struct IgnoreComments { - ParseErrorOr operator()(XML::Node::Comment const&) { return {}; } -}; - -inline constexpr IgnoreComments ignore_comments {}; - bool contains_empty_text(XML::Node const* node); Optional get_attribute_by_name(XML::Node const* node, StringView attribute_name);