if (null == module)
module = ModuleDecl.DEFAULT;
chewEols();
Unit unit = new Unit(file, module);
scope = unit;
RequireDecl require;
do {
require = require();
chewEols();
if (null != require) {
if (unit.imports().contains(require) && require.alias == null) {
addError("Duplicate module import: " + require.toSymbol(),
require.sourceLine, require.sourceColumn);
throw new LoopCompileException();
}
unit.declare(require);
}
} while (require != null);
FunctionDecl function;
ClassDecl classDecl = null;
do {
function = functionDecl();
if (function == null) {
classDecl = classDecl();
}
chewEols();
if (null != function) {
if (unit.resolveFunction(function.name(), false) != null) {
addError("Duplicate function definition: " + function.name(),
function.sourceLine,
function.sourceColumn);
throw new LoopCompileException();
}
unit.declare(function);
} else if (null != classDecl) {
if (unit.getType(classDecl.name) != null) {
addError("Duplicate type definition: " + classDecl.name,
classDecl.sourceLine, classDecl.sourceColumn);
throw new LoopCompileException();
}
unit.declare(classDecl);
}
} while (function != null || classDecl != null);
// Now slurp up any freeform expressions into the module initializer.
Node expression;
while ((expression = computation()) != null) {
unit.addToInitializer(expression);
if (match(Kind.EOL) == null)
break;
chewEols();
}