char-buffer.cc
char-set.cc
characters.cc
-# debug-parser.cc # not to be used in production, it uses std::cout
+ debug-parser.cc
idioms.cc
instrumented-parser.cc
message.cc
#include "debug-parser.h"
-#include <iostream>
+#include "user-state.h"
+#include <ostream>
#include <string>
namespace Fortran {
std::optional<Success> DebugParser::Parse(ParseState &state) const {
if (auto ustate = state.userState()) {
- const CookedSource &cooked{ustate->cooked()};
- if (auto context = state.context()) {
- context->Emit(std::cout, cooked);
+ if (auto out = ustate->debugOutput()) {
+ const CookedSource &cooked{ustate->cooked()};
+ if (auto context = state.context()) {
+ context->Emit(*out, cooked);
+ }
+ Provenance p{cooked.GetProvenance(state.GetLocation()).start()};
+ cooked.allSources().Identify(*out, p, "", true);
+ *out << " parser debug: " << std::string{str_, length_} << "\n\n";
}
- Provenance p{cooked.GetProvenance(state.GetLocation()).start()};
- cooked.allSources().Identify(std::cout, p, "", true);
- std::cout << " parser debug: " << std::string{str_, length_} << "\n\n";
}
return {Success{}};
}
// 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.
-// When this feature is in use for temporary debugging, be sure to
-// compile and link debug-parser.cc.
#include "basic-parsers.h"
#include "parse-state.h"
log_.Dump(out, cooked_);
}
-void Parsing::Parse() {
+void Parsing::Parse(std::ostream *out) {
UserState userState{cooked_};
- userState.set_instrumentedParse(options_.instrumentedParse).set_log(&log_);
+ userState.set_debugOutput(out)
+ .set_instrumentedParse(options_.instrumentedParse)
+ .set_log(&log_);
ParseState parseState{cooked_};
parseState.set_inFixedForm(options_.isFixedForm)
.set_encoding(options_.encoding)
void DumpCookedChars(std::ostream &) const;
void DumpProvenance(std::ostream &) const;
void DumpParsingLog(std::ostream &) const;
- void Parse();
+ void Parse(std::ostream *debugOutput = nullptr);
void ClearLog();
void Identify(std::ostream &o, const char *at, const std::string &prefix,
#include "parse-tree.h"
#include <cinttypes>
#include <optional>
+#include <ostream>
#include <set>
#include <unordered_set>
const CookedSource &cooked() const { return cooked_; }
+ std::ostream *debugOutput() const { return debugOutput_; }
+ UserState &set_debugOutput(std::ostream *out) {
+ debugOutput_ = out;
+ return *this;
+ }
+
ParsingLog *log() const { return log_; }
UserState &set_log(ParsingLog *log) {
log_ = log;
private:
const CookedSource &cooked_;
+ std::ostream *debugOutput_{nullptr};
+
ParsingLog *log_{nullptr};
bool instrumentedParse_{false};
parsing.DumpCookedChars(std::cout);
return {};
}
- parsing.Parse();
+ parsing.Parse(&std::cout);
if (options.instrumentedParse) {
parsing.DumpParsingLog(std::cout);
return {};