[110] TypeDeclaration ::= "as" SequenceType
TODO: err:XPTY0004, err:XQST0054, err:XP0006
************************************************************************/
final public void parseVarDecl() throws ParseException, XQueryException {
final QualifiedName varName;
Type varType = null;
XQExpression valueExpr = null;
boolean isExternal = false;
currentToken = jj_consume_token(DefineVariable);
// TODO spaces afrer "$"
currentToken = jj_consume_token(VarName);
varName = QNameUtil.parse(currentToken.image, namespaceContext, currentModule.getNamespace());
switch(jj_nt.kind) {
case As:
currentToken = jj_consume_token(As);
varType = parseSequenceType();
break;
default:
jj_la1[22] = jj_gen;
;
}
switch(jj_nt.kind) {
case ColonEquals:
currentToken = jj_consume_token(ColonEquals);
valueExpr = parseExprSingle();
break;
case External:
currentToken = jj_consume_token(External);
isExternal = true;
break;
default:
jj_la1[23] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
final Variable variable;
if(isExternal) {
Variable extVar = currentModule.getVariable(varName);
if(extVar != null) {
variable = extVar;
} else {
variable = ExpressionFactory.createExternalVariable(varName, currentModule);
currentModule.putVariable(varName, variable);
}
} else { // internal
if(isLibraryModule) {
final String expectedNamespace = currentModule.getNamespace();
if(expectedNamespace != null) {
if(!expectedNamespace.equals(varName.getNamespaceURI())) {
error("err:XQST0048");
}
}
}
variable = currentModule.declareGlobalVariable(varName, valueExpr); // may causes err:XQ0049