From f7c952f842cc6c467e1181d6723057ebb19af39d Mon Sep 17 00:00:00 2001 From: Dan Klishch Date: Tue, 23 Jan 2024 18:33:31 -0500 Subject: [PATCH] JSSpecCompiler: Ignore notes in algorithm steps --- .../JSSpecCompiler/Parser/SpecParser.cpp | 10 ++++++---- .../CodeGenerators/JSSpecCompiler/Parser/SpecParser.h | 4 ++-- .../JSSpecCompiler/Parser/TextParser.cpp | 8 +++++++- .../CodeGenerators/JSSpecCompiler/Parser/TextParser.h | 2 +- .../JSSpecCompiler/Tests/spec-parsing.xml | 9 +++++++++ .../JSSpecCompiler/Tests/spec-parsing.xml.expectation | 5 +++++ 6 files changed, 30 insertions(+), 8 deletions(-) diff --git a/Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/Parser/SpecParser.cpp b/Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/Parser/SpecParser.cpp index beae11f696..831ce8af99 100644 --- a/Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/Parser/SpecParser.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/Parser/SpecParser.cpp @@ -97,7 +97,7 @@ bool AlgorithmStep::parse() { TextParser parser(m_ctx, m_tokens, m_node); - TextParseErrorOr parse_result = TextParseError {}; + TextParseErrorOr parse_result = TextParseError {}; if (m_substeps) parse_result = parser.parse_step_with_substeps(RefPtr(m_substeps).release_nonnull()); else @@ -133,10 +133,12 @@ Optional AlgorithmStepList::create(SpecificationParsingContex update_logical_scope_for_step(ctx, parent_scope, step_number); return AlgorithmStep::create(ctx, child); }); - if (!step_creation_result.has_value()) + if (!step_creation_result.has_value()) { all_steps_parsed = false; - else - step_expressions.append(step_creation_result.release_value().tree()); + } else { + if (auto expression = step_creation_result.release_value().tree()) + step_expressions.append(expression.release_nonnull()); + } ++step_number; return; } diff --git a/Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/Parser/SpecParser.h b/Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/Parser/SpecParser.h index 8dd8da7a1c..1dc156b247 100644 --- a/Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/Parser/SpecParser.h +++ b/Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/Parser/SpecParser.h @@ -62,7 +62,7 @@ class AlgorithmStep { public: static Optional create(SpecificationParsingContext& ctx, XML::Node const* node); - Tree tree() const { return m_expression; } + NullableTree tree() const { return m_expression; } private: AlgorithmStep(SpecificationParsingContext& ctx) @@ -75,7 +75,7 @@ private: SpecificationParsingContext& m_ctx; Vector m_tokens; XML::Node const* m_node; - Tree m_expression = error_tree; + NullableTree m_expression = error_tree; NullableTree m_substeps; }; diff --git a/Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/Parser/TextParser.cpp b/Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/Parser/TextParser.cpp index 5bf7604406..f6aa00f22c 100644 --- a/Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/Parser/TextParser.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/Parser/TextParser.cpp @@ -598,10 +598,16 @@ TextParseErrorOr TextParser::parse_else(Tree else_branch) } // | -TextParseErrorOr TextParser::parse_step_without_substeps() +TextParseErrorOr TextParser::parse_step_without_substeps() { auto rollback = rollback_point(); + // NOTE: ... + if (auto result = consume_word("NOTE:"sv); !result.is_error()) { + rollback.disarm(); + return nullptr; + } + // if (auto result = parse_simple_step_or_inline_if_branch(); !result.is_error()) { rollback.disarm(); diff --git a/Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/Parser/TextParser.h b/Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/Parser/TextParser.h index d71942c7cc..530192b274 100644 --- a/Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/Parser/TextParser.h +++ b/Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/Parser/TextParser.h @@ -56,7 +56,7 @@ public: } TextParseErrorOr parse_clause_header(ClauseHasAoidAttribute clause_has_aoid_attribute); - TextParseErrorOr parse_step_without_substeps(); + TextParseErrorOr parse_step_without_substeps(); TextParseErrorOr parse_step_with_substeps(Tree substeps); FailedTextParseDiagnostic get_diagnostic() const; diff --git a/Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/Tests/spec-parsing.xml b/Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/Tests/spec-parsing.xml index c85a1a2a38..5c63963284 100644 --- a/Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/Tests/spec-parsing.xml +++ b/Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/Tests/spec-parsing.xml @@ -73,4 +73,13 @@ + +

7 Notes ( )

+ +
    +
  1. NOTE: This abstract operation returns unused in case you didn't notice.
  2. +
  3. Return unused.
  4. +
+
+
diff --git a/Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/Tests/spec-parsing.xml.expectation b/Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/Tests/spec-parsing.xml.expectation index 01b6287810..d892367e24 100644 --- a/Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/Tests/spec-parsing.xml.expectation +++ b/Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/Tests/spec-parsing.xml.expectation @@ -100,3 +100,8 @@ TreeList ReturnNode WellKnownNode Undefined +Notes(): +TreeList + ReturnNode + Enumerator unused +