Exemple #1
0
Value* Vector_eval(const Vector* vec, const Context* ctx) {
    ArgList* args = ArgList_eval(vec->vals, ctx);
    if(args == NULL) {
        return ValErr(ignoreError());
    }
    return ValVec(Vector_new(args));
}
Exemple #2
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;
}
Exemple #3
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));
}
Exemple #4
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));
}
Exemple #5
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));
}
Exemple #6
0
static Expression* parseExpr(const char** expr) {
	Variable* var;
	Value* val = Value_parse(expr, 0, 0);
	
	if(val->type == VAL_END) {
		var = VarErr(ignoreError());
	}
	else if(val->type == VAL_ERR) {
		Error* err = Error_copy(val->err);
		var = VarErr(err);
	}
	else {
		var = VarValue(NULL, Value_copy(val));
	}
	
	Value_free(val);
	
	return Expression_new(var);
}