mirror of
https://github.com/GothenburgBitFactory/timewarrior.git
synced 2025-07-07 20:06:39 +02:00
Grammar: Diagnostics now controlled by ::debug
This commit is contained in:
parent
3829415d19
commit
63df5ba992
1 changed files with 10 additions and 0 deletions
|
@ -28,6 +28,7 @@
|
||||||
#include <Grammar.h>
|
#include <Grammar.h>
|
||||||
#include <Lexer.h>
|
#include <Lexer.h>
|
||||||
#include <text.h>
|
#include <text.h>
|
||||||
|
#include <iostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -134,6 +135,9 @@ void Grammar::loadFromString (const std::string& input)
|
||||||
rule_name = "";
|
rule_name = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (_debug)
|
||||||
|
std::cout << dump () << "\n";
|
||||||
|
|
||||||
// Validate the parsed grammar.
|
// Validate the parsed grammar.
|
||||||
validate ();
|
validate ();
|
||||||
}
|
}
|
||||||
|
@ -228,6 +232,9 @@ std::string Grammar::dump () const
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
void Grammar::validate () const
|
void Grammar::validate () const
|
||||||
{
|
{
|
||||||
|
if (_debug)
|
||||||
|
std::cout << "Validating...\n";
|
||||||
|
|
||||||
if (_start == "")
|
if (_start == "")
|
||||||
throw std::string ("There are no rules defined.");
|
throw std::string ("There are no rules defined.");
|
||||||
|
|
||||||
|
@ -280,6 +287,9 @@ void Grammar::validate () const
|
||||||
for (auto& nu : notUsed)
|
for (auto& nu : notUsed)
|
||||||
if (nu != _start)
|
if (nu != _start)
|
||||||
throw format ("Definition '{1}' is defined, but not referenced.", nu);
|
throw format ("Definition '{1}' is defined, but not referenced.", nu);
|
||||||
|
|
||||||
|
if (_debug)
|
||||||
|
std::cout << "Validated\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue