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 intstatic final intstatic final intstatic final intprotected booleanIf true, then tokenbuffer contains escaped characters.static final ThreadLocationstatic final charFields 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.voidcheckEncodingSpec(String line) charGet specification of how symbols should be case-folded.protected ObjecthandlePostfix(Object value, ReadTable rtable, int line, int column) After reading a value check for following'['or':'.protected ObjecthandleToken(int startPos, ReadTable rtable) protected booleanisTerminatingChar(int ch, ReadTable rtable) protected ObjectmakeNil()protected Pairprotected Pairprotected Pairprotected Pairstatic ObjectparseNumber(char[] buffer, int start, int count, char exactness, int radix, int flags) Parse a number.static ObjectparseNumber(CharSequence str, int radix) protected ObjectreadAndHandleToken(int ch, int startPos, ReadTable rtable) static ObjectreadCharacter(LispReader reader) Read a "command" - a top-level expression or declaration.intReads a C-style String escape sequence.final intreadEscape(int c) static ObjectreadGeneralArray(LispReader in, int rank, PrimType elementType) intfinal voidreadNestedComment(char start1, char start2, char end1, char end2) Read a #|...|#-style comment (which may contain other nested comments).static ObjectreadNumberWithRadix(int previous, LispReader reader, int radix) Read a number from a LispReaderfinal ObjectreadObject(int c) readObject(int sharingIndex, boolean topLevel) static ObjectreadSpecial(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 voidprotected voidprotected voidvoidsetReadCase(char readCase) voidsetReturnMutablePairs(boolean v) Set whether returned pairs are mutable or not (the default).protected booleanvalidPostfixLookupStart(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_quickMethods 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:
IOExceptionSyntaxException
-
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:
IOExceptionSyntaxException
-
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:
IOExceptionSyntaxException
-
readValuesAndAppend
public Pair readValuesAndAppend(int ch, ReadTable rtable, Pair last) throws IOException, SyntaxException - Throws:
IOExceptionSyntaxException
-
readAndHandleToken
protected Object readAndHandleToken(int ch, int startPos, ReadTable rtable) throws IOException, SyntaxException - Throws:
IOExceptionSyntaxException
-
handleToken
- Throws:
IOExceptionSyntaxException
-
isTerminatingChar
- Throws:
IOExceptionSyntaxException
-
readTokenString
- Throws:
IOExceptionSyntaxException
-
readObject
- Throws:
IOExceptionSyntaxException
-
readObject
- Throws:
IOExceptionSyntaxException
-
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:
IOExceptionSyntaxException
-
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:
IOExceptionSyntaxException
-
readEscape
- Throws:
IOExceptionSyntaxException
-
readHexEscape
- Throws:
IOExceptionSyntaxException
-
readObject
- Throws:
IOExceptionSyntaxException
-
readCommand
Read a "command" - a top-level expression or declaration. Return Sequence.eofValue at end of file.- Throws:
IOExceptionSyntaxException
-
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:
IOExceptionSyntaxException
-
readCharacter
- Throws:
IOExceptionSyntaxException
-
readSpecial
- Throws:
IOExceptionSyntaxException
-
readGeneralArray
public static Object readGeneralArray(LispReader in, int rank, PrimType elementType) throws IOException, SyntaxException - Throws:
IOExceptionSyntaxException
-