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
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 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
Fields Modifier and Type Field Description static int
SCM_ANGLE
static int
SCM_COLATITUDE
static int
SCM_LEXPONENT_IS_BIGDECIMAL
static int
SCM_NUMBERS
protected boolean
seenEscapes
If true, then tokenbuffer contains escaped characters.static ThreadLocation
symbolReadCase
static char
TOKEN_ESCAPE_CHAR
-
Fields inherited from class gnu.text.Lexer
nesting, port, tentative, tokenBuffer, tokenBufferLength
-
-
Constructor Summary
Constructors Constructor Description LispReader(gnu.kawa.io.InPort port)
LispReader(gnu.kawa.io.InPort port, SourceMessages messages)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Object
bindSharedObject(int sharingIndex, Object value)
Bind value to index in sharingStructuretable.void
checkEncodingSpec(String line)
char
getReadCase()
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
makePair(Object car, int line, int column)
protected Pair
makePair(Object car, int startline, int startcolumn, int endline, int endcolumn)
protected Pair
makePair(Object car, Object cdr, int line, int column)
protected Pair
makePair2(Object car, Object cadr, Object cddr, int line, int column)
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)
Object
readCommand()
Read a "command" - a top-level expression or declaration.int
readEscape()
Reads a C-style String escape sequence.int
readEscape(int c)
static Object
readGeneralArray(LispReader in, int rank, PrimType elementType)
int
readHexEscape()
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 LispReaderObject
readObject()
Object
readObject(int c)
Object
readObject(int sharingIndex, boolean topLevel)
static Object
readSpecial(LispReader reader)
String
readTokenString(int ch, ReadTable rtable)
Object
readValues(int ch, ReadTableEntry entry, ReadTable rtable, int sharingIndex)
May return zero or multiple values.Object
readValues(int ch, ReadTable rtable, int sharingIndex)
Pair
readValuesAndAppend(int ch, ReadTable rtable, Pair last)
protected void
setCar(Object pair, Object car)
protected void
setCar(Object pair, Object car, int endline, int endcolumn)
protected void
setCdr(Object pair, Object cdr)
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 Detail
-
symbolReadCase
public static final ThreadLocation symbolReadCase
-
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.
-
SCM_NUMBERS
public static final int SCM_NUMBERS
- See Also:
- Constant Field Values
-
SCM_ANGLE
public static final int SCM_ANGLE
- See Also:
- Constant Field Values
-
SCM_COLATITUDE
public static final int SCM_COLATITUDE
- See Also:
- Constant Field Values
-
SCM_LEXPONENT_IS_BIGDECIMAL
public static final int SCM_LEXPONENT_IS_BIGDECIMAL
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
LispReader
public LispReader(gnu.kawa.io.InPort port)
-
LispReader
public LispReader(gnu.kawa.io.InPort port, SourceMessages messages)
-
-
Method Detail
-
setReturnMutablePairs
public void setReturnMutablePairs(boolean v)
Set whether returned pairs are mutable or not (the default).
-
bindSharedObject
public Object bindSharedObject(int sharingIndex, Object value)
Bind value to index in sharingStructuretable.- Parameters:
value
- The object being defined.sharingIndex
- Back-reference index. I.e. the value N in a @code{#N=} form. If negative, do nothing.- Returns:
- The value unchanged.
-
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
public void checkEncodingSpec(String line)
-
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
protected Object handleToken(int startPos, ReadTable rtable) throws IOException, SyntaxException
- Throws:
IOException
SyntaxException
-
isTerminatingChar
protected boolean isTerminatingChar(int ch, ReadTable rtable) throws IOException, SyntaxException
- Throws:
IOException
SyntaxException
-
readTokenString
public String readTokenString(int ch, ReadTable rtable) throws IOException, SyntaxException
- Throws:
IOException
SyntaxException
-
readObject
public Object readObject() throws IOException, SyntaxException
- Throws:
IOException
SyntaxException
-
readObject
public Object readObject(int sharingIndex, boolean topLevel) throws IOException, SyntaxException
- Throws:
IOException
SyntaxException
-
validPostfixLookupStart
protected boolean validPostfixLookupStart(int ch, ReadTable rtable) throws IOException
- 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
public static Object parseNumber(CharSequence str, int radix)
-
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
public int readEscape() throws 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:
IOException
SyntaxException
-
readEscape
public final int readEscape(int c) throws IOException, SyntaxException
- Throws:
IOException
SyntaxException
-
readHexEscape
public int readHexEscape() throws IOException, SyntaxException
- Throws:
IOException
SyntaxException
-
readObject
public final Object readObject(int c) throws IOException, SyntaxException
- Throws:
IOException
SyntaxException
-
readCommand
public Object readCommand() throws IOException, SyntaxException
Read a "command" - a top-level expression or declaration. Return Sequence.eofValue at end of file.- Throws:
IOException
SyntaxException
-
makeNil
protected Object makeNil()
-
makePair
protected Pair makePair(Object car, int startline, int startcolumn, int endline, int endcolumn)
-
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
public static Object readCharacter(LispReader reader) throws IOException, SyntaxException
- Throws:
IOException
SyntaxException
-
readSpecial
public static Object readSpecial(LispReader reader) throws IOException, SyntaxException
- Throws:
IOException
SyntaxException
-
readGeneralArray
public static Object readGeneralArray(LispReader in, int rank, PrimType elementType) throws IOException, SyntaxException
- Throws:
IOException
SyntaxException
-
-