throws IOException {
MessageContext mc = new MessageContext();
for (Pair<InputSource, File> input : inputs) {
mc.addInputSource(input.a);
}
final MessageQueue errs = new EchoingMessageQueue(
err, mc, false);
RenderContext rc = new RenderContext(
new JsMinimalPrinter(new Concatenator(out, new Callback<IOException>() {
public void handle(IOException ex) {
errs.addMessage(
MessageType.IO_ERROR,
MessagePart.Factory.valueOf(ex.getMessage()));
}
})));
for (Pair<InputSource, File> input : inputs) {
CharProducer cp = CharProducer.Factory.fromFile(
input.b, Charsets.UTF_8.name());
JsLexer lexer = new JsLexer(cp);
JsTokenQueue tq = new JsTokenQueue(lexer, input.a);
Parser p = new Parser(tq, errs);
try {
while (!tq.isEmpty()) {
Block b = p.parse();
for (Statement topLevelStmt : b.children()) {
topLevelStmt.render(rc);
if (!topLevelStmt.isTerminal()) { rc.getOut().consume(";"); }
}
}
} catch (ParseException ex) {
ex.toMessageQueue(errs);
}
}
rc.getOut().noMoreTokens();
out.flush();
MessageLevel maxMessageLevel = MessageLevel.values()[0];
for (Message msg : errs.getMessages()) {
if (msg.getMessageLevel().compareTo(maxMessageLevel) >= 0) {
maxMessageLevel = msg.getMessageLevel();
}
}
return maxMessageLevel.compareTo(MessageLevel.ERROR) < 0;