main.cpp 974 B

12345678910111213141516171819202122232425262728293031323334353637
  1. /*
  2. * Copyright (c) 2023, Dan Klishch <danilklishch@gmail.com>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <AK/Format.h>
  7. #include <LibCore/File.h>
  8. #include <LibMain/Main.h>
  9. #include <LibXML/Parser/Parser.h>
  10. #include "Parser/SpecParser.h"
  11. ErrorOr<int> serenity_main(Main::Arguments)
  12. {
  13. using namespace JSSpecCompiler;
  14. auto input = TRY(TRY(Core::File::standard_input())->read_until_eof());
  15. XML::Parser parser { StringView(input.bytes()) };
  16. auto maybe_document = parser.parse();
  17. if (maybe_document.is_error()) {
  18. outln("{}", maybe_document.error());
  19. return 1;
  20. }
  21. auto document = maybe_document.release_value();
  22. auto maybe_function = JSSpecCompiler::SpecFunction::create(&document.root());
  23. if (maybe_function.is_error()) {
  24. outln("{}", maybe_function.error()->to_string());
  25. return 1;
  26. }
  27. auto function = maybe_function.value();
  28. out("{}", function.m_algorithm.m_tree);
  29. return 0;
  30. }