1/**
2 * Copyright (c) 2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16#ifndef ES2PANDA_PARSER_CORE_ETS_NOLINT_PARSER_H
17#define ES2PANDA_PARSER_CORE_ETS_NOLINT_PARSER_H
18
19namespace ark::es2panda::parser {
20
21class ETSNolintParser {
22public:
23    explicit ETSNolintParser(const ParserImpl *mainParser);
24    void CollectETSNolints();
25    void ApplyETSNolintsToStatements(ArenaVector<ir::Statement *> &statements) const;
26
27private:
28    void SetStartPos();
29    void NextSymbol();
30    void BackwardSymbol();
31    void NextSymbol(std::size_t i);
32    void BackwardSymbol(std::size_t i);
33    void RewindToStart() const;
34
35    char32_t PeekSymbol() const;
36    bool TryPeekU32String(const std::u32string &str);
37    bool IsEtsNolint();
38    bool IsNextLine();
39    bool IsBegin();
40    bool IsEnd();
41
42    std::set<ETSWarnings> ParseETSNolintArgs();
43    bool ValidETSNolintArg(const std::u32string &warningName) const;
44    ETSWarnings MapETSNolintArg(const std::u32string &warningName) const;
45
46    void AddToETSNolintLinesCollection(std::size_t line, const std::set<ETSWarnings> &collection);
47    bool IsLineWithETSNolint(const std::size_t line) const;
48    std::set<ETSWarnings> GetWarningsCollectionByLine(std::size_t line) const;
49
50    void ApplyETSNolintsToNodesRecursively(ir::AstNode *node) const;
51
52    const ParserImpl *parser_;
53    std::size_t startPos_ = 0;
54    std::size_t posOffset_ = 0;
55    std::size_t line_ = 0;
56    std::set<ETSWarnings> applyingCollection_;
57    std::map<size_t, std::set<ETSWarnings>> linesCollection_;
58    std::map<std::u32string, ETSWarnings> warningsMap_;
59};
60}  // namespace ark::es2panda::parser
61#endif
62