Class TokenizerBase<TT,​T extends Token<TT>>

  • Type Parameters:
    TT - TokenType type.
    T - Token type.
    All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable, java.lang.Readable, Tokenizer<TT,​T>

    public abstract class TokenizerBase<TT,​T extends Token<TT>>
    extends LineBufferedReader
    implements Tokenizer<TT,​T>
    Base tokenizer used around providence. The base tokenizer supports the minimum of what all the tokenizers require, so that each will mostly expand support, not much reduce it.
    • Constructor Detail

      • TokenizerBase

        protected TokenizerBase​(java.io.Reader in,
                                int bufferSize,
                                boolean preLoadAll)
    • Method Detail

      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • genericToken

        protected abstract T genericToken​(char[] buffer,
                                          int offset,
                                          int len,
                                          @Nonnull
                                          TT type,
                                          int lineNo,
                                          int linePos)
      • identifierToken

        protected abstract T identifierToken​(char[] buffer,
                                             int offset,
                                             int len,
                                             int lineNo,
                                             int linePos)
      • stringToken

        protected abstract T stringToken​(char[] buffer,
                                         int offset,
                                         int len,
                                         int lineNo,
                                         int linePos)
      • numberToken

        protected abstract T numberToken​(char[] buffer,
                                         int offset,
                                         int len,
                                         int lineNo,
                                         int linePos)
      • symbolToken

        protected abstract T symbolToken​(char[] buffer,
                                         int offset,
                                         int len,
                                         int lineNo,
                                         int linePos)
      • failure

        @Nonnull
        public LexerException failure​(@Nonnull
                                      T token,
                                      @Nonnull
                                      java.lang.String message,
                                      @Nonnull
                                      java.lang.Object... params)
      • eofFailure

        @Nonnull
        protected LexerException eofFailure​(@Nonnull
                                            java.lang.String message,
                                            @Nonnull
                                            java.lang.Object... params)
      • currentLineNo

        public int currentLineNo()
        Description copied from interface: Tokenizer
        Get the current line number. Note that the lines should be 1-indexed, meaning the first line (before the first newline) is line no 1. This should point to the position where it will continue parsing, any previous tokens should be represented by itself.
        Specified by:
        currentLineNo in interface Tokenizer<TT,​T extends Token<TT>>
        Returns:
        The current line number.
      • currentLinePos

        public int currentLinePos()
        Description copied from interface: Tokenizer
        Get the current line position. This should point to the char position of the current line, meaning it is 0-indexed. This should point to the position where it will continue parsing, any previous tokens should be represented by itself.
        Specified by:
        currentLinePos in interface Tokenizer<TT,​T extends Token<TT>>
        Returns:
        The current line position.
      • currentLine

        @Nonnull
        public java.lang.CharSequence currentLine()
        Specified by:
        currentLine in interface Tokenizer<TT,​T extends Token<TT>>
        Returns:
        Content of the current line. The char-sequence must be effectively immutable.
      • readUntil

        @Nullable
        public T readUntil​(@Nonnull
                           java.lang.CharSequence terminator,
                           @Nonnull
                           TT type,
                           boolean allowEof)
                    throws java.io.IOException
        Description copied from interface: Tokenizer
        Read all content until the given terminator string is encountered. The terminator should not become part of the returned token. The returned sequence may span more than one line.
        Specified by:
        readUntil in interface Tokenizer<TT,​T extends Token<TT>>
        Parameters:
        terminator - The terminator string.
        type - The token type for the resulting token.
        allowEof - Set to true if EOF is allowed as a replacement for the terminator.
        Returns:
        The char sequence from the current position until the encountered terminator or the end of the file. Or null if no chars before the terminator.
        Throws:
        LexerException - On parse errors or validation failure.
        java.io.IOException - If unable to parse token.
      • parseNextToken

        @Nullable
        public T parseNextToken()
                         throws java.io.IOException
        Description copied from interface: Tokenizer
        Continue parsing content and return the next token to be found.
        Specified by:
        parseNextToken in interface Tokenizer<TT,​T extends Token<TT>>
        Returns:
        The next token, or null if there is none.
        Throws:
        LexerException - If parsing token failed.
        java.io.IOException - If reading failed.
      • isWhitespace

        protected boolean isWhitespace()
      • startNumber

        protected boolean startNumber()
      • startString

        protected boolean startString()
      • startIdentifier

        protected boolean startIdentifier()
      • allowIdentifier

        protected boolean allowIdentifier​(int last)
      • identifierSeparator

        protected boolean identifierSeparator​(int last)
      • startSymbol

        protected boolean startSymbol()
      • nextSymbol

        @Nonnull
        protected T nextSymbol()
                        throws java.io.IOException
        Throws:
        java.io.IOException