From df917518ed8150a81f3d7f5089d12b275caaa9e3 Mon Sep 17 00:00:00 2001 From: Zhelyapov Aleksey Date: Mon, 1 Jul 2024 19:45:06 +0300 Subject: [PATCH] Fixed bug panda-runtime issue #14098 (nested multiline comment). Signed-off-by: Zhelyapov Aleksey --- ets2panda/lexer/ETSLexer.cpp | 52 +------------------ ets2panda/lexer/ETSLexer.h | 1 - .../parser/ets/comment_block-expected.txt | 2 +- ets2panda/test/parser/ets/comment_block.ets | 3 +- 4 files changed, 3 insertions(+), 55 deletions(-) diff --git a/ets2panda/lexer/ETSLexer.cpp b/ets2panda/lexer/ETSLexer.cpp index 607ae7b552..1cbb947551 100644 --- a/ets2panda/lexer/ETSLexer.cpp +++ b/ets2panda/lexer/ETSLexer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 - 2023 Huawei Device Co., Ltd. + * Copyright (c) 2021 - 2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -94,56 +94,6 @@ void ETSLexer::CheckUtf16Compatible(char32_t cp) const } } -void ETSLexer::SkipMultiLineComment() -{ - uint32_t depth = 1U; - - // Just to reduce extra nested level(s) - auto const checkAsterisk = [this, &depth]() -> bool { - if (Iterator().Peek() == LEX_CHAR_SLASH) { - Iterator().Forward(1); - - if (--depth == 0U) { - return false; - } - } - return true; - }; - - while (true) { - switch (Iterator().Next()) { - case util::StringView::Iterator::INVALID_CP: { - ThrowError("Unterminated multi-line comment"); - break; - } - case LEX_CHAR_LF: - case LEX_CHAR_CR: - case LEX_CHAR_LS: - case LEX_CHAR_PS: { - Pos().NextTokenLine()++; - continue; - } - case LEX_CHAR_ASTERISK: { - if (!checkAsterisk()) { - return; - } - break; - } - case LEX_CHAR_SLASH: { - if (Iterator().Peek() == LEX_CHAR_ASTERISK) { - Iterator().Forward(1); - depth++; - } - break; - } - - default: { - break; - } - } - } -} - void ETSLexer::ScanAsteriskPunctuator() { GetToken().type_ = TokenType::PUNCTUATOR_MULTIPLY; diff --git a/ets2panda/lexer/ETSLexer.h b/ets2panda/lexer/ETSLexer.h index 341c800aca..71f734e349 100644 --- a/ets2panda/lexer/ETSLexer.h +++ b/ets2panda/lexer/ETSLexer.h @@ -35,7 +35,6 @@ public: void NextToken(NextTokenFlags flags = NextTokenFlags::NONE) override; void ScanHashMark() override; bool ScanCharLiteral() override; - void SkipMultiLineComment() override; void ScanAsteriskPunctuator() override; void ScanNumberLeadingZero() override diff --git a/ets2panda/test/parser/ets/comment_block-expected.txt b/ets2panda/test/parser/ets/comment_block-expected.txt index 89446062c9..34161da49d 100644 --- a/ets2panda/test/parser/ets/comment_block-expected.txt +++ b/ets2panda/test/parser/ets/comment_block-expected.txt @@ -146,7 +146,7 @@ "column": 1 }, "end": { - "line": 34, + "line": 33, "column": 6 } } diff --git a/ets2panda/test/parser/ets/comment_block.ets b/ets2panda/test/parser/ets/comment_block.ets index 875515bd19..68dfeaa95b 100644 --- a/ets2panda/test/parser/ets/comment_block.ets +++ b/ets2panda/test/parser/ets/comment_block.ets @@ -21,8 +21,7 @@ /* /* - nested block - */ + block */ /* -- Gitee