Grammar: Upgraded tokens from std::string to full object

This commit is contained in:
Paul Beckingham 2015-12-22 08:06:20 -05:00
parent 29cb35123a
commit 6fac8a4a54
2 changed files with 19 additions and 6 deletions

View file

@ -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";
}

View file

@ -41,10 +41,18 @@ public:
std::string dump () const;
protected:
class Production : public std::vector <std::string>
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 <Token>
{
};
class Rule : public std::vector <Production>