addError("Expected newline after require (are you trying to alias Java imports?)",
tokens.get(i - 1));
throw new LoopCompileException();
}
return new RequireDecl(module.get(0).value).sourceLocation(module);
}
if (null == module) {
addError("Expected module identifier", tokens.get(i - 1));
throw new LoopCompileException();
}
List<String> requires = new ArrayList<String>();
requires.add(module.get(0).value);
boolean aliased, javaImport = false;
while (match(Token.Kind.DOT) != null) {
module = match(Token.Kind.IDENT);
if (null == module) {
module = match(Kind.TYPE_IDENT);
javaImport = true;
}
if (null == module) {
addError("Expected module identifier part after '.'", tokens.get(i - 1));
throw new LoopCompileException();
}
requires.add(module.get(0).value);
}
List<Token> asToken = match(Kind.IDENT);
aliased = asToken != null && RestrictedKeywords.AS.equals(asToken.get(0).value);
List<Token> aliasTokens = match(Kind.IDENT);
if (aliased) {
if (aliasedModules == null)
aliasedModules = new HashSet<String>();
if (aliasTokens == null) {
addError("Expected module alias after '" + RestrictedKeywords.AS + "'", tokens.get(i - 1));
throw new LoopCompileException();
}
// Cache the aliases for some smart parsing of namespaced function calls.
aliasedModules.add(aliasTokens.get(0).value);
}
if (match(Token.Kind.EOL) == null) {
addError("Expected newline after require declaration", tokens.get(i - 1));
throw new LoopCompileException();
}
// We also allow java imports outside using the backticks syntax.
String alias = aliased ? aliasTokens.get(0).value : null;
if (javaImport) {
return new RequireDecl(requires.toString().replace(", ", "."), alias)
.sourceLocation(module);
}
return new RequireDecl(requires, alias)
.sourceLocation(module);
}