From f4605a1bc775c820a04cca413c267cd52fb40cbc Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sat, 31 May 2014 13:52:59 -0400 Subject: [PATCH] Parser - Implemented ::capture_last, so that new args can be injected at either end of the command line. --- src/Parser.cpp | 16 ++++++++++++++++ src/Parser.h | 1 + 2 files changed, 17 insertions(+) diff --git a/src/Parser.cpp b/src/Parser.cpp index 0b97a2dc2..8ace3463c 100644 --- a/src/Parser.cpp +++ b/src/Parser.cpp @@ -531,6 +531,22 @@ Tree* Parser::captureFirst (const std::string& arg) return t; } +//////////////////////////////////////////////////////////////////////////////// +Tree* Parser::captureLast (const std::string& arg) +{ + // Insert the arg as the new first branch. + Tree* t = new Tree ("argIns"); + if (!t) + throw std::string (STRING_ERROR_MEMORY); + + t->attribute ("raw", arg); + t->tag ("?"); + t->_trunk = _tree; + + _tree->_branches.push_back (t); + return t; +} + //////////////////////////////////////////////////////////////////////////////// const std::string Parser::getFilterExpression () { diff --git a/src/Parser.h b/src/Parser.h index 0f8440fbe..ea09b5353 100644 --- a/src/Parser.h +++ b/src/Parser.h @@ -57,6 +57,7 @@ public: void applyOverrides (); void injectDefaults (); Tree* captureFirst (const std::string&); + Tree* captureLast (const std::string&); const std::string getFilterExpression (); const std::vector getWords () const;