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 intSCM_ANGLEstatic intSCM_COLATITUDEstatic intSCM_LEXPONENT_IS_BIGDECIMALstatic intSCM_NUMBERSprotected booleanseenEscapesIf true, then tokenbuffer contains escaped characters.static ThreadLocationsymbolReadCasestatic charTOKEN_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 ObjectbindSharedObject(int sharingIndex, Object value)Bind value to index in sharingStructuretable.voidcheckEncodingSpec(String line)chargetReadCase()Get 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 PairmakePair(Object car, int line, int column)protected PairmakePair(Object car, int startline, int startcolumn, int endline, int endcolumn)protected PairmakePair(Object car, Object cdr, int line, int column)protected PairmakePair2(Object car, Object cadr, Object cddr, int line, int column)static 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)ObjectreadCommand()Read a "command" - a top-level expression or declaration.intreadEscape()Reads a C-style String escape sequence.intreadEscape(int c)static ObjectreadGeneralArray(LispReader in, int rank, PrimType elementType)intreadHexEscape()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 LispReaderObjectreadObject()ObjectreadObject(int c)ObjectreadObject(int sharingIndex, boolean topLevel)static ObjectreadSpecial(LispReader reader)StringreadTokenString(int ch, ReadTable rtable)ObjectreadValues(int ch, ReadTableEntry entry, ReadTable rtable, int sharingIndex)May return zero or multiple values.ObjectreadValues(int ch, ReadTable rtable, int sharingIndex)PairreadValuesAndAppend(int ch, ReadTable rtable, Pair last)protected voidsetCar(Object pair, Object car)protected voidsetCar(Object pair, Object car, int endline, int endcolumn)protected voidsetCdr(Object pair, Object cdr)voidsetReadCase(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_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, SyntaxExceptionRead a #|...|#-style comment (which may contain other nested comments). Assumes the initial "#|" has already been read.- Throws:
IOExceptionSyntaxException
-
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:
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
protected Object handleToken(int startPos, ReadTable rtable) throws IOException, SyntaxException
- Throws:
IOExceptionSyntaxException
-
isTerminatingChar
protected boolean isTerminatingChar(int ch, ReadTable rtable) throws IOException, SyntaxException- Throws:
IOExceptionSyntaxException
-
readTokenString
public String readTokenString(int ch, ReadTable rtable) throws IOException, SyntaxException
- Throws:
IOExceptionSyntaxException
-
readObject
public Object readObject() throws IOException, SyntaxException
- Throws:
IOExceptionSyntaxException
-
readObject
public Object readObject(int sharingIndex, boolean topLevel) throws IOException, SyntaxException
- Throws:
IOExceptionSyntaxException
-
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:
IOExceptionSyntaxException
-
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, SyntaxExceptionReads 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
public final int readEscape(int c) throws IOException, SyntaxException- Throws:
IOExceptionSyntaxException
-
readHexEscape
public int readHexEscape() throws IOException, SyntaxException- Throws:
IOExceptionSyntaxException
-
readObject
public final Object readObject(int c) throws IOException, SyntaxException
- Throws:
IOExceptionSyntaxException
-
readCommand
public Object readCommand() throws IOException, SyntaxException
Read a "command" - a top-level expression or declaration. Return Sequence.eofValue at end of file.- Throws:
IOExceptionSyntaxException
-
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:
IOExceptionSyntaxException
-
readCharacter
public static Object readCharacter(LispReader reader) throws IOException, SyntaxException
- Throws:
IOExceptionSyntaxException
-
readSpecial
public static Object readSpecial(LispReader reader) throws IOException, SyntaxException
- Throws:
IOExceptionSyntaxException
-
readGeneralArray
public static Object readGeneralArray(LispReader in, int rank, PrimType elementType) throws IOException, SyntaxException
- Throws:
IOExceptionSyntaxException
-
-