From c16fed3d9354f15efa67321d8170a7419571589d Mon Sep 17 00:00:00 2001 From: Slavomir Kucera Date: Mon, 4 Oct 2021 14:38:53 +0200 Subject: [PATCH] fix: DOT operator in string concatenation is optional --- clients/vscode-hlasmplugin/CHANGELOG.md | 1 + .../src/parsing/grammar/ca_expr_rules.g4 | 2 +- .../test/semantics/concatenation_test.cpp | 45 ++++++++++++++++++- 3 files changed, 46 insertions(+), 2 deletions(-) diff --git a/clients/vscode-hlasmplugin/CHANGELOG.md b/clients/vscode-hlasmplugin/CHANGELOG.md index 973aea7f5..c24485a20 100644 --- a/clients/vscode-hlasmplugin/CHANGELOG.md +++ b/clients/vscode-hlasmplugin/CHANGELOG.md @@ -24,6 +24,7 @@ - Attribute expressions ending with dot are not parsed correctly - Improve evaluation and diagnostics of conditional assembler expressions - Operands of dynamically generated statements may be incorrectly parsed +- DOT operator in string concatenation is optional ## [0.14.0](https://github.com/eclipse/che-che4z-lsp-for-hlasm/compare/0.13.0...0.14.0) (2021-08-18) diff --git a/parser_library/src/parsing/grammar/ca_expr_rules.g4 b/parser_library/src/parsing/grammar/ca_expr_rules.g4 index 63c4de2e2..320001f09 100644 --- a/parser_library/src/parsing/grammar/ca_expr_rules.g4 +++ b/parser_library/src/parsing/grammar/ca_expr_rules.g4 @@ -328,7 +328,7 @@ ca_string returns [ca_expr_ptr ca_expr] { $ca_expr = std::move($ca_string_b.ca_expr); } - | tmp=ca_string dot ca_string_b + | tmp=ca_string dot? ca_string_b { auto r = provider.get_range($tmp.ctx->getStart(), $ca_string_b.ctx->getStop()); $ca_expr = std::make_unique>(std::move($tmp.ca_expr), std::move($ca_string_b.ca_expr), r); diff --git a/parser_library/test/semantics/concatenation_test.cpp b/parser_library/test/semantics/concatenation_test.cpp index 94cdb84d7..ab3c513b4 100644 --- a/parser_library/test/semantics/concatenation_test.cpp +++ b/parser_library/test/semantics/concatenation_test.cpp @@ -14,6 +14,7 @@ #include "gmock/gmock.h" +#include "../common_testing.h" #include "semantics/concatenation_term.h" using namespace hlasm_plugin::parser_library::semantics; @@ -83,4 +84,46 @@ TEST(concatenation, contains_var_sym) EXPECT_EQ(var, nullptr); } -} \ No newline at end of file +} + +TEST(concatenation, no_dots) +{ + std::string input = R"( +&A SETC ' ' +&A SETC '&A'(1,1)'&A'(1,1) +)"; + analyzer a(input); + a.analyze(); + a.collect_diags(); + + EXPECT_TRUE(a.diags().empty()); + EXPECT_EQ(get_var_value(a.hlasm_ctx(), "A"), " "); +} + +TEST(concatenation, with_dots) +{ + std::string input = R"( +&A SETC ' ' +&A SETC '&A'(1,1).'&A'(1,1) +)"; + analyzer a(input); + a.analyze(); + a.collect_diags(); + + EXPECT_TRUE(a.diags().empty()); + EXPECT_EQ(get_var_value(a.hlasm_ctx(), "A"), " "); +} + +TEST(concatenation, no_dots_without_subscript) +{ + std::string input = R"( +&A SETC ' ' +&A SETC '&A''&A' +)"; + analyzer a(input); + a.analyze(); + a.collect_diags(); + + EXPECT_TRUE(a.diags().empty()); + EXPECT_EQ(get_var_value(a.hlasm_ctx(), "A"), " ' "); +}