diff --git a/src/Grammar.cpp b/src/Grammar.cpp index f6d64365..b82cbab4 100644 --- a/src/Grammar.cpp +++ b/src/Grammar.cpp @@ -111,15 +111,16 @@ void Grammar::loadFromString (const std::string& input) } else if (token.front () == ':') { - // TODO Handle decorated tokens here. - _rules[rule_name].back ().decorate (token); + // Decorate the most recent token, of the most recent production, + // of the current rule. + _rules[rule_name].back ().back ().decorate (token); } else { if (token_count <= 1) _rules[rule_name].push_back (Grammar::Production ()); - _rules[rule_name].back ().push_back (token); + _rules[rule_name].back ().push_back (Grammar::Token (token)); } } } @@ -143,7 +144,11 @@ std::string Grammar::dump () const { out << " "; for (auto& term : production) - out << term << " "; + { + out << term._token << " "; + if (term._decoration != "") + out << "(" << term._decoration << ") "; + } out << "\n"; } diff --git a/src/Grammar.h b/src/Grammar.h index 89fb65e4..0f6ee07f 100644 --- a/src/Grammar.h +++ b/src/Grammar.h @@ -41,10 +41,18 @@ public: std::string dump () const; protected: - class Production : public std::vector + class Token { public: - void decorate (const std::string& value) {} + Token (const std::string& value) { _token = value; } + void decorate (const std::string& value) { _decoration = value; } + + std::string _token; + std::string _decoration; + }; + + class Production : public std::vector + { }; class Rule : public std::vector