java.lang.Object
org.bzdev.util.JSUtilities.JSON.Parser
- Direct Known Subclasses:
JSUtilities.YAML.Parser
- Enclosing class:
- JSUtilities.JSON
Parser support class for JSON.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static enumSpecify whether or not comments are allowed and what their syntax is. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected intThis method is part of the implementation and is only used internally.protected longThis method is part of the implementation and is only used internally.protected JSUtilities.LocatorUsed internally. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected intGet the column This method is part of the implementation and is only used internally.protected intThe indentation after a new line.Return a map that associates line-number, column-number pairs with locations.Get the object generated by a parser.protected booleanhasComment(String s) Determine if a string has a comment This method is part of the implementation and is only used internally.protected intnextChar()Read a character.protected JSArrayparseArray(org.bzdev.util.JSUtilities.YAML.Parser.YAMLData ydata) Parse a JSON array.protected NumberParse a number.protected JSObjectparseObject(org.bzdev.util.JSUtilities.YAML.Parser.YAMLData ydata) Parse a YAML object.protected StringParse a JSON string.protected StringparseString(boolean isIdent) Parse a string.protected ObjectParse a JSON value.protected ObjectparseValue(org.bzdev.util.JSUtilities.YAML.Parser.YAMLData ydata) Parse a JSON value with string mapping.protected ObjectparseValueJS(org.bzdev.util.JSUtilities.YAML.Parser.YAMLData ydata) Parse a value for JSON This method is part of the implementation and is only used internally.protected voidpushChar(int ch) Push back an already-read character.protected voidpushString(String s) Push back an already-read string.protected StringreadLine()Read a string terminated by an EOL sequence, which is not part of the string.protected voidsetColumn(int col) Set the current column This method is used in init3 only.protected voidDetermine how comments are treated.protected voidSkip over whitespace.protected voidSkip over whitespace, restricted to a single lineprotected StringStrip a comment from a string.protected voidTag a location.
-
Field Details
-
locator
Used internally. -
lineno
protected long linenoThis method is part of the implementation and is only used internally. -
column
protected int columnThis method is part of the implementation and is only used internally.
-
-
Constructor Details
-
Parser
Constructor.- Parameters:
r- a reader.- Throws:
IOException- if an IO error occurred
-
-
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
Determine how comments are treated. The default isJSUtilities.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
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
Read a character.- Returns:
- the next character
- Throws:
IOException- if an IO error occurred
-
readLine
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
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
Strip a comment from a string.- Parameters:
s- the string- Returns:
- the string with comments removed.
-
getResults
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
Skip over whitespace.- Throws:
IOException- an error occurred
-
skipWhitespace1
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
Parse a JSON string.- Returns:
- a string
- Throws:
IOException- if an IO error occurred
-
parseString
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
Parse a number.- Returns:
- the number
- Throws:
IOException- an error occurred
-
parseValue
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
-