Esempio n. 1
0
static Value* parseToken(const char** expr, parser_cb* cb) {
	Value* ret;
	
	char* token = nextToken(expr);
	if(token == NULL) {
		return ValErr(badChar(**expr));
	}
	
	trimSpaces(expr);
	if(**expr == '(') {
		(*expr)++;
		ArgList* arglist = ArgList_parse(expr, ',', ')', cb);
		if(arglist == NULL) {
			/* Parse error occurred and has already been raised */
			free(token);
			return ValErr(ignoreError());
		}
		
		ret = ValCall(FuncCall_create(token, arglist));
	}
	else {
		ret = ValVar(token);
	}
	
	free(token);
	return ret;
}
Esempio n. 2
0
Value* Vector_parse(const char** expr) {
	ArgList* vals = ArgList_parse(expr, ',', '>');
	if(vals == NULL)
		return ValErr(ignoreError());
	
	if(vals->count < 2) {
		ArgList_free(vals);
		return ValErr(syntaxError("Vector must have at least 2 components."));
	}
	
	return ValVec(Vector_new(vals));
}
Esempio n. 3
0
Value* Vector_parse(const char** expr, parser_cb* cb) {
    ArgList* vals = ArgList_parse(expr, ',', '>', cb);

    if(vals == NULL) {
        /* Error occurred and has already been raised */
        return ValErr(ignoreError());
    }

    if(vals->count < 1) {
        ArgList_free(vals);
        return ValErr(syntaxError("Vector must have at least 1 component."));
    }

    return ValVec(Vector_new(vals));
}
Esempio n. 4
0
static Value* callFunc(Value* val, const char** expr, parser_cb* cb) {
	/* Ugly, but parses better. Only variables and the results of calls can be funcs */
	if(val->type != VAL_VAR && val->type != VAL_CALL && val->type != VAL_PLACE) {
		return val;
	}
	
	/* Move past the opening parenthesis */
	(*expr)++;
	
	ArgList* args = ArgList_parse(expr, ',', ')', cb);
	if(args == NULL) {
		Value_free(val);
		return ValErr(ignoreError());
	}
	
	return ValCall(FuncCall_new(val, args));
}