Package gnu.kawa.lispexpr
Class LispReader
- java.lang.Object
-
- java.io.Reader
-
- gnu.text.Lexer
-
- gnu.kawa.lispexpr.LispReader
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable,java.lang.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 java.lang.ObjectbindSharedObject(int sharingIndex, java.lang.Object value)Bind value to index in sharingStructuretable.voidcheckEncodingSpec(java.lang.String line)chargetReadCase()Get specification of how symbols should be case-folded.protected java.lang.ObjecthandlePostfix(java.lang.Object value, ReadTable rtable, int line, int column)After reading a value check for following'['or':'.protected java.lang.ObjecthandleToken(int startPos, ReadTable rtable)protected booleanisTerminatingChar(int ch, ReadTable rtable)protected java.lang.ObjectmakeNil()protected PairmakePair(java.lang.Object car, int line, int column)protected PairmakePair(java.lang.Object car, int startline, int startcolumn, int endline, int endcolumn)protected PairmakePair(java.lang.Object car, java.lang.Object cdr, int line, int column)protected PairmakePair2(java.lang.Object car, java.lang.Object cadr, java.lang.Object cddr, int line, int column)static java.lang.ObjectparseNumber(char[] buffer, int start, int count, char exactness, int radix, int flags)Parse a number.static java.lang.ObjectparseNumber(java.lang.CharSequence str, int radix)protected java.lang.ObjectreadAndHandleToken(int ch, int startPos, ReadTable rtable)static java.lang.ObjectreadCharacter(LispReader reader)java.lang.ObjectreadCommand()Read a "command" - a top-level expression or declaration.intreadEscape()Reads a C-style String escape sequence.intreadEscape(int c)static java.lang.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 java.lang.ObjectreadNumberWithRadix(int previous, LispReader reader, int radix)Read a number from a LispReaderjava.lang.ObjectreadObject()java.lang.ObjectreadObject(int c)java.lang.ObjectreadObject(int sharingIndex, boolean topLevel)static java.lang.ObjectreadSpecial(LispReader reader)java.lang.StringreadTokenString(int ch, ReadTable rtable)java.lang.ObjectreadValues(int ch, ReadTableEntry entry, ReadTable rtable, int sharingIndex)May return zero or multiple values.java.lang.ObjectreadValues(int ch, ReadTable rtable, int sharingIndex)PairreadValuesAndAppend(int ch, ReadTable rtable, Pair last)protected voidsetCar(java.lang.Object pair, java.lang.Object car)protected voidsetCar(java.lang.Object pair, java.lang.Object car, int endline, int endcolumn)protected voidsetCdr(java.lang.Object pair, java.lang.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
-
-
-
-
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 java.lang.Object bindSharedObject(int sharingIndex, java.lang.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 java.io.IOException, SyntaxExceptionRead a #|...|#-style comment (which may contain other nested comments). Assumes the initial "#|" has already been read.- Throws:
java.io.IOExceptionSyntaxException
-
checkEncodingSpec
public void checkEncodingSpec(java.lang.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 java.lang.Object readValues(int ch, ReadTable rtable, int sharingIndex) throws java.io.IOException, SyntaxException- Throws:
java.io.IOExceptionSyntaxException
-
readValues
public java.lang.Object readValues(int ch, ReadTableEntry entry, ReadTable rtable, int sharingIndex) throws java.io.IOException, SyntaxExceptionMay return zero or multiple values. Returns no values if looking at whitespace or a comment.- Throws:
java.io.IOExceptionSyntaxException
-
readValuesAndAppend
public Pair readValuesAndAppend(int ch, ReadTable rtable, Pair last) throws java.io.IOException, SyntaxException
- Throws:
java.io.IOExceptionSyntaxException
-
readAndHandleToken
protected java.lang.Object readAndHandleToken(int ch, int startPos, ReadTable rtable) throws java.io.IOException, SyntaxException- Throws:
java.io.IOExceptionSyntaxException
-
handleToken
protected java.lang.Object handleToken(int startPos, ReadTable rtable) throws java.io.IOException, SyntaxException- Throws:
java.io.IOExceptionSyntaxException
-
isTerminatingChar
protected boolean isTerminatingChar(int ch, ReadTable rtable) throws java.io.IOException, SyntaxException- Throws:
java.io.IOExceptionSyntaxException
-
readTokenString
public java.lang.String readTokenString(int ch, ReadTable rtable) throws java.io.IOException, SyntaxException- Throws:
java.io.IOExceptionSyntaxException
-
readObject
public java.lang.Object readObject() throws java.io.IOException, SyntaxException- Throws:
java.io.IOExceptionSyntaxException
-
readObject
public java.lang.Object readObject(int sharingIndex, boolean topLevel) throws java.io.IOException, SyntaxException- Throws:
java.io.IOExceptionSyntaxException
-
validPostfixLookupStart
protected boolean validPostfixLookupStart(int ch, ReadTable rtable) throws java.io.IOException- Throws:
java.io.IOException
-
handlePostfix
protected java.lang.Object handlePostfix(java.lang.Object value, ReadTable rtable, int line, int column) throws java.io.IOException, SyntaxExceptionAfter reading a value check for following'['or':'.- Throws:
java.io.IOExceptionSyntaxException
-
parseNumber
public static java.lang.Object parseNumber(java.lang.CharSequence str, int radix)
-
parseNumber
public static java.lang.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 java.io.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:
java.io.IOExceptionSyntaxException
-
readEscape
public final int readEscape(int c) throws java.io.IOException, SyntaxException- Throws:
java.io.IOExceptionSyntaxException
-
readHexEscape
public int readHexEscape() throws java.io.IOException, SyntaxException- Throws:
java.io.IOExceptionSyntaxException
-
readObject
public final java.lang.Object readObject(int c) throws java.io.IOException, SyntaxException- Throws:
java.io.IOExceptionSyntaxException
-
readCommand
public java.lang.Object readCommand() throws java.io.IOException, SyntaxExceptionRead a "command" - a top-level expression or declaration. Return Sequence.eofValue at end of file.- Throws:
java.io.IOExceptionSyntaxException
-
makeNil
protected java.lang.Object makeNil()
-
makePair
protected Pair makePair(java.lang.Object car, int line, int column)
-
makePair
protected Pair makePair(java.lang.Object car, int startline, int startcolumn, int endline, int endcolumn)
-
makePair
protected Pair makePair(java.lang.Object car, java.lang.Object cdr, int line, int column)
-
makePair2
protected Pair makePair2(java.lang.Object car, java.lang.Object cadr, java.lang.Object cddr, int line, int column)
-
setCar
protected void setCar(java.lang.Object pair, java.lang.Object car, int endline, int endcolumn)
-
setCar
protected void setCar(java.lang.Object pair, java.lang.Object car)
-
setCdr
protected void setCdr(java.lang.Object pair, java.lang.Object cdr)
-
readNumberWithRadix
public static java.lang.Object readNumberWithRadix(int previous, LispReader reader, int radix) throws java.io.IOException, SyntaxExceptionRead 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:
java.io.IOExceptionSyntaxException
-
readCharacter
public static java.lang.Object readCharacter(LispReader reader) throws java.io.IOException, SyntaxException
- Throws:
java.io.IOExceptionSyntaxException
-
readSpecial
public static java.lang.Object readSpecial(LispReader reader) throws java.io.IOException, SyntaxException
- Throws:
java.io.IOExceptionSyntaxException
-
readGeneralArray
public static java.lang.Object readGeneralArray(LispReader in, int rank, PrimType elementType) throws java.io.IOException, SyntaxException
- Throws:
java.io.IOExceptionSyntaxException
-
-