package semantic;

import error.CompilerError;

import parse.Loc;
import types.Type;

public interface SemanticHelper {

   static CompilerError typeMismatch(Loc loc, Type found, Type... expected) {
      final StringBuilder builder = new StringBuilder();
      final int n = expected.length;
      if (n > 0) {
         builder.append(expected[0]);
         if (n > 1) {
            for (int i = 1; i < n - 2; i++)
               builder.append(", ").append(expected[i]);
            builder.append(" or ").append(expected[n - 1]);
         }
      }
      return new CompilerError(loc, "type mismatch: found %s but expected %s", found, builder);
   }

   static CompilerError undefined(Loc loc, String category, String name) {
      return new CompilerError(loc, "undefined %s '%s'", category, name);
   }

   static CompilerError notAFunction(Loc loc, String name) {
      return new CompilerError(loc, "'%s' is not a function", name);
   }

   static CompilerError tooFewArguments(Loc loc, String name) {
      return new CompilerError(loc, "too few arguments in call to '%s'", name);
   }

   static CompilerError tooMuchArguments(Loc loc, String name) {
      return new CompilerError(loc, "too much arguments in call to '%s'", name);
   }

}

@@ -114,16 +114,355 @@
 lper %7B%0A%0A
+   static CompilerError error(String message) %7B%0A      return new CompilerError(message);%0A   %7D%0A%0A   static CompilerError error(String format, Object... args) %7B%0A      return new CompilerError(format, args);%0A   %7D%0A%0A   static CompilerError error(Loc loc, String format, Object... args) %7B%0A      return new CompilerError(loc, format, args);%0A   %7D%0A%0A
    stati
@@ -527,24 +527,24 @@
 expected) %7B%0A
-
       final 
@@ -893,37 +893,25 @@
      return 
-new CompilerE
+e
 rror(loc, %22t
@@ -1199,37 +1199,25 @@
      return 
-new CompilerE
+e
 rror(loc, %22'
@@ -1326,37 +1326,25 @@
      return 
-new CompilerE
+e
 rror(loc, %22t
@@ -1465,37 +1465,25 @@
      return 
-new CompilerE
+e
 rror(loc, %22t

Add more helper methods for reporting errors