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 <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.
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue