gnu.kawa.lispexpr
Class LispReader

java.lang.Object
  extended by java.io.Reader
      extended by gnu.text.Lexer
          extended by gnu.kawa.lispexpr.LispReader
All Implemented Interfaces:
java.io.Closeable, java.lang.Readable
Direct Known Subclasses:
BRLRead, Q2Read

public class LispReader
extends Lexer

A Lexer for reading S-expressions in generic Lisp-like syntax. This class may have outlived its usefulness: It's mostly just a wrapper around a LineBufferedReader plus a helper token-buffer. The functionality should be moved to ReadTable, though it is unclear what to do about the tokenBuffer.


Field Summary
protected  boolean finalColonIsKeyword
          True if "IDENTIFIER:" should be treated as a keyword.
protected  boolean initialColonIsKeyword
          True if ":IDENTIFIER" should be treated as a keyword.
static int SCM_NUMBERS
           
protected  boolean seenEscapes
          If true, then tokenbuffer contains escaped characters.
static char TOKEN_ESCAPE_CHAR
           
 
Fields inherited from class gnu.text.Lexer
interactive, nesting, port, tokenBuffer, tokenBufferLength
 
Fields inherited from class java.io.Reader
lock
 
Constructor Summary
LispReader(LineBufferedReader port)
           
LispReader(LineBufferedReader port, SourceMessages messages)
           
 
Method Summary
 java.lang.Object handleToken(int startPos, int endPos, ReadTable rtable)
          Classify and return a token in tokenBuffer from startPos to endPos.
static java.lang.Object lookupUnit(java.lang.String name)
          Resolve a unit name, if possible.
protected  java.lang.Object makeNil()
           
protected  java.lang.Object makePair(java.lang.Object car, int line, int column)
           
 java.lang.Object makePair(java.lang.Object car, java.lang.Object cdr)
           
static java.lang.Object parseNumber(char[] buffer, int start, int count, char exactness, int radix, int flags)
          Parse a number.
static java.lang.Object readCharacter(LispReader reader)
           
 java.lang.Object readCommand()
          Read a "command" - a top-level expression or declaration.
 int readEscape()
          Reads a C-style String escape sequence.
 int readEscape(int c)
           
 void readNestedComment(char c1, char c2)
          Read a #|...|#-style comment (which may contain other nested comments).
static java.lang.Object readNumberWithRadix(int previous, LispReader reader, int radix)
          Read a number from a LispReader
 java.lang.Object readObject()
           
 java.lang.Object readObject(int c)
           
static SimpleVector readSimpleVector(LispReader reader, char kind)
           
static java.lang.Object readSpecial(LispReader reader)
           
 java.lang.Object readValues(int ch, ReadTable rtable)
           
 java.lang.Object readValues(int ch, ReadTableEntry entry, ReadTable rtable)
          May return zero or multiple values.
protected  java.lang.Object returnSymbol(int startPos, int endPos, ReadTable rtable)
           
protected  void setCdr(java.lang.Object pair, java.lang.Object cdr)
           
protected  boolean validPostfixLookupStart(ReadTable rtable)
           
 
Methods inherited from class gnu.text.Lexer
checkErrors, checkNext, clearErrors, close, eofError, eofError, error, error, error, fatal, getColumnNumber, getErrors, getLineNumber, getMessages, getName, getPort, isInteractive, mark, peek, popNesting, pushNesting, read, read, readDigitsInBuffer, readOptionalExponent, reset, seenErrors, setInteractive, setMessages, skip_quick, skip, tokenBufferAppend, unread_quick, unread, unread
 
Methods inherited from class java.io.Reader
mark, markSupported, read, read, ready, skip
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TOKEN_ESCAPE_CHAR

public static final char TOKEN_ESCAPE_CHAR
See Also:
Constant Field Values

seenEscapes

protected boolean seenEscapes
If true, then tokenbuffer contains escaped characters. These are prefixed (in the buffer) by TOKEN_ESCAPE_CHAR.


initialColonIsKeyword

protected boolean initialColonIsKeyword
True if ":IDENTIFIER" should be treated as a keyword.


finalColonIsKeyword

protected boolean finalColonIsKeyword
True if "IDENTIFIER:" should be treated as a keyword.


SCM_NUMBERS

public static final int SCM_NUMBERS
See Also:
Constant Field Values
Constructor Detail

LispReader

public LispReader(LineBufferedReader port)

LispReader

