Parcourir la source

JSSpecCompiler: Remove ParseError

Dan Klishch il y a 1 an
Parent
commit
94f5086b93

+ 0 - 1
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

+ 0 - 1
Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/Parser/Lexer.h

@@ -6,7 +6,6 @@
 
 #pragma once
 
-#include "Parser/ParseError.h"
 #include "Parser/Token.h"
 
 namespace JSSpecCompiler {

+ 0 - 57
Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/Parser/ParseError.cpp

@@ -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;
-}
-
-}

+ 0 - 38
Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/Parser/ParseError.h

@@ -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>>;
-
-}

+ 0 - 1
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"
 

+ 0 - 1
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 {

+ 1 - 8
Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/Parser/XMLUtils.h

@@ -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);