1 | //===-- lib/Parser/debug-parser.h -------------------------------*- C++ -*-===// |
2 | // |
3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | // See https://llvm.org/LICENSE.txt for license information. |
5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | |
9 | #ifndef FORTRAN_PARSER_DEBUG_PARSER_H_ |
10 | #define FORTRAN_PARSER_DEBUG_PARSER_H_ |
11 | |
12 | // Implements the parser with syntax "(YOUR MESSAGE HERE)"_debug for use |
13 | // in temporary modifications to the grammar intended for tracing the |
14 | // flow of the parsers. Not to be used in production. |
15 | |
16 | #include "basic-parsers.h" |
17 | #include "flang/Parser/parse-state.h" |
18 | #include <cstddef> |
19 | #include <optional> |
20 | |
21 | namespace Fortran::parser { |
22 | |
23 | class DebugParser { |
24 | public: |
25 | using resultType = Success; |
26 | constexpr DebugParser(const DebugParser &) = default; |
27 | constexpr DebugParser(const char *str, std::size_t n) |
28 | : str_{str}, length_{n} {} |
29 | std::optional<Success> Parse(ParseState &) const; |
30 | |
31 | private: |
32 | const char *const str_; |
33 | const std::size_t length_; |
34 | }; |
35 | |
36 | constexpr DebugParser operator""_debug (const char str[], std::size_t n) { |
37 | return DebugParser{str, n}; |
38 | } |
39 | } // namespace Fortran::parser |
40 | #endif // FORTRAN_PARSER_DEBUG_PARSER_H_ |
41 | |