00001 #include "rtreesubstitutionrule.h"
00002
00003 SubstitutionRule::SubstitutionRule(List* iphpInPattern, List* itplOutPattern, List* iphpOutPattern)
00004 : phpInPattern(iphpInPattern), tplOutPattern(itplOutPattern), phpOutPattern(iphpOutPattern) {};
00005
00006 bool SubstitutionRule::execute(RuleContext* context, List* phpIn, List* phpOut, List* tplOut,Node::Assignment &assign) const {
00007 if (phpInPattern->matchToBegining(phpIn,assign,context->getNameSpace())){
00008 List* phpOutMatched = dynamic_cast<List*>(phpOutPattern->copy());
00009 phpOutMatched->substitute(assign);
00010 List* tplOutMatched = dynamic_cast<List*>(tplOutPattern->copy());
00011 tplOutMatched->substitute(assign);
00012
00013
00014 for (int i=0 ; i<phpInPattern->getLength() ; i++){
00015 delete phpIn->front();
00016 phpIn->pop_front();
00017 };
00018 context->assignVariableNames(phpOutMatched,tplOutMatched);
00019 phpOut->append(phpOutMatched);
00020 tplOut->append(tplOutMatched);
00021 return true;
00022 }
00023 return false;
00024 };
00025
00026 Rule* SubstitutionRule::copy(){
00027 return new SubstitutionRule(phpInPattern->copyList(),
00028 tplOutPattern->copyList(),
00029 phpOutPattern->copyList());
00030 };
00031
00032 Rule* SubstitutionRule::substitute(const Node::Assignment &assign){
00033 phpInPattern->substitute(assign);
00034 tplOutPattern->substitute(assign);
00035 phpOutPattern->substitute(assign);
00036 return this;
00037 };
00038
00039 ostream& SubstitutionRule::print(ostream& os) const{
00040 os << "SubstitutionRule - ";
00041 phpInPattern->print(os);
00042
00043 return os;
00044 };