From b74df136fe8a46beedaed7e50e0dd44564c60cc4 Mon Sep 17 00:00:00 2001 From: Dan Klishch Date: Tue, 16 Jan 2024 17:44:59 -0500 Subject: [PATCH] JSSpecCompiler: Always treat trailing MemberAccess as punctuation Due to the way expression parser is written, we need to resolve the ambiguity between member access operators and dots used for punctuation during lexing. The lexer uses a (totally bulletproof) heuristic to do that: whenever '.' is followed by ' ' or '\n', it is considered a dot and member access otherwise. While it works fine for prettified test cases, non-prettified files often lack enter after a trailing dot character. Since MemberAccess will always be invalid at that position, explicitly treat trailing dot as a part of punctuation. --- .../JSSpecCompiler/Parser/Lexer.cpp | 4 ++++ .../Tests/spec-no-new-line-after-dot.xml | 19 +++++++++++++++++++ ...spec-no-new-line-after-dot.xml.expectation | 8 ++++++++ Tests/JSSpecCompiler/test-runner.cpp | 1 + 4 files changed, 32 insertions(+) create mode 100644 Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/Tests/spec-no-new-line-after-dot.xml create mode 100644 Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/Tests/spec-no-new-line-after-dot.xml.expectation diff --git a/Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/Parser/Lexer.cpp b/Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/Parser/Lexer.cpp index 5e9fd95406..e0678f30b8 100644 --- a/Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/Parser/Lexer.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/Parser/Lexer.cpp @@ -151,6 +151,10 @@ ParseErrorOr tokenize_tree(XML::Node const* node, bool allow }, move(ignore_comments))); } + + if (tokens.size() && tokens.last().type == TokenType::MemberAccess) + tokens.last().type = TokenType::Dot; + return result; } diff --git a/Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/Tests/spec-no-new-line-after-dot.xml b/Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/Tests/spec-no-new-line-after-dot.xml new file mode 100644 index 0000000000..18a443406c --- /dev/null +++ b/Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/Tests/spec-no-new-line-after-dot.xml @@ -0,0 +1,19 @@ +]> + + + +

1 The Celestial Object

+ +

1.1 Abstract Operations

+ +

1.1.1 Foo ( a )

+ +
    +
  1. Return a.[[b]].
  2. +
+
+
+
+
+
+
diff --git a/Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/Tests/spec-no-new-line-after-dot.xml.expectation b/Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/Tests/spec-no-new-line-after-dot.xml.expectation new file mode 100644 index 0000000000..b84a41a8be --- /dev/null +++ b/Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/Tests/spec-no-new-line-after-dot.xml.expectation @@ -0,0 +1,8 @@ +===== AST after reference-resolving ===== +Foo(a): +TreeList + ReturnNode + BinaryOperation MemberAccess + Var a + Slot b + diff --git a/Tests/JSSpecCompiler/test-runner.cpp b/Tests/JSSpecCompiler/test-runner.cpp index 272aa4c95c..27df47276c 100644 --- a/Tests/JSSpecCompiler/test-runner.cpp +++ b/Tests/JSSpecCompiler/test-runner.cpp @@ -49,6 +49,7 @@ const Array regression_tests = { }, TestDescription { .sources = { + "spec-no-new-line-after-dot.xml"sv, "spec-single-function-simple.xml"sv, }, .flags = { dump_after_frontend },