package org.karaffe.compiler.frontend.karaffe;

import org.antlr.v4.runtime.DefaultErrorStrategy;
import org.antlr.v4.runtime.InputMismatchException;
import org.antlr.v4.runtime.Parser;
import org.antlr.v4.runtime.RecognitionException;
import org.antlr.v4.runtime.Token;
import org.antlr.v4.runtime.TokenStream;

public class KaraffeParseErrorStrategy extends DefaultErrorStrategy {
  private int firstErrorTokenIndex = -1;

  @Override
  public void recover(Parser recognizer, RecognitionException e) {
    int errIndex = recognizer.getInputStream().index();
    if (firstErrorTokenIndex == -1) {
      firstErrorTokenIndex = errIndex;
    }
    TokenStream input = recognizer.getInputStream();
    if (input.index() < input.size() - 1) {
      recognizer.consume();
    }
  }

  @Override
  public Token recoverInline(Parser recognizer) throws RecognitionException {
    throw new InputMismatchException(recognizer);
  }

  @Override
  public void sync(Parser recognizer) {
  }
}

@@ -757,24 +757,89 @@
 .consume();%0A
+    %7D else %7B%0A      throw new InputMismatchException(recognizer);%0A
     %7D%0A  %7D%0A%0A 

Fix parser error handling