From 66f4cdba85830ee5a41491c286cc594cb8e780ee Mon Sep 17 00:00:00 2001 From: Dan Klishch Date: Thu, 17 Aug 2023 22:31:56 -0400 Subject: [PATCH] JSSpecCompiler: Make it compile and dump AST created from stdin input --- .../Lagom/Tools/CodeGenerators/CMakeLists.txt | 3 ++ .../JSSpecCompiler/CMakeLists.txt | 13 +++++++ .../CodeGenerators/JSSpecCompiler/main.cpp | 37 +++++++++++++++++++ 3 files changed, 53 insertions(+) create mode 100644 Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/CMakeLists.txt create mode 100644 Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/main.cpp diff --git a/Meta/Lagom/Tools/CodeGenerators/CMakeLists.txt b/Meta/Lagom/Tools/CodeGenerators/CMakeLists.txt index e4bacbd23c..f47a5c1612 100644 --- a/Meta/Lagom/Tools/CodeGenerators/CMakeLists.txt +++ b/Meta/Lagom/Tools/CodeGenerators/CMakeLists.txt @@ -1,5 +1,8 @@ add_subdirectory(GMLCompiler) add_subdirectory(IPCCompiler) +if (BUILD_LAGOM) + add_subdirectory(JSSpecCompiler) +endif() add_subdirectory(LibEDID) add_subdirectory(LibGL) add_subdirectory(LibLocale) diff --git a/Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/CMakeLists.txt b/Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/CMakeLists.txt new file mode 100644 index 0000000000..5a1684f4d8 --- /dev/null +++ b/Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/CMakeLists.txt @@ -0,0 +1,13 @@ +set(SOURCES + AST/ASTPrinting.cpp + Parser/Lexer.cpp + Parser/ParseError.cpp + Parser/SpecParser.cpp + Parser/TextParser.cpp + Parser/XMLUtils.cpp + main.cpp +) + +lagom_tool(JSSpecCompiler LIBS LibMain LibXML) +target_include_directories(JSSpecCompiler PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) +target_compile_options(JSSpecCompiler PRIVATE -Wno-missing-field-initializers) diff --git a/Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/main.cpp b/Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/main.cpp new file mode 100644 index 0000000000..276ac45784 --- /dev/null +++ b/Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/main.cpp @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2023, Dan Klishch + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include +#include +#include +#include + +#include "Parser/SpecParser.h" + +ErrorOr serenity_main(Main::Arguments) +{ + using namespace JSSpecCompiler; + + auto input = TRY(TRY(Core::File::standard_input())->read_until_eof()); + XML::Parser parser { StringView(input.bytes()) }; + + auto maybe_document = parser.parse(); + if (maybe_document.is_error()) { + outln("{}", maybe_document.error()); + return 1; + } + auto document = maybe_document.release_value(); + + auto maybe_function = JSSpecCompiler::Function::create(&document.root()); + if (maybe_function.is_error()) { + outln("{}", maybe_function.error()->to_string()); + return 1; + } + auto function = maybe_function.value(); + + out("{}", function.m_algorithm.m_tree); + return 0; +}