gnu.kawa.lispexpr

Class LispReader

Known Direct Subclasses:
BRLRead, CLispReader, Q2Read, ScmRead

public class LispReader
extends Lexer

A Lexer to reading S-expressions in generic Lisp-like syntax.

Field Summary

static int
SCM_NUMBERS
static char
TOKEN_ESCAPE_CHAR
protected boolean
finalColonIsKeyword
True if "IDENTIFIER:" should be treated as a keyword.
protected boolean
initialColonIsKeyword
True if ":IDENTIFIER" should be treated as a keyword.
protected boolean
seenEscapes
If true, then tokenbuffer contains escaped characters.

Fields inherited from class gnu.text.Lexer

interactive, nesting, port, tokenBuffer, tokenBufferLength

Constructor Summary

LispReader(LineBufferedReader port)
LispReader(LineBufferedReader port, SourceMessages messages)

Method Summary

char
getReadCase()
Get specification of how symbols should be case-folded.
Object
handleToken(int startPos, int endPos)
Classify and return a token in tokenBuffer from startPos to endPos.
static Object
lookupUnit(String name)
Resolve a unit name, if possible.
protected Object
makeNil()
Object
makePair(Object car, Object cdr)
protected Object
makePair(Object car, int line, int column)
protected Object
makeSymbol(String name)
static Object
parseNumber(char[] buffer, int start, int count, char exactness, int radix, int flags)
Parse a number.
static Object
readCharacter(LispReader reader)
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 Object
readNumberWithRadix(int previous, LispReader reader, int radix)
Read a number from a LispReader
Object
readObject()
Object
readObject(int c)
static SimpleVector
readSimpleVector(LispReader reader, char kind)
static Object
readSpecial(LispReader reader)
void
readToken(int ch, boolean inEscapes, char readCase)
Object
readValues(int ch)
Object
readValues(int ch, ReadTableEntry entry)
May return zero or multiple values.
protected Object
returnSymbol(int startPos, int endPos)
protected void
setCdr(Object pair, Object cdr)

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, skip_quick, tokenBufferAppend, unread, unread, unread_quick

Field Details

SCM_NUMBERS

public static final int SCM_NUMBERS
Field Value:
1

TOKEN_ESCAPE_CHAR

public static final char TOKEN_ESCAPE_CHAR
Field Value:
'\uffff'

finalColonIsKeyword

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

initialColonIsKeyword

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

seenEscapes

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

Constructor Details

LispReader

public LispReader(LineBufferedReader port)

LispReader

public LispReader(LineBufferedReader port,
                  SourceMessages messages)

Method Details

getReadCase

public char getReadCase()
Get specification of how symbols should be case-folded.
Returns:
Either 'P' (means preserve case), 'U' (upcase), 'D' (downcase, or 'I' (invert case).

handleToken

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

lookupUnit

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

makeNil

protected Object makeNil()

makePair

public Object makePair(Object car,
                       Object cdr)

makePair

protected Object makePair(Object car,
                          int line,
                          int column)

makeSymbol

protected Object makeSymbol(String name)

parseNumber

public static 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.

readCharacter

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

readCommand

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

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.

readEscape

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

readNestedComment

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

readNumberWithRadix

public static 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

readObject

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

readObject

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

readSimpleVector

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

readSpecial

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

readToken

public void readToken(int ch,
                      boolean inEscapes,
                      char readCase)
            throws java.io.IOException,
                   SyntaxException

readValues

public Object readValues(int ch)
            throws java.io.IOException,
                   SyntaxException

readValues

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

returnSymbol

protected Object returnSymbol(int startPos,
                              int endPos)

setCdr

protected void setCdr(Object pair,
                      Object cdr)