From 967be9e750221ab2ab783f95df79bb26d290a45e Mon Sep 17 00:00:00 2001 From: Martial Simon Date: Mon, 15 Sep 2025 01:07:58 +0200 Subject: add: added projects --- tiger-compiler/src/parse/tweast.hh | 79 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 tiger-compiler/src/parse/tweast.hh (limited to 'tiger-compiler/src/parse/tweast.hh') diff --git a/tiger-compiler/src/parse/tweast.hh b/tiger-compiler/src/parse/tweast.hh new file mode 100644 index 0000000..910f694 --- /dev/null +++ b/tiger-compiler/src/parse/tweast.hh @@ -0,0 +1,79 @@ +/** + ** \file parse/tweast.hh + ** \brief Declaration of parse::Tweast. + */ + +#pragma once + +#include +#include +#include + +#include + +#include +#include +#include + +namespace parse +{ + /// \brief TWEAST stands for ``Text With Embedded Abstract Syntax Trees''. + /// + /// Aggregate string to parse and tables of metavariables. + class Tweast + : public MetavarMap + , public MetavarMap + , public MetavarMap + , public MetavarMap + , public MetavarMap + { + public: + Tweast(); + Tweast(const std::string& str); + + /// \brief Stream manipulator. + /// + /// Append Tiger expressions to the string to parse. + template Tweast& operator<<(const T& t); + + /// Metavariables manipulator. + template T* take(unsigned s); + + /// Move the contents of all aggregated Tweast metavariables into + /// the current Tweast. + void flatten(); + + /// Get the current input string. + std::string input_get() const; + + /// Print the table + std::ostream& dump(std::ostream& ostr) const; + + protected: + // Insert base class members in the current scope. + using MetavarMap::append_; + using MetavarMap::append_; + using MetavarMap::append_; + using MetavarMap::append_; + using MetavarMap::append_; + + /// Fake append (default case, i.e. when \a data is not a metavariable). + template T& append_(unsigned&, T& data) const; + + template + void move_metavars_(Tweast& tweast, std::string& input); + + protected: + /// The next identifier suffix to create. + static unsigned count_; + + /// The string to parse. + std::stringstream input_; + }; + + /// Display the content of the tweast. + std::ostream& operator<<(std::ostream& ostr, const Tweast& in); + +} // namespace parse + +#include -- cgit v1.2.3