package gavilan.kakuro;

import gavq.kakuro.KakuroLexer;
import gavq.kakuro.KakuroParser;
import java.io.IOException;
import java.io.Reader;
import java.util.Optional;
import java.util.function.Function;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.antlr.v4.runtime.ANTLRInputStream;
import org.antlr.v4.runtime.CommonTokenStream;
import org.antlr.v4.runtime.tree.ParseTree;
import org.antlr.v4.runtime.tree.ParseTreeWalker;

public class Interpreter {

public static Optional<CreateModelListener> interpretRule(Reader r, Function<KakuroParser, ParseTree> rule) {
  try {
    var input = new ANTLRInputStream(r);
    var lexer = new KakuroLexer(input);
    var tokens = new CommonTokenStream(lexer);
    var parser = new KakuroParser(tokens);
    var tree = rule.apply(parser);
    var walker = new ParseTreeWalker();
    var modelListener = new CreateModelListener();
    walker.walk(modelListener, tree);
    return Optional.of(modelListener);
  }
  catch (IOException ex) {
    Logger.getLogger(Interpreter.class.getName()).log(Level.SEVERE, "", ex);
    return Optional.empty();
  }
}

public static GridController interpret(Reader r) {
  return interpretRule(r, KakuroParser::grid)
    .map(CreateModelListener::getGridController)
    .orElse(new GridController());
}
}

@@ -290,32 +290,27 @@
 runtime.
-ANTLRInput
+Char
 Stream
+s
 ;%0Aimport
@@ -611,28 +611,30 @@
 t = 
-new ANTLRInputStream
+CharStreams.fromReader
 (r);

update for antlr 4.8