mirror of
https://github.com/GothenburgBitFactory/timewarrior.git
synced 2025-07-27 12:16:25 +02:00
Rules: Implemented ::parseRule
This commit is contained in:
parent
65486032e0
commit
be88c0452d
1 changed files with 31 additions and 0 deletions
|
@ -274,6 +274,37 @@ void Rules::parse (const std::string& input, int nest /* = 1 */)
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
void Rules::parseRule (const std::string& input)
|
||||
{
|
||||
// Break the rule def into lines.
|
||||
auto lines = split (input, '\n');
|
||||
|
||||
// Tokenize the first line.
|
||||
std::vector <std::string> tokens;
|
||||
std::string token;
|
||||
Lexer::Type type;
|
||||
Lexer lexer (lines[0]);
|
||||
while (lexer.token (token, type))
|
||||
tokens.push_back (token);
|
||||
|
||||
// Based on the tokens of the first line, determine which rule stype needs to
|
||||
// be parsed.
|
||||
if (tokens.size () >= 2 &&
|
||||
tokens[0] == "define")
|
||||
{
|
||||
// define rule xxx:
|
||||
if (tokens.size () == 3 &&
|
||||
tokens[1] == "rule" &&
|
||||
tokens[2][tokens[2].length() - 1] == ':')
|
||||
parseRuleGeneral (lines);
|
||||
|
||||
// define theme:
|
||||
else if (tokens.size () == 2 &&
|
||||
tokens[1] == "theme:")
|
||||
parseRuleTheme (lines);
|
||||
|
||||
// Error.
|
||||
else
|
||||
throw format ("Unrecognized rule type '{1}'", join (" ", tokens));
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue