Class Json5Lexer


  • public class Json5Lexer
    extends java.lang.Object
    This is a lexer to convert the provided data into tokens according to the json5 specification. The resulting tokens can then be used in an appropriate parser to construct Json5Object's and Json5Array's.
    See Also:
    Json5 Standard.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected Json5Options options  
      protected boolean root
      whether we're currently parsing the root object/array
    • Constructor Summary

      Constructors 
      Constructor Description
      Json5Lexer​(java.io.Reader reader, Json5Options options)
      Constructs a new lexer from a specific Reader.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void back()
      Forces the parser to re-read the last character
      protected static java.lang.String charToString​(char c)
      Converts a character into a string representation: if c == 0, "EOF" is returned if c fulfills one of the following conditions, "'x'" is returned, where x is the value returned by Character.toString(char): if c is an extended ASCII character (U+0001-U+00FF), except control characters if c is a Unicode letter if c is a Unicode digit otherwise, "U+XXXX" is returned, where XXXX is the uppercase hexadecimal representation of c's Unicode codepoint, padded with zeros (0) to a length of 4 characters
      java.lang.String consumeComment()
      Returns the last comment that was read and clears it.
      char nextClean()
      Reads until encountering a character that is not a whitespace according to the JSON5 Specification
      java.lang.String nextMemberName()
      Reads a member name from the source according to the JSON5 Specification
      Json5Element nextValue()
      Reads a value from the source according to the JSON5 Specification
      Json5Exception syntaxError​(java.lang.String message)
      Constructs a new Json5Exception with a detail message
      Json5Exception syntaxError​(java.lang.String message, java.lang.Throwable cause)
      Constructs a new Json5Exception with a detail message and a causing exception
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • root

        protected boolean root
        whether we're currently parsing the root object/array
    • Constructor Detail

      • Json5Lexer

        public Json5Lexer​(java.io.Reader reader,
                          Json5Options options)
        Constructs a new lexer from a specific Reader.

        Note: The reader must be closed after operation (Reader.close())!

        Parameters:
        reader - a reader.
        options - the options for lexing.
    • Method Detail

      • consumeComment

        public java.lang.String consumeComment()
        Returns the last comment that was read and clears it.
        Returns:
        The captured comment content, or null if no comment was found.
      • back

        public void back()
        Forces the parser to re-read the last character
      • nextClean

        public char nextClean()
        Reads until encountering a character that is not a whitespace according to the JSON5 Specification
        Returns:
        a non-whitespace character, or 0 if the end of the stream has been reached
      • nextMemberName

        public java.lang.String nextMemberName()
        Reads a member name from the source according to the JSON5 Specification
        Returns:
        an member name
      • syntaxError

        public Json5Exception syntaxError​(java.lang.String message,
                                          java.lang.Throwable cause)
        Constructs a new Json5Exception with a detail message and a causing exception
        Parameters:
        message - the detail message
        cause - the causing exception
        Returns:
        a Json5Exception
      • toString

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

        protected static java.lang.String charToString​(char c)
        Converts a character into a string representation:
        • if c == 0, "EOF" is returned
        • if c fulfills one of the following conditions, "'x'" is returned, where x is the value returned by Character.toString(char):
          • if c is an extended ASCII character (U+0001-U+00FF), except control characters
          • if c is a Unicode letter
          • if c is a Unicode digit
        • otherwise, "U+XXXX" is returned, where XXXX is the uppercase hexadecimal representation of c's Unicode codepoint, padded with zeros (0) to a length of 4 characters
        Parameters:
        c - the character
        Returns:
        the string representation