CLI2: Added ::defaultCommand

This commit is contained in:
Paul Beckingham 2015-06-14 17:49:16 -04:00
parent 81844753fd
commit f59724297f
2 changed files with 32 additions and 30 deletions

View file

@ -436,7 +436,12 @@ void CLI2::analyze ()
// Process _args. // Process _args.
aliasExpansion (); aliasExpansion ();
findOverrides (); findOverrides ();
findCommand (); if (! findCommand ())
{
defaultCommand ();
if (! findCommand ())
throw std::string (STRING_TRIVIAL_INPUT);
}
if (context.config.getInteger ("debug.parser") >= 3) if (context.config.getInteger ("debug.parser") >= 3)
{ {
@ -1914,31 +1919,25 @@ void CLI2::insertJunctions ()
context.debug (dump ("CLI2::analyze insertJunctions")); context.debug (dump ("CLI2::analyze insertJunctions"));
} }
} }
*/
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void CLI2::injectDefaults () void CLI2::defaultCommand ()
{ {
// Scan the top-level branches for evidence of ID, UUID, overrides and other // Scan the top-level branches for evidence of ID, UUID, overrides and other
// arguments. // arguments.
bool changes = false; bool changes = false;
bool found_command = false; bool found_command = false;
bool found_sequence = false; bool found_sequence = false;
bool found_terminator = false;
for (auto& a : _args) for (auto& a : _args)
{ {
std::string raw = a.attribute ("raw"); std::string raw = a.attribute ("raw");
if (isTerminator (raw))
found_terminator = true;
if (! found_terminator && isCommand (raw)) if (a.hasTag ("CMD"))
found_command = true; found_command = true;
else if (! found_terminator && if (a._lextype == Lexer::Type::uuid ||
(isUUIDList (raw) || a._lextype == Lexer::Type::number)
isUUID (raw) ||
isIDSequence (raw) ||
isID (raw)))
found_sequence = true; found_sequence = true;
} }
@ -1952,48 +1951,49 @@ void CLI2::injectDefaults ()
std::string defaultCommand = context.config.get ("default.command"); std::string defaultCommand = context.config.get ("default.command");
if (defaultCommand != "") if (defaultCommand != "")
{ {
// Split the defaultCommand into separate args.
std::vector <std::string> tokens = Lexer::split (defaultCommand);
// Modify _args to be: <args0> [<def0> ...] <args1> [...] // Modify _args to be: <args0> [<def0> ...] <args1> [...]
std::vector <A> reconstructed; std::vector <A2> reconstructed;
for (auto a = _args.begin (); a != _args.end (); ++a) for (auto a = _args.begin (); a != _args.end (); ++a)
{ {
// This stores the argument, and has the side effect of positioning
// insertions *after* the CMD.
reconstructed.push_back (*a); reconstructed.push_back (*a);
if (a == _args.begin ()) if (a == _args.begin ())
{ {
for (auto& token : tokens) std::string lexeme;
Lexer::Type type;
Lexer lex (defaultCommand);
lex.ambiguity (false);
while (lex.token (lexeme, type))
{ {
A arg ("argDefault", token); A2 cmd (lexeme, type);
arg.tag ("DEFAULT"); cmd.tag ("DEFAULT");
reconstructed.push_back (arg); reconstructed.push_back (cmd);
} }
} }
} }
_args = reconstructed; _args = reconstructed;
} changes = true;
// Only an error in strict mode.
else if (_strict)
{
throw std::string (STRING_TRIVIAL_INPUT);
} }
} }
else else
{ {
A info ("argDefault", "information"); A2 info ("information", Lexer::Type::word);
info.tag ("ASSUMED"); info.tag ("DEFAULT");
_args.push_back (info); _args.push_back (info);
changes = true;
} }
} }
if (changes && if (changes &&
context.config.getInteger ("debug.parser") >= 3) context.config.getInteger ("debug.parser") >= 3)
context.debug (dump ("CLI2::analyze injectDefaults")); context.debug (dump ("CLI2::analyze defaultCommand"));
} }
/*
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void CLI2::decomposeModAttributes () void CLI2::decomposeModAttributes ()
{ {

View file

@ -130,7 +130,9 @@ private:
void findOperators (); void findOperators ();
void findAttributes (); void findAttributes ();
void insertJunctions (); void insertJunctions ();
void injectDefaults (); */
void defaultCommand ();
/*
void decomposeModAttributes (); void decomposeModAttributes ();
void decomposeModAttributeModifiers (); void decomposeModAttributeModifiers ();
void decomposeModTags (); void decomposeModTags ();