static void _parse_ecma_array (AmfParser * parser, GstAmfNode * node) { int n_elements; int i; n_elements = _parse_u32 (parser); /* FIXME This is weird. The one time I've seen this, the encoded value * was 0, but the number of elements was 1. */ if (n_elements != 0) { GST_ERROR ("unimplemented, n_elements != 0"); } if (n_elements == 0) n_elements++; for (i = 0; i < n_elements; i++) { char *s; GstAmfNode *child_node; s = _parse_utf8_string (parser); child_node = _parse_value (parser); gst_amf_object_append_take (node, s, child_node); g_free (s); } _parse_u24 (parser); }
static enum RPC_Error _parse_pair(uchar **str, struct RPC_Node *node) { enum RPC_Error status; if( (node->children = calloc(2, sizeof *node)) == NULL ) return RPC_FAIL; if( (status=_parse_key(str,&node->children[0])) != RPC_OK ) { free(node->children); return status; } if( (status=_parse_value(str, &node->children[1])) != RPC_OK ) { _free_rpc_node(&node->children[0]); free(node->children); return status; } node->numChildren = 2; node->type = RPC_PAIR; return RPC_OK; }
int Configure::_parse_item(char*& src, ConfNode* item) { ConfNode* node = new ConfNode(ITEM); char token[CONF_LINE_NUM]; _parse_key(src, token); node->set_key(token); expect(src, ":"); node->set_father(item); node->add_to_tree(); _parse_value(src, token); node->set_value(token); return CONF_SUCC; };
GstAmfNode * gst_amf_node_new_parse (const guint8 * data, gsize size, gsize * n_bytes) { AmfParser _p = { 0 }, *parser = &_p; GstAmfNode *node; parser->data = data; parser->size = size; node = _parse_value (parser); if (n_bytes) *n_bytes = parser->offset; return node; }
Error VariantConstruct::parse(const String& p_string,Variant& r_ret,String &r_err_str,int &r_err_line,Variant::ObjectConstruct* p_construct,void* p_ud) { const CharType *str = p_string.ptr(); int idx = 0; int len = p_string.length(); Token token; r_err_line=0; String aux_key; Error err = _get_token(str,idx,len,token,r_err_line,r_err_str); if (err) return err; return _parse_value(r_ret,token,str,idx,len,r_err_line,r_err_str,p_construct,p_ud); }
static void _parse_object (AmfParser * parser, GstAmfNode * node) { while (1) { char *s; GstAmfNode *child_node; s = _parse_utf8_string (parser); child_node = _parse_value (parser); if (child_node->type == GST_AMF_TYPE_OBJECT_END) { g_free (s); gst_amf_node_free (child_node); break; } gst_amf_object_append_take (node, s, child_node); g_free (s); } }
Error JSON::parse(const String &p_json, Variant &r_ret, String &r_err_str, int &r_err_line) { const CharType *str = p_json.ptr(); int idx = 0; int len = p_json.length(); Token token; r_err_line = 0; String aux_key; Error err = _get_token(str, idx, len, token, r_err_line, r_err_str); if (err) return err; err = _parse_value(r_ret, token, str, idx, len, r_err_line, r_err_str); return err; }
Error VariantConstruct::_parse_array(Array &array,const CharType *p_str,int &index, int p_len,int &line,String &r_err_str,Variant::ObjectConstruct* p_construct,void* p_ud) { Token token; bool need_comma=false; while(index<p_len) { Error err = _get_token(p_str,index,p_len,token,line,r_err_str); if (err!=OK) return err; if (token.type==TK_BRACKET_CLOSE) { return OK; } if (need_comma) { if (token.type!=TK_COMMA) { r_err_str="Expected ','"; return ERR_PARSE_ERROR; } else { need_comma=false; continue; } } Variant v; err = _parse_value(v,token,p_str,index,p_len,line,r_err_str,p_construct,p_ud); if (err) return err; array.push_back(v); need_comma=true; } return OK; }
void eval_block(code *block, map* vars) { while (true) { code_skip_whitespace(block); if (block->source[block->pos] == '?') { uint8_t brackets = 0; size_t start, length = 0; mpz_t value; mpz_init(value); block->pos++; code_skip_whitespace(block); _parse_value(block, value, vars); code_skip_whitespace(block); start = block->pos + 1; while (true) { length++; if (block->source[block->pos] == '{') { brackets++; block->pos++; } else if (block->source[block->pos] == '}') { brackets--; block->pos++; if (brackets == 0) break; } else { block->pos++; } } if (mpz_sgn(value) == 0) { code subblock; code_init(&subblock); code_append(&subblock, block->source + start * sizeof(char), length - 2); eval_block(&subblock, vars); code_free(&subblock); } mpz_clear(value); } else if (block->source[block->pos] == '!') { mpz_t value; mpz_init(value); block->pos++; code_skip_whitespace(block); _parse_value(block, value, vars); mpz_out_str(stdout, 10, value); printf("\n"); mpz_clear(value); } else { char *var = malloc(1024 * sizeof(char)); mpz_t value; mpz_init(value); _parse_variable_name(block, var); code_skip_whitespace(block); switch (block->source[block->pos]) { case '=': block->pos++; code_skip_whitespace(block); _parse_value(block, value, vars); map_set(vars, var, value, false); break; case '+': block->pos += 2; code_skip_whitespace(block); _parse_value(block, value, vars); map_set(vars, var, value, true); break; case '-': block->pos += 2; code_skip_whitespace(block); _parse_value(block, value, vars); mpz_neg(value, value); map_set(vars, var, value, true); break; default: fprintf(stderr, "Parse error\n"); } free(var); mpz_clear(value); } code_skip_whitespace(block); if (block->pos >= block->length) return; if (block->source[block->pos] == ';') { block->pos++; } else { fprintf(stderr, "Missing ;\n"); return; } } }
Error VariantConstruct::_parse_dict(Dictionary &dict,const CharType *p_str,int &index, int p_len,int &line,String &r_err_str,Variant::ObjectConstruct* p_construct,void* p_ud) { bool at_key=true; Variant key; Token token; bool need_comma=false; while(index<p_len) { if (at_key) { Error err = _get_token(p_str,index,p_len,token,line,r_err_str); if (err!=OK) return err; if (token.type==TK_CURLY_BRACKET_CLOSE) { return OK; } if (need_comma) { if (token.type!=TK_COMMA) { r_err_str="Expected '}' or ','"; return ERR_PARSE_ERROR; } else { need_comma=false; continue; } } err = _parse_value(key,token,p_str,index,p_len,line,r_err_str,p_construct,p_ud); if (err!=OK) return err; err = _get_token(p_str,index,p_len,token,line,r_err_str); if (err!=OK) return err; if (token.type!=TK_COLON) { r_err_str="Expected ':'"; return ERR_PARSE_ERROR; } at_key=false; } else { Error err = _get_token(p_str,index,p_len,token,line,r_err_str); if (err!=OK) return err; Variant v; err = _parse_value(v,token,p_str,index,p_len,line,r_err_str,p_construct,p_ud); if (err) return err; dict[key]=v; need_comma=true; at_key=true; } } return OK; }