From 8b904a57f4cac2e5eb5ae1f7824e2a24fabf69ce Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sun, 24 Aug 2014 16:09:30 -0400 Subject: [PATCH] Parser - ::findPattern was performing the wrong scan, and needed branch pruning outside the iterator loop. --- src/Parser.cpp | 60 +++++++++++++++++++++++++------------------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/src/Parser.cpp b/src/Parser.cpp index 20e7b92b7..e6d5834e7 100644 --- a/src/Parser.cpp +++ b/src/Parser.cpp @@ -805,43 +805,43 @@ std::string Parser::getCommand () const // /pattern/ --> description ~ pattern void Parser::findPattern () { -// context.debug ("Parser::findPattern"); - - std::vector prune; - std::vector nodes; - collect (nodes, collectAll); - std::vector ::iterator i; - for (i = nodes.begin (); i != nodes.end (); ++i) + bool action = true; + do { - Nibbler n ((*i)->attribute ("raw")); - std::string pattern; - if (n.getQuoted ('/', pattern) && - n.depleted () && - pattern.length () > 0) + action = false; + + std::vector prune; + std::vector nodes; + collect (nodes); + std::vector ::iterator i; + for (i = nodes.begin (); i != nodes.end (); ++i) { - (*i)->unTag ("?"); - (*i)->tag ("PATTERN"); - prune.push_back (*i); + Nibbler n ((*i)->attribute ("raw")); + std::string pattern; + if (n.getQuoted ('/', pattern) && + n.depleted () && + pattern.length () > 0) + { + (*i)->unTag ("?"); + (*i)->tag ("PATTERN"); + (*i)->removeAllBranches (); - Tree* branch = (*i)->addBranch (new Tree ("argPat")); - branch->attribute ("raw", "description"); + Tree* branch = (*i)->addBranch (new Tree ("argPat")); + branch->attribute ("raw", "description"); - branch = (*i)->addBranch (new Tree ("argPat")); - branch->attribute ("raw", "~"); - branch->tag ("OP"); + branch = (*i)->addBranch (new Tree ("argPat")); + branch->attribute ("raw", "~"); + branch->tag ("OP"); - branch = (*i)->addBranch (new Tree ("argPat")); - branch->attribute ("raw", pattern); - branch->tag ("STRING"); + branch = (*i)->addBranch (new Tree ("argPat")); + branch->attribute ("raw", pattern); + branch->tag ("STRING"); + action = true; + break; + } } } - - // Prune branches outside the loop. - for (i = prune.begin (); i != prune.end (); ++i) - (*i)->removeAllBranches (); - -// if (prune.size ()) -// context.debug (_tree->dump ()); + while (action); } ////////////////////////////////////////////////////////////////////////////////