From c65b30fbbacfb9eb271896e9ae2790f149d9011a Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Thu, 3 Jul 2014 22:40:43 -0400 Subject: [PATCH] Parser - Implemented ::resolveAliases to expand them. --- src/Parser.cpp | 48 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/src/Parser.cpp b/src/Parser.cpp index fbc34f645..9702ecfec 100644 --- a/src/Parser.cpp +++ b/src/Parser.cpp @@ -25,7 +25,6 @@ //////////////////////////////////////////////////////////////////////////////// #include -#include #include #include #include @@ -47,6 +46,9 @@ extern Context context; // Overridden by rc.abbreviation.minimum. static int minimumMatchLength = 3; +// Alias expansion limit. Any more indicates some kind of error. +static int safetyValveDefault = 10; + //////////////////////////////////////////////////////////////////////////////// Parser::Parser () { @@ -331,6 +333,50 @@ void Parser::findTerminator () //////////////////////////////////////////////////////////////////////////////// void Parser::resolveAliases () { + bool something; + int safety_valve = safetyValveDefault; + + do + { + something = false; + std::vector ::iterator i; + for (i = _tree->_branches.begin (); i != _tree->_branches.end (); ++i) + { + // Parser override operator. + if ((*i)->attribute ("raw") == "--") + break; + + std::map ::iterator a; + if ((*i)->_branches.size ()) + { + std::vector ::iterator b; + for (b = (*i)->_branches.begin (); b != (*i)->_branches.end (); ++b) + { + a = _aliases.find ((*b)->attribute ("raw")); + if (a != _aliases.end ()) + { + (*b)->attribute ("raw", a->second); + (*b)->tag ("ALIAS"); + something = true; + } + } + } + else + { + a = _aliases.find ((*i)->attribute ("raw")); + if (a != _aliases.end ()) + { + (*i)->attribute ("raw", a->second); + (*i)->tag ("ALIAS"); + something = true; + } + } + } + } + while (something && --safety_valve > 0); + + if (safety_valve <= 0) + context.debug (format ("Nested alias limit of {1} reached.", safetyValveDefault)); } ////////////////////////////////////////////////////////////////////////////////