Class JSUtilities.JSON.Parser

java.lang.Object
org.bzdev.util.JSUtilities.JSON.Parser
Direct Known Subclasses:
JSUtilities.YAML.Parser
Enclosing class:
JSUtilities.JSON

public static class JSUtilities.JSON.Parser extends Object
Parser support class for JSON.
  • Field Details

    • locator

      protected JSUtilities.Locator locator
      Used internally.
    • lineno

      protected long lineno
      This method is part of the implementation and is only used internally.
    • column

      protected int column
      This method is part of the implementation and is only used internally.
  • Constructor Details

  • Method Details

    • tagLocation

      protected void tagLocation()
      Tag a location. Used internally.
    • getLocationMap

      Return a map that associates line-number, column-number pairs with locations.
      Returns:
      the map
    • getColumn

      protected int getColumn()
      Get the column This method is part of the implementation and is only used internally.
      Returns:
      the column
    • setCommentMode

      protected void setCommentMode(JSUtilities.JSON.Parser.CommentMode mode)
      Determine how comments are treated. The default is JSUtilities.JSON.Parser.CommentMode.JS.
      Parameters:
      mode - the comment mode
    • setColumn

      protected void setColumn(int col)
      Set the current column This method is used in init3 only.
      Parameters:
      col - the column number
    • pushChar

      protected void pushChar(int ch)
      Push back an already-read character. The pushback stack is finite (maximum of 512 characters). The characters are assumed to be on the same line.
      Parameters:
      ch - the character
    • pushString

      protected void pushString(String s)
      Push back an already-read string. The pushback stack is finite (maximum of 512 characters). The characters are assumed to be on the same line. The values pushed basck included delimiting double quotes and some characters are escaped.

      This methods is used by init3 in the YAML parser.

      Parameters:
      s - the string to push back
    • nextChar

      protected int nextChar() throws IOException
      Read a character.
      Returns:
      the next character
      Throws:
      IOException - if an IO error occurred
    • readLine

      protected String readLine() throws IOException
      Read a string terminated by an EOL sequence, which is not part of the string.
      Returns:
      the string
      Throws:
      IOException - an IO error occurred
    • hasComment

      protected boolean hasComment(String s)
      Determine if a string has a comment This method is part of the implementation and is only used internally.
      Parameters:
      s - a string
      Returns:
      true if s has a comment; false otherwise
    • stripComment

      protected String stripComment(String s)
      Strip a comment from a string.
      Parameters:
      s - the string
      Returns:
      the string with comments removed.
    • getResults

      public Object getResults() throws IOException
      Get the object generated by a parser.
      Returns:
      the object (a Boolean, Integer, Long, Double, JSArray, JSObject, or the value null)
      Throws:
      IOException - if an IO error occurred
    • getLineIndentation

      protected int getLineIndentation()
      The indentation after a new line.
      Returns:
      the indentation
    • skipWhitespace

      protected void skipWhitespace() throws IOException
      Skip over whitespace.
      Throws:
      IOException - an error occurred
    • skipWhitespace1

      protected void skipWhitespace1() throws IOException
      Skip over whitespace, restricted to a single line
      Throws:
      IOException - an error occurred
    • parseObject

      protected JSObject parseObject(org.bzdev.util.JSUtilities.YAML.Parser.YAMLData ydata) throws IOException
      Parse a YAML object. This method is part of the implementation and is only used internally.
      Parameters:
      ydata - YAML data
      Returns:
      the parsed object
      Throws:
      IOException - an error occurred
    • parseArray

      protected JSArray parseArray(org.bzdev.util.JSUtilities.YAML.Parser.YAMLData ydata) throws IOException
      Parse a JSON array.
      Parameters:
      ydata - YAML data
      Returns:
      the parsed array
      Throws:
      IOException - an error occurred
    • parseString

      protected String parseString() throws IOException
      Parse a JSON string.
      Returns:
      a string
      Throws:
      IOException - if an IO error occurred
    • parseString

      protected String parseString(boolean isIdent) throws IOException
      Parse a string.
      Parameters:
      isIdent - true if the string is an identifier without double quotes; false otherwise
      Returns:
      the string
      Throws:
      IOException - an error occurred
    • parseNumber

      protected Number parseNumber() throws IOException
      Parse a number.
      Returns:
      the number
      Throws:
      IOException - an error occurred
    • parseValue

      protected Object parseValue() throws IOException
      Parse a JSON value. This method is part of the implementation and is only used internally.
      Returns:
      a parsed object
      Throws:
      IOException - an error occurred
    • parseValue

      protected Object parseValue(org.bzdev.util.JSUtilities.YAML.Parser.YAMLData ydata) throws IOException
      Parse a JSON value with string mapping. This method is part of the implementation and is only used internally.
      Parameters:
      ydata - YAML data
      Returns:
      the parsed object
      Throws:
      IOException - an error occurred
    • parseValueJS

      protected Object parseValueJS(org.bzdev.util.JSUtilities.YAML.Parser.YAMLData ydata) throws IOException
      Parse a value for JSON This method is part of the implementation and is only used internally.
      Parameters:
      ydata - YAML data
      Returns:
      the parsed object
      Throws:
      IOException - if an IO error occurred