1 21 22 package org.armedbear.lisp; 23 24 public final class peek_char extends Primitive 26 { 27 private peek_char() 28 { 29 super("peek-char", 30 "&optional peek-type input-stream eof-error-p eof-value recursive-p"); 31 } 32 33 public LispObject execute(LispObject[] args) throws ConditionThrowable 34 { 35 int length = args.length; 36 if (length > 5) 37 signal(new WrongNumberOfArgumentsException(this)); 38 LispObject peekType = length > 0 ? args[0] : NIL; 39 Stream stream = length > 1 ? inSynonymOf(args[1]) : getStandardInput(); 40 boolean eofError = length > 2 ? (args[2] != NIL) : true; 41 LispObject eofValue = length > 3 ? args[3] : NIL; 42 boolean recursive = length > 4 ? (args[4] != NIL) : false; 43 if (peekType == NIL) { 44 LispObject result = stream.readChar(eofError, eofValue); 45 if (result instanceof LispCharacter) 46 stream.unreadChar((LispCharacter)result); 47 return result; 48 } 49 if (peekType == T) { 50 Readtable rt = currentReadtable(); 51 while (true) { 52 LispObject result = stream.readChar(eofError, eofValue); 53 if (result instanceof LispCharacter) { 54 char c = ((LispCharacter)result).value; 55 if (!rt.isWhitespace(c)) { 56 stream.unreadChar((LispCharacter)result); 57 return result; 58 } 59 } else 60 return result; 61 } 62 } 63 if (peekType instanceof LispCharacter) { 64 char c = ((LispCharacter)peekType).value; 65 while (true) { 66 LispObject result = stream.readChar(eofError, eofValue); 67 if (result instanceof LispCharacter) { 68 if (((LispCharacter)result).value == c) { 69 stream.unreadChar((LispCharacter)result); 70 return result; 71 } 72 } else 73 return result; 74 } 75 } 76 return signal(new SimpleError(String.valueOf(peekType) + 77 " is an illegal peek-type.")); 78 } 79 80 private static final Primitive PEEK_CHAR = new peek_char(); 81 } 82 | Popular Tags |