timew: Instantiates Grammar

This commit is contained in:
Paul Beckingham 2015-12-20 16:20:15 -05:00
parent a5922b7797
commit 801f39d2fa
3 changed files with 31 additions and 0 deletions

View file

@ -26,6 +26,7 @@
#include <cmake.h>
#include <Grammar.h>
#include <text.h>
////////////////////////////////////////////////////////////////////////////////
Grammar::Grammar ()
@ -33,3 +34,22 @@ Grammar::Grammar ()
}
////////////////////////////////////////////////////////////////////////////////
void Grammar::loadFromFile (File& file)
{
if (file.exists ())
{
std::string contents;
file.read (contents);
loadFromString (contents);
}
else
throw format ("Grammar file '{0}'not found.", static_cast<std::string> (file));
}
////////////////////////////////////////////////////////////////////////////////
void Grammar::loadFromString (const std::string& input)
{
// TODO Load and parse BNF.
}
////////////////////////////////////////////////////////////////////////////////

View file

@ -27,10 +27,15 @@
#ifndef INCLUDED_GRAMMAR
#define INCLUDED_GRAMMAR
#include <FS.h>
#include <string>
class Grammar
{
public:
Grammar ();
void loadFromFile (File&);
void loadFromString (const std::string&);
};
#endif

View file

@ -25,6 +25,7 @@
////////////////////////////////////////////////////////////////////////////////
#include <cmake.h>
#include <Grammar.h>
#include <iostream>
#include <new>
#include <cstring>
@ -45,6 +46,11 @@ int main (int argc, const char** argv)
{
// TODO Initialize configuration.
// TODO Load grammar.
// TODO Load from string, else file on config override.
File file ("./grammar.cfg");
Grammar grammar;
grammar.loadFromFile (file);
// TODO Load rules.
// TODO Parse CLI.
// TODO Dispatch to commands.