} catch (Exception e) { throw new XPathException("Internal error while loading module: " + location, e);
    private Module compileModule(String namespaceURI, String location, Module module, Source source) throws XPathException {        LOG.debug("Loading module from " + location);        Reader reader;        try {        	reader = source.getReader();        } catch (IOException e) {        	throw new XPathException("IO exception while loading module " + namespaceURI, e);        }        XQueryContext modContext = new ModuleContext(this);        XQueryLexer lexer = new XQueryLexer(modContext, reader);        XQueryParser parser = new XQueryParser(lexer);        XQueryTreeParser astParser = new XQueryTreeParser(modContext);        try {        	parser.xpath();        	if (parser.foundErrors()) {        		LOG.debug(parser.getErrorMessage());        		throw new XPathException(        			"error found while loading module from " + location + ": "        				+ parser.getErrorMessage());        	}        	AST ast = parser.getAST();        	PathExpr path = new PathExpr(modContext);        	astParser.xpath(ast, path);        	if (astParser.foundErrors()) {        		throw new XPathException(        			"error found while loading module from " + location + ": "        				+ astParser.getErrorMessage(),        			astParser.getLastException());        	}        	path.analyze(null, 0);        	ExternalModule modExternal = astParser.getModule();        	if(modExternal == null)        		throw new XPathException("source at " + location + " is not a valid module");        	if(!modExternal.getNamespaceURI().equals(namespaceURI))        		throw new XPathException("namespace URI declared by module (" + modExternal.getNamespaceURI() +         			") does not match namespace URI in import statement, which was: " + namespaceURI);        	modules.put(modExternal.getNamespaceURI(), modExternal);        	modExternal.setSource(source);        	modExternal.setContext(modContext);        	module = modExternal;        } catch (RecognitionException e) {        	throw new XPathException(        		"error found while loading module from " + location + ": " + e.getMessage(),        		e.getLine(), e.getColumn());        } catch (TokenStreamException e) {        	throw new XPathException(        		"error found while loading module from " + location + ": " + e.getMessage(),        		e);        }        declareModuleVars(module);        return module;    }