App-Mxpress-PDF

 view release on metacpan or  search on metacpan

public/javascripts/ace/worker-xquery.js  view on Meta::CPAN


        getNamespaces: function(){
            return this.root.namespaces;
        },
        
        getNamespace: function (uri) {
            var that = this;
            while (that) {
                var namespace = that.namespaces[uri];
                if (namespace) {
                    return namespace;
                }
                that = that.parent;
            }

        },

        getNamespaceByPrefix: function (prefix) {
            var found = [];
            var handler = function (uri) {
                var namespace = that.namespaces[uri];
                if (namespace.prefixes.indexOf(prefix) !== -1) {
                    namespace.uri = uri;
                    found.push(namespace);
                }
            };
            var that = this;
            while (that) {
                Object.keys(that.namespaces).forEach(handler);
                that = that.parent;
            }
            var result;
            found.forEach(function(ns){
                if(ns.type === 'moduleDecl') {
                    result = ns;
                }
            });
            if(result) {
                return result;
            } else {
                return found[0];
            }
        },
        
        resolveQName: function(value, pos){
            var qname = {
                uri: '',
                prefix: '',
                name: ''
            };
            var idx;
            if (value.substring(0, 2) === 'Q{') {
                idx = value.indexOf('}');
                qname.uri = value.substring(2, idx);
                qname.name = value.substring(idx + 1);
            } else {
                idx = value.indexOf(':');
                qname.prefix = value.substring(0, idx);
                var namespace = this.getNamespaceByPrefix(qname.prefix);
                if(!namespace && qname.prefix !== '' && ['fn', 'jn'].indexOf(qname.prefix) === -1) {
                    throw new StaticError('XPST0081', '"' + qname.prefix + '": can not expand prefix of lexical QName to namespace URI', pos);
                }
                if(namespace) {
                    qname.uri = namespace.uri;
                }
                qname.name = value.substring(idx + 1);
            }
            return qname;
        },
        
        variables: {},
        varRefs: {},
        functionCalls: {},
    
        addVariable: function(qname, type, pos){
            if(
                type === 'VarDecl' && this.moduleNamespace !== '' &&
                !(this.moduleNamespace === qname.uri || qname.uri === '')
            ) {
                throw new StaticError('XQST0048', '"' + qname.prefix + ':' + qname.name + '": Qname not library namespace', pos);
            }
            var key = getVarKey(qname);
            if(type === 'VarDecl' && this.variables[key]) {
                throw new StaticError('XQST0049', '"' + qname.name + '": duplicate variable declaration', pos);
            }
            this.variables[key] = {
                type: type,
                pos: pos,
                qname: qname,
                annotations: {}
            };
            return this;
        },
        
        getVariables: function(){
            var variables = {};
            var that = this;
            var handler = function(key){
                if(!variables[key]){
                    variables[key] = that.variables[key];
                }
            };
            while(that){
                Object.keys(that.variables).forEach(handler);
                that = that.parent;
            }
            return variables;
        },
        
        getVariable: function(qname) {
            var key = getVarKey(qname);
            var that = this;
            while(that) {
                if(that.variables[key]) {
                    return that.variables[key];
                }
                that = that.parent;
            }
        },
        
        addVarRef: function(qname, pos){



( run in 0.406 second using v1.01-cache-2.11-cpan-5b529ec07f3 )