- Added a strict analysis mode that throws errors. In non-strict mode no errors
  are thrown because parsing is incomplete most of the time, and only the final
  pass needs to be strict.
This commit is contained in:
Paul Beckingham 2014-11-08 14:00:39 -05:00
parent 11d210a7c7
commit b9b998c769
3 changed files with 10 additions and 8 deletions

View file

@ -219,6 +219,7 @@ const std::string A::dump () const
////////////////////////////////////////////////////////////////////////////////
CLI::CLI ()
: _strict (false)
{
}
@ -283,13 +284,16 @@ void CLI::add (const std::string& arg)
// Intended to be called after ::initialize() and ::add(), to perform the final
// analysis. Analysis is also performed directly after the above, because there
// is a need to extract overrides early, before entities are proviedd.
void CLI::analyze (bool parse /* = true */)
void CLI::analyze (bool parse /* = true */, bool strict /* = false */)
{
// Clean what needs to be cleaned. Most in this case.
_args.clear ();
_id_ranges.clear ();
_uuid_list.clear ();
// For propagation.
_strict = strict;
for (int i = 0; i < _original_args.size (); ++i)
{
if (i == 0)
@ -1785,13 +1789,10 @@ void CLI::injectDefaults ()
context.header ("[" + combined + "]");
}
// TODO This fails because when ::injectDefaults is first run,
// ::applyOverrides has not yet been called.
else
// Only an error in strict mode.
else if (_strict)
{
/*
throw std::string (STRING_TRIVIAL_INPUT);
*/
}
}
else

View file

@ -73,7 +73,7 @@ public:
void entity (const std::string&, const std::string&);
void initialize (int, const char**);
void add (const std::string&);
void analyze (bool parse = true);
void analyze (bool parse = true, bool strict = false);
void applyOverrides ();
void getOverride (std::string&, File&);
void getDataLocation (Path&);
@ -132,6 +132,7 @@ public:
std::vector <std::pair <int, int> > _id_ranges;
std::vector <std::string> _uuid_list;
bool _strict;
};
#endif

View file

@ -209,7 +209,7 @@ int Context::initialize (int argc, const char** argv)
cli.entity ("attribute", col->first);
staticInitialization (); // Decouple code from Context.
cli.analyze (); // Parse all elements.
cli.analyze (true, true); // Parse all elements, strict mode.
tdb2.set_location (data_dir); // Prepare the task database.