public LispReader(LineBufferedReader port,
                  SourceMessages messages)
Method Detail

lookupUnit

public static java.lang.Object lookupUnit(java.lang.String name)
Resolve a unit name, if possible. Returns null if the unit name is unknown.


readNestedComment

public final void readNestedComment(char c1,
                                    char c2)
                             throws java.io.IOException,
                                    SyntaxException
Read a #|...|#-style comment (which may contain other nested comments). Assumes the initial "#|" has already been read.

Throws:
java.io.IOException
SyntaxException

readValues

public java.lang.Object readValues(int ch,
                                   ReadTable rtable)
                            throws java.io.IOException,
                                   SyntaxException
Throws:
java.io.IOException
SyntaxException

readValues

public java.lang.Object readValues(int ch,
                                   ReadTableEntry entry,
                                   ReadTable rtable)
                            throws java.io.IOException,
                                   SyntaxException
May return zero or multiple values.

Throws:
java.io.IOException
SyntaxException

readObject

public java.lang.Object readObject()
                            throws java.io.IOException,
                                   SyntaxException
Throws:
java.io.IOException
SyntaxException

validPostfixLookupStart

protected boolean validPostfixLookupStart(ReadTable rtable)
                                   throws java.io.IOException
Throws:
java.io.IOException

parseNumber

public static java.lang.Object parseNumber(char[] buffer,
                                           int start,
                                           int count,
                                           char exactness,
                                           int radix,
                                           int flags)
Parse a number.

Parameters:
buffer - contains the characters of the number
start - startinging index of the number in the buffer
count - number of characters in buffer to use
exactness - either 'i' or 'I' force an inexact result, either 'e' or 'E' force an exact result, '\0' yields an inact or inexact depending on the form of the literal, while ' ' is like '\0' but does not allow more exactness specifiers.
radix - the number base to use or 0 if unspecified
Returns:
the number if a valid number; null or a String-valued error message if if there was some error parsing the number.

returnSymbol

protected java.lang.Object returnSymbol(int startPos,
                                        int endPos,
                                        ReadTable rtable)

handleToken

public java.lang.Object handleToken(int startPos,
                                    int endPos,
                                    ReadTable rtable)
Classify and return a token in tokenBuffer from startPos to endPos.


readEscape

public int readEscape()
               throws java.io.IOException,
                      SyntaxException
Reads a C-style String escape sequence. Assume '\\' has already been read. Return the converted character, or -1 on EOF, or -2 to ignore.

Throws:
java.io.IOException
SyntaxException

readEscape

public final int readEscape(int c)
                     throws java.io.IOException,
                            SyntaxException
Throws:
java.io.IOException
SyntaxException

readObject

public final java.lang.Object readObject(int c)
                                  throws java.io.IOException,
                                         SyntaxException
Throws:
java.io.IOException
SyntaxException

readCommand

public java.lang.Object readCommand()
                             throws java.io.IOException,
                                    SyntaxException
Read a "command" - a top-level expression or declaration. Return Sequence.eofValue of end of file.

Throws:
java.io.IOException
SyntaxException

makeNil

protected java.lang.Object makeNil()

makePair

protected java.lang.Object makePair(java.lang.Object car,
                                    int line,
                                    int column)

makePair

public java.lang.Object makePair(java.lang.Object car,
                                 java.lang.Object cdr)

setCdr

protected void setCdr(java.lang.Object pair,
                      java.lang.Object cdr)

readNumberWithRadix

public static java.lang.Object readNumberWithRadix(int previous,
                                                   LispReader reader,
                                                   int radix)
                                            throws java.io.IOException,
                                                   SyntaxException
Read a number from a LispReader

Parameters:
previous - number of characters already pushed on tokenBuffer
reader - LispReader to read from
radix - base to use or -1 if unspecified
Throws:
java.io.IOException
SyntaxException

readCharacter

public static java.lang.Object readCharacter(LispReader reader)
                                      throws java.io.IOException,
                                             SyntaxException
Throws:
java.io.IOException
SyntaxException

readSpecial

public static java.lang.Object readSpecial(LispReader reader)
                                    throws java.io.IOException,
                                           SyntaxException
Throws:
java.io.IOException
SyntaxException

readSimpleVector

public static SimpleVector readSimpleVector(LispReader reader,
                                            char kind)
                                     throws java.io.IOException,
                                            SyntaxException
Throws:
java.io.IOException
SyntaxException