Package gnu.kawa.lispexpr
Class LispReader
java.lang.Object
java.io.Reader
gnu.text.Lexer
gnu.kawa.lispexpr.LispReader
- All Implemented Interfaces:
Closeable
,AutoCloseable
,Readable
- Direct Known Subclasses:
BRLRead
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 an InPort plus a helper token-buffer.
The functionality should be moved to ReadTable, though it is
unclear what to do about the tokenBuffer.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
static final int
static final int
static final int
protected boolean
If true, then tokenbuffer contains escaped characters.static final ThreadLocation
static final char
Fields inherited from class gnu.text.Lexer
nesting, port, tentative, tokenBuffer, tokenBufferLength
-
Constructor Summary
ConstructorsConstructorDescriptionLispReader
(gnu.kawa.io.InPort port) LispReader
(gnu.kawa.io.InPort port, SourceMessages messages) -
Method Summary
Modifier and TypeMethodDescriptionbindSharedObject
(int sharingIndex, Object value) Bind value to index in sharingStructuretable.void
checkEncodingSpec
(String line) char
Get specification of how symbols should be case-folded.protected Object
handlePostfix
(Object value, ReadTable rtable, int line, int column) After reading a value check for following'['
or':'
.protected Object
handleToken
(int startPos, ReadTable rtable) protected boolean
isTerminatingChar
(int ch, ReadTable rtable) protected Object
makeNil()
protected Pair
protected Pair
protected Pair
protected Pair
static Object
parseNumber
(char[] buffer, int start, int count, char exactness, int radix, int flags) Parse a number.static Object
parseNumber
(CharSequence str, int radix) protected Object
readAndHandleToken
(int ch, int startPos, ReadTable rtable) static Object
readCharacter
(LispReader reader) Read a "command" - a top-level expression or declaration.int
Reads a C-style String escape sequence.final int
readEscape
(int c) static Object
readGeneralArray
(LispReader in, int rank, PrimType elementType) int
final void
readNestedComment
(char start1, char start2, char end1, char end2) Read a #|...|#-style comment (which may contain other nested comments).static Object
readNumberWithRadix
(int previous, LispReader reader, int radix) Read a number from a LispReaderfinal Object
readObject
(int c) readObject
(int sharingIndex, boolean topLevel) static Object
readSpecial
(LispReader reader) readTokenString
(int ch, ReadTable rtable) readValues
(int ch, ReadTableEntry entry, ReadTable rtable, int sharingIndex) May return zero or multiple values.readValues
(int ch, ReadTable rtable, int sharingIndex) readValuesAndAppend
(int ch, ReadTable rtable, Pair last) protected void
protected void
protected void
void
setReadCase
(char readCase) void
setReturnMutablePairs
(boolean v) Set whether returned pairs are mutable or not (the default).protected boolean
validPostfixLookupStart
(int ch, 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, isTentative, mark, peek, popNesting, pushNesting, read, read, readCodePoint, readDelimited, readDigits, readDigitsInBuffer, readIntDigits, readOptionalExponent, readUnicodeChar, reset, seenErrors, setInteractive, setMessages, setTentative, skip, skip_quick, tokenBufferAppend, tokenBufferString, unread, unread, unread_quick
Methods inherited from class java.io.Reader
mark, markSupported, nullReader, read, read, ready, skip, transferTo
-
Field Details
-
symbolReadCase
-
TOKEN_ESCAPE_CHAR
public static final char TOKEN_ESCAPE_CHAR- See Also:
-
seenEscapes
protected boolean seenEscapesIf true, then tokenbuffer contains escaped characters. These are prefixed (in the buffer) by TOKEN_ESCAPE_CHAR. -
SCM_NUMBERS
public static final int SCM_NUMBERS- See Also:
-
SCM_ANGLE
public static final int SCM_ANGLE- See Also:
-
SCM_COLATITUDE
public static final int SCM_COLATITUDE- See Also:
-
SCM_LEXPONENT_IS_BIGDECIMAL
public static final int SCM_LEXPONENT_IS_BIGDECIMAL- See Also:
-
-
Constructor Details
-
LispReader
public LispReader(gnu.kawa.io.InPort port) -
LispReader
-
-
Method Details
-
setReturnMutablePairs
public void setReturnMutablePairs(boolean v) Set whether returned pairs are mutable or not (the default). -
readNestedComment
public final void readNestedComment(char start1, char start2, char end1, char end2) throws IOException, SyntaxException Read a #|...|#-style comment (which may contain other nested comments). Assumes the initial "#|" has already been read.- Throws:
IOException
SyntaxException
-
checkEncodingSpec
-
getReadCase
public char getReadCase()Get specification of how symbols should be case-folded.- Returns:
- Either '\0' (unspecified - defaults to preserve case), 'P' (means preserve case), 'U' (upcase), 'D' (downcase), or 'I' (invert case).
-
setReadCase
public void setReadCase(char readCase) -
readValues
public Object readValues(int ch, ReadTable rtable, int sharingIndex) throws IOException, SyntaxException - Throws:
IOException
SyntaxException
-
readValues
public Object readValues(int ch, ReadTableEntry entry, ReadTable rtable, int sharingIndex) throws IOException, SyntaxException May return zero or multiple values. Returns no values if looking at whitespace or a comment.- Throws:
IOException
SyntaxException
-
readValuesAndAppend
public Pair readValuesAndAppend(int ch, ReadTable rtable, Pair last) throws IOException, SyntaxException - Throws:
IOException
SyntaxException
-
readAndHandleToken
protected Object readAndHandleToken(int ch, int startPos, ReadTable rtable) throws IOException, SyntaxException - Throws:
IOException
SyntaxException
-
handleToken
- Throws:
IOException
SyntaxException
-
isTerminatingChar
- Throws:
IOException
SyntaxException
-
readTokenString
- Throws:
IOException
SyntaxException
-
readObject
- Throws:
IOException
SyntaxException
-
readObject
- Throws:
IOException
SyntaxException
-
validPostfixLookupStart
- Throws:
IOException
-
handlePostfix
protected Object handlePostfix(Object value, ReadTable rtable, int line, int column) throws IOException, SyntaxException After reading a value check for following'['
or':'
.- Throws:
IOException
SyntaxException
-
parseNumber
-
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 numberstart
- startinging index of the number in the buffercount
- number of characters in buffer to useexactness
- 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 A negative radix is an overideable default.- Returns:
- the number if a valid number; null or a String-valued error message if if there was some error parsing the number.
-
readEscape
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:
IOException
SyntaxException
-
readEscape
- Throws:
IOException
SyntaxException
-
readHexEscape
- Throws:
IOException
SyntaxException
-
readObject
- Throws:
IOException
SyntaxException
-
readCommand
Read a "command" - a top-level expression or declaration. Return Sequence.eofValue at end of file.- Throws:
IOException
SyntaxException
-
makeNil
-
makePair
-
makePair
-
makePair
-
makePair2
-
setCar
-
setCar
-
setCdr
-
readNumberWithRadix
public static Object readNumberWithRadix(int previous, LispReader reader, int radix) throws IOException, SyntaxException Read a number from a LispReader- Parameters:
previous
- number of characters already pushed on tokenBufferreader
- LispReader to read fromradix
- base to use or -1 if unspecified- Throws:
IOException
SyntaxException
-
readCharacter
- Throws:
IOException
SyntaxException
-
readSpecial
- Throws:
IOException
SyntaxException
-
readGeneralArray
public static Object readGeneralArray(LispReader in, int rank, PrimType elementType) throws IOException, SyntaxException - Throws:
IOException
SyntaxException
-