1 package kawa.standard; 2 import kawa.lang.*; 3 import gnu.lists.*; 4 import gnu.expr.*; 5 6 10 11 public class syntax_error extends Syntax 12 { 13 public static final syntax_error syntax_error = new syntax_error(); 14 static { syntax_error.setName("%syntax-error"); } 15 16 public Expression rewrite (Object obj, Translator tr) 17 { 18 StringBuffer buffer = new StringBuffer (); 19 int words = 0; 20 while (obj instanceof Pair) 21 { 22 Pair pair = (Pair) obj; 23 if (words > 0) 24 buffer.append (' '); 25 buffer.append (pair.car); 26 obj = pair.cdr; 27 words++; 28 } 29 if (obj != LList.Empty) 30 { 31 if (words > 0) 32 buffer.append (' '); 33 buffer.append (obj); 34 } 35 return tr.syntaxError (buffer.toString ()); 36 } 37 38 public static Expression error (Object form, Object [] message) 39 { 40 StringBuffer buffer = new StringBuffer (); 41 int len = message.length; 42 if (message == null || len == 0) 43 buffer.append("invalid syntax"); 44 else 45 { 46 for (int i = 0; i < len; i++) 47 buffer.append(message[i]); 48 } 49 Translator tr = (Translator) Compilation.getCurrent(); 50 if (tr == null) 51 throw new RuntimeException (buffer.toString()); 52 Object savePos = tr.pushPositionOf(form); 53 try 54 { 55 return tr.syntaxError(buffer.toString()); 56 } 57 finally 58 { 59 tr.popPositionOf(savePos); 60 } 61 } 62 } 63 | Popular Tags |