mirror of
https://github.com/GothenburgBitFactory/timewarrior.git
synced 2025-07-07 20:06:39 +02:00
timew: Instantiates Grammar
This commit is contained in:
parent
a5922b7797
commit
801f39d2fa
3 changed files with 31 additions and 0 deletions
|
@ -26,6 +26,7 @@
|
||||||
|
|
||||||
#include <cmake.h>
|
#include <cmake.h>
|
||||||
#include <Grammar.h>
|
#include <Grammar.h>
|
||||||
|
#include <text.h>
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
Grammar::Grammar ()
|
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.
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -27,10 +27,15 @@
|
||||||
#ifndef INCLUDED_GRAMMAR
|
#ifndef INCLUDED_GRAMMAR
|
||||||
#define INCLUDED_GRAMMAR
|
#define INCLUDED_GRAMMAR
|
||||||
|
|
||||||
|
#include <FS.h>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
class Grammar
|
class Grammar
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Grammar ();
|
Grammar ();
|
||||||
|
void loadFromFile (File&);
|
||||||
|
void loadFromString (const std::string&);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#include <cmake.h>
|
#include <cmake.h>
|
||||||
|
#include <Grammar.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <new>
|
#include <new>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
@ -45,6 +46,11 @@ int main (int argc, const char** argv)
|
||||||
{
|
{
|
||||||
// TODO Initialize configuration.
|
// TODO Initialize configuration.
|
||||||
// TODO Load grammar.
|
// 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 Load rules.
|
||||||
// TODO Parse CLI.
|
// TODO Parse CLI.
|
||||||
// TODO Dispatch to commands.
|
// TODO Dispatch to commands.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue