index.js
function parseEsprima(input, fromFactory){

    var type = input.type;

    if(type === esprimaType.value){
        return input.value;
    }


    if(type === esprimaType.policy){

        var policyName = input.name;

        if(fromFactory){
            return require(sails.config.paths.policies + '/' + policyName);
        }

        return policyName;
    }


    if(type === esprimaType.factory){

        var factoryName = input.callee.name;

        try {
            var factory = require(sails.config.paths.policyFactories + '/' + factoryName);
        } catch (e) {
            return require(sails.config.paths.policies + '/' + factoryName);
        }

        var args = input.arguments.map(function(arg){
            return this.parseEsprima(arg, true);
        }, this);

        return factory.apply(this, args);
    }


    throw new Error('esprima type unhandled: ' + type);
}
function parseEsprima(input, fromFactory){

    var type = input.type;

    if(type === esprimaType.value){
        return input.value;
    }


    if(type === esprimaType.policy){

        var policyName = input.name;

        if(fromFactory){
            return require(sails.config.paths.policies + '/' + policyName);
        }

        return policyName;
    }


    if(type === esprimaType.factory){

        var factoryName = input.callee.name;

        try {
            var factory = require(sails.config.paths.policyFactories + '/' + factoryName);
        } catch (e) {
            return require(sails.config.paths.policies + '/' + factoryName);
        }

        var args = input.arguments.map(function(arg){
            return this.parseEsprima(arg, true);
        }, this);

        return factory.apply(this, args);
    }


    throw new Error('esprima type unhandled: ' + type);
}
/*
input [Esprima Object]
fromFactory [Boolean] set to true the result will be interpreted by a factory