diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/cru/parse/ParsingAlgorithm.hpp | 22 | ||||
-rw-r--r-- | include/cru/parse/ParsingAlgorithmContext.hpp | 23 | ||||
-rw-r--r-- | include/cru/parse/ParsingContext.hpp | 21 |
3 files changed, 66 insertions, 0 deletions
diff --git a/include/cru/parse/ParsingAlgorithm.hpp b/include/cru/parse/ParsingAlgorithm.hpp new file mode 100644 index 00000000..1ea30a80 --- /dev/null +++ b/include/cru/parse/ParsingAlgorithm.hpp @@ -0,0 +1,22 @@ +#pragma once +#include "Grammar.hpp" + +namespace cru::parse { +class ParsingAlgorithmContext; + +// Represents a parsing algorithm. +// It does not relate to any specific grammar. +// It is used to validate a grammar and create a parsing algorithm context. +class ParsingAlgorithm { + public: + ParsingAlgorithm() = default; + + CRU_DELETE_COPY(ParsingAlgorithm) + CRU_DELETE_MOVE(ParsingAlgorithm) + + ~ParsingAlgorithm() = default; + + virtual bool CanHandle(Grammar* grammar) const = 0; + virtual ParsingAlgorithmContext* CreateContext(Grammar* grammar) const = 0; +}; +} // namespace cru::parse diff --git a/include/cru/parse/ParsingAlgorithmContext.hpp b/include/cru/parse/ParsingAlgorithmContext.hpp new file mode 100644 index 00000000..072203ec --- /dev/null +++ b/include/cru/parse/ParsingAlgorithmContext.hpp @@ -0,0 +1,23 @@ +#pragma once +#include "Grammar.hpp" + +namespace cru::parse { +class ParsingAlgorithm; + +// A parsing algorithm context contains all data a parsing algorithm needs to +// parse for a grammar. It does not relate to any input. For example, it can +// contain any state machine. +class ParsingAlgorithmContext { + public: + ParsingAlgorithmContext(Grammar* grammar, ParsingAlgorithm* algorithm); + + CRU_DELETE_COPY(ParsingAlgorithmContext) + CRU_DELETE_MOVE(ParsingAlgorithmContext) + + ~ParsingAlgorithmContext(); + + private: + Grammar* grammar_; + ParsingAlgorithm* algorithm_; +}; +} // namespace cru::parse diff --git a/include/cru/parse/ParsingContext.hpp b/include/cru/parse/ParsingContext.hpp new file mode 100644 index 00000000..369acf41 --- /dev/null +++ b/include/cru/parse/ParsingContext.hpp @@ -0,0 +1,21 @@ +#pragma once +#include "ParsingAlgorithmContext.hpp" + +namespace cru::parse { +// A parsing context contains all info that a program needs to know when parsing +// a input sequence of terminals. +class ParsingContext { + public: + ParsingContext(ParsingAlgorithmContext* parsing_algorithm_context, + std::vector<Terminal*> input); + + CRU_DELETE_COPY(ParsingContext) + CRU_DELETE_MOVE(ParsingContext) + + ~ParsingContext(); + + private: + ParsingAlgorithmContext* parsing_algorithm_context_; + std::vector<Terminal*> input_; +}; +} // namespace cru::parse |