Grammar: Converted from std::set to std::vector to preserve ordering

This commit is contained in:
Paul Beckingham 2015-12-25 22:54:25 -05:00
parent 9b126699e7
commit c73464b39f
2 changed files with 8 additions and 9 deletions

View file

@ -144,24 +144,24 @@ std::string Grammar::start () const
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
std::set <std::string> Grammar::rules () const std::vector <std::string> Grammar::rules () const
{ {
std::set <std::string> results; std::vector <std::string> results;
for (auto& rule : _rules) for (auto& rule : _rules)
results.insert (rule.first); results.push_back (rule.first);
return results; return results;
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
std::set <std::string> Grammar::terminals () const std::vector <std::string> Grammar::terminals () const
{ {
std::set <std::string> results; std::vector <std::string> results;
for (auto& rule : _rules) for (auto& rule : _rules)
for (auto& production : rule.second) for (auto& production : rule.second)
for (auto& token : production) for (auto& token : production)
if (_rules.find (token._token) == _rules.end ()) if (_rules.find (token._token) == _rules.end ())
results.insert (token._token); results.push_back (token._token);
return results; return results;
} }

View file

@ -29,7 +29,6 @@
#include <FS.h> #include <FS.h>
#include <string> #include <string>
#include <set>
#include <vector> #include <vector>
#include <map> #include <map>
@ -40,8 +39,8 @@ public:
void loadFromFile (File&); void loadFromFile (File&);
void loadFromString (const std::string&); void loadFromString (const std::string&);
std::string start () const; std::string start () const;
std::set <std::string> rules () const; std::vector <std::string> rules () const;
std::set <std::string> terminals () const; std::vector <std::string> terminals () const;
std::string dump () const; std::string dump () const;
protected: protected: