Пример #1
0
Tokens Parser::parse(){
	boost::smatch matches;
	boost::regex re;
	//re.assign("(?:\\n\\s*)?\\{\\.(!)?([^\\}\\s]*)(([^\\}\"\']([\"\'].*?[\"\'])?)*)\\}?",boost::regex_constants::icase);
	re.assign("(?:\\n\\s*)?\\{\\.(!)?([^\\}\\s]*)(.*?)(?<!\\\\)\\}",boost::regex_constants::icase);

	string leftovers = str;
	string::const_iterator begin,end;
	begin = str.begin();
	end = str.end();

	Tokens result;
	result.reserve(50);

	while(boost::regex_search(begin,end,matches,re)){
		string comm(matches[1].str());
		string func(matches[2].str());
		string parm(matches[3].str());
		string text(matches.prefix().str());

		if(text!=""){
			Token temp;
			temp.func = "ECHO";
			temp.param = text;
			result.push_back(temp);
		}
		if(comm==""){
			Token temp;
			temp.func = func;
			temp.param = parm;
			result.push_back(temp);
		}
		begin = matches.suffix().first;
		leftovers = matches.suffix().str();
	}

	if(leftovers!=""){
		Token temp;
		temp.func = "ECHO";
		temp.param = leftovers;
		result.push_back(temp);
	}

	return result;
}