2018-03-01 01:56:10 +01:00
|
|
|
#ifndef FORTRAN_PARSER_PARSING_H_
|
|
|
|
#define FORTRAN_PARSER_PARSING_H_
|
|
|
|
|
|
|
|
#include "characters.h"
|
|
|
|
#include "message.h"
|
|
|
|
#include "parse-tree.h"
|
|
|
|
#include "provenance.h"
|
2018-03-17 00:13:49 +01:00
|
|
|
#include <optional>
|
2018-03-01 01:56:10 +01:00
|
|
|
#include <ostream>
|
2018-03-17 00:13:49 +01:00
|
|
|
#include <string>
|
|
|
|
#include <utility>
|
|
|
|
#include <vector>
|
2018-03-01 01:56:10 +01:00
|
|
|
|
|
|
|
namespace Fortran {
|
|
|
|
namespace parser {
|
|
|
|
|
|
|
|
struct Options {
|
|
|
|
Options() {}
|
|
|
|
|
2018-03-17 00:13:49 +01:00
|
|
|
using Predefinition = std::pair<std::string, std::optional<std::string>>;
|
|
|
|
|
2018-03-01 01:56:10 +01:00
|
|
|
bool isFixedForm{false};
|
|
|
|
int fixedFormColumns{72};
|
|
|
|
bool enableBackslashEscapes{true};
|
|
|
|
bool enableOldDebugLines{false};
|
|
|
|
bool isStrictlyStandard{false};
|
|
|
|
Encoding encoding{Encoding::UTF8};
|
2018-03-17 00:13:49 +01:00
|
|
|
std::vector<std::string> searchDirectories;
|
|
|
|
std::vector<Predefinition> predefinitions;
|
2018-03-01 01:56:10 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
class Parsing {
|
|
|
|
public:
|
|
|
|
Parsing() {}
|
|
|
|
|
|
|
|
bool consumedWholeFile() const { return consumedWholeFile_; }
|
2018-03-29 02:15:00 +02:00
|
|
|
const char *finalRestingPlace() const { return finalRestingPlace_; }
|
2018-03-01 01:56:10 +01:00
|
|
|
Messages &messages() { return messages_; }
|
|
|
|
Program &parseTree() { return *parseTree_; }
|
|
|
|
|
|
|
|
bool Prescan(const std::string &path, Options);
|
|
|
|
void DumpCookedChars(std::ostream &) const;
|
|
|
|
void DumpProvenance(std::ostream &) const;
|
|
|
|
bool Parse();
|
|
|
|
|
2018-03-29 02:15:00 +02:00
|
|
|
void Identify(std::ostream &o, const char *at, const std::string &prefix,
|
2018-03-01 01:56:10 +01:00
|
|
|
bool echoSourceLine = false) const {
|
2018-03-29 21:16:10 +02:00
|
|
|
allSources_.Identify(
|
|
|
|
o, cooked_.GetProvenance(at).start(), prefix, echoSourceLine);
|
2018-03-01 01:56:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
Options options_;
|
|
|
|
AllSources allSources_;
|
2018-03-23 23:14:52 +01:00
|
|
|
CookedSource cooked_{allSources_};
|
|
|
|
Messages messages_{cooked_};
|
2018-03-01 01:56:10 +01:00
|
|
|
bool anyFatalError_{false};
|
|
|
|
bool consumedWholeFile_{false};
|
2018-03-29 02:15:00 +02:00
|
|
|
const char *finalRestingPlace_{nullptr};
|
2018-03-01 01:56:10 +01:00
|
|
|
std::optional<Program> parseTree_;
|
|
|
|
};
|
|
|
|
} // namespace parser
|
|
|
|
} // namespace Fortran
|
|
|
|
#endif // FORTRAN_PARSER_PARSING_H_
|