mirror of
https://github.com/GothenburgBitFactory/timewarrior.git
synced 2025-06-26 10:54:28 +02:00
Rules: Added parse stub
This commit is contained in:
parent
252fcab570
commit
38e7dbf68a
2 changed files with 35 additions and 1 deletions
|
@ -26,8 +26,30 @@
|
||||||
|
|
||||||
#include <cmake.h>
|
#include <cmake.h>
|
||||||
#include <Rules.h>
|
#include <Rules.h>
|
||||||
|
#include <FS.h>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Nested files are supported, with the following construct:
|
||||||
|
// import /absolute/path/to/file
|
||||||
|
void Rules::load (const std::string& file, int nest /* = 1 */)
|
||||||
|
{
|
||||||
|
if (nest > 10)
|
||||||
|
throw std::string ("Rules files may only be nested to 10 levels.");
|
||||||
|
|
||||||
|
// First time in, load the default values.
|
||||||
|
if (nest == 1)
|
||||||
|
{
|
||||||
|
// This is where defaults would be set.
|
||||||
|
_original_file = File (file);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read the file, then parse the contents.
|
||||||
|
std::string contents;
|
||||||
|
if (File::read (file, contents) && contents.length ())
|
||||||
|
parse (contents, nest);
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// define r:
|
// define r:
|
||||||
// name value
|
// name value
|
||||||
|
@ -40,9 +62,16 @@ std::string Rules::get (const std::string& rule, const std::string& name) const
|
||||||
std::string Rules::dump () const
|
std::string Rules::dump () const
|
||||||
{
|
{
|
||||||
std::stringstream out;
|
std::stringstream out;
|
||||||
out << "Rules\n";
|
out << "Rules\n"
|
||||||
|
<< " _original_file " << _original_file
|
||||||
|
<< "\n";
|
||||||
|
|
||||||
return out.str ();
|
return out.str ();
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
void Rules::parse (const std::string& input, int nest /* = 1 */)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -33,10 +33,15 @@ class Rules
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Rules () = default;
|
Rules () = default;
|
||||||
|
void load (const std::string&, int next = 1);
|
||||||
std::string get (const std::string&, const std::string&) const;
|
std::string get (const std::string&, const std::string&) const;
|
||||||
std::string dump () const;
|
std::string dump () const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void parse (const std::string&, int next = 1);
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::string _original_file {};
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue