Class 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 Detail

      • seenEscapes

        protected boolean seenEscapes
        If true, then tokenbuffer contains escaped characters. These are prefixed (in the buffer) by TOKEN_ESCAPE_CHAR.
      • 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,
                                            SyntaxException
        Read a #|...|#-style comment (which may contain other nested comments). Assumes the initial "#|" has already been read.
        Throws:
        java.io.IOException
        SyntaxException
      • 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,
                                           ReadTableEntry entry,
                                           ReadTable rtable,
                                           int sharingIndex)
                                    throws java.io.IOException,
                                           SyntaxException
        May return zero or multiple values. Returns no values if looking at whitespace or a comment.
        Throws:
        java.io.IOException
        SyntaxException
      • readAndHandleToken

        protected java.lang.Object readAndHandleToken​(int ch,
                                                      int startPos,
                                                      ReadTable rtable)
                                               throws java.io.IOException,
                                                      SyntaxException
        Throws:
        java.io.IOException
        SyntaxException
      • readObject

        public java.lang.Object readObject​(int sharingIndex,
                                           boolean topLevel)
                                    throws java.io.IOException,
                                           SyntaxException
        Throws:
        java.io.IOException
        SyntaxException
      • 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,
                                                 SyntaxException
        After reading a value check for following '[' or ':'.
        Throws:
        java.io.IOException
        SyntaxException
      • 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 number
        start - startinging index of the number in the buffer
        count - number of characters in buffer to use
        exactness - 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,
                              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:
        java.io.IOException
        SyntaxException
      • readObject

        public final java.lang.Object readObject​(int c)
                                          throws java.io.IOException,
                                                 SyntaxException
        Throws:
        java.io.IOException
        SyntaxException
      • readCommand

        public java.lang.Object readCommand()
                                     throws java.io.IOException,
                                            SyntaxException
        Read a "command" - a top-level expression or declaration. Return Sequence.eofValue at end of file.
        Throws:
        java.io.IOException
        SyntaxException
      • 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,
                                                           SyntaxException
        Read a number from a LispReader
        Parameters:
        previous - number of characters already pushed on tokenBuffer
        reader - LispReader to read from
        radix - base to use or -1 if unspecified
        Throws:
        java.io.IOException
        SyntaxException