Esempio n. 1
0
void PackParser::onRawPack(const QByteArray &rawpack)
{
    bool isCompressed = rawpack[0] & 0x1;
    PACK_TYPE pack_type = PACK_TYPE((rawpack[0] & binL<110>::value) >> 0x1);
    QByteArray data_without_header = rawpack.right(rawpack.length()-1);
    if(isCompressed){
        QByteArray tmp = qUncompress(data_without_header);
        if(tmp.isEmpty()){
            qWarning()<<"bad input"<<data_without_header.toHex();
            return;
        }
        emit newPack(ParserResult(pack_type, tmp));
    }else{
        emit newPack(ParserResult(pack_type, data_without_header));
    }
}
Esempio n. 2
0
size_t Parser::run() {
std::vector<int> stack;
std::vector<Dynamic> ret;

ptr<Token> cur = tokens->pop();
if(isTOKEOS(cur)) return 0;

std::string fname = TOKSOF_data(cur);

cur = tokens->pop();
int cstate = entry_state;
//while(cur->id!=-3) {
while(!isTOKEOS(cur)) {
	int action = actions[cstate][isTOKEOF(cur) ? 0 : INDEX(cur)+2];
	switch(action&3) {
		case 0: //error
			results->push(ParserResult(fname, Dynamic ::null));
			
			//skip to end of file, or end of process token.
			while(!isTOKEOF(cur)) cur = tokens->pop();
			ret.clear();
			
			stack.clear();
			cstate = entry_state;
			cur = tokens->pop();
			if(!isTOKEOS(cur)) {
				fname = TOKSOF_data(cur);
				cur = tokens->pop();
			}

			break;
		case 1: //accept
			results->push(ParserResult(fname, Dynamic (ret.front())));

			ret.clear();
			
			stack.clear();
			cstate = entry_state;
			cur = tokens->pop();
			if(!isTOKEOS(cur)) {
				fname = TOKSOF_data(cur);
				cur = tokens->pop();
			}
			
			break;
		case 2: //shift
			ret.push_back(cur);
			stack.push_back(cstate);
			cstate = action >> 2;

			cur = tokens->pop();
		
			break;
		case 3: //reduce
			const RULE& c = rules[action>>2];
			(*(c.cb))(ret);
			
			if (c.cnt > 0) {
				for(int i = 0; i<(c.cnt-1); i++) stack.pop_back();
				cstate = stack.back();
			}else stack.push_back(cstate);
			
			cstate = actions[cstate][c.sym];
	}
}
	return 0;
}