llvm/flang/lib/parser/debug-parser.h
peter klausler 424ec7b35b [flang] Handle empty files gracefully.
Create interval.h.  Use std::size_t instead of bare size_t.  Redefine parser::Name to not be just a bare string.

Break out and rename CharBlock from token-sequence.h for use in the parse tree.

Incremental replacement of name strings with pointers to cooked characters.

Fix case sensitivity problem.

Use new CharBlock encoding to replace strings for real literal constants.

Normalized cooked character stream to lower case.

Simplify parsing now that cooked stream is lower case.  Replace Keyword in parse tree.

Add static_asserts to || and recovery parsers to enforce same result types.

Remove needless TODO comment inserted earlier.

Fix case conversion on prefixed character literals (f90_correct/dc04.f90).

Use CharBlock in user-state.h.

Complete transition from nextChar to nextCh (i.e., always use pointers).

Document extensions.  Begin work on compiler directive lines.

More documentation work.

Reformat prescan.cc.

More work on compiler directive scanning.

Original-commit: flang-compiler/f18@38d0404e16
Reviewed-on: https://github.com/flang-compiler/f18/pull/29
Tree-same-pre-rewrite: false
2018-03-23 13:32:55 -07:00

44 lines
1.2 KiB
C++

#ifndef FORTRAN_PARSER_DEBUG_PARSER_H_
#define FORTRAN_PARSER_DEBUG_PARSER_H_
// Implements the parser with syntax "(YOUR MESSAGE HERE)"_debug for use
// in temporary modifications to the grammar intended for tracing the
// flow of the parsers. Not to be used in production.
#include "basic-parsers.h"
#include "parse-state.h"
#include <cstddef>
#include <iostream>
#include <optional>
#include <string>
namespace Fortran {
namespace parser {
class DebugParser {
public:
using resultType = Success;
constexpr DebugParser(const DebugParser &) = default;
constexpr DebugParser(const char *str, std::size_t n)
: str_{str}, length_{n} {}
std::optional<Success> Parse(ParseState *state) const {
if (auto context = state->context()) {
context->Emit(std::cout, *state->cooked().allSources());
}
state->cooked().allSources()->Identify(
std::cout, state->GetProvenance(), "");
std::cout << " parser debug: " << std::string{str_, length_} << '\n';
return {Success{}};
}
private:
const char *const str_;
std::size_t length_;
};
constexpr DebugParser operator""_debug(const char str[], std::size_t n) {
return DebugParser{str, n};
}
} // namespace parser
} // namespace Fortran
#endif // FORTRAN_PARSER_DEBUG_PARSER_H_