Package nonapi.io.github.classgraph.json
Class JSONParser
- java.lang.Object
-
- nonapi.io.github.classgraph.types.Parser
-
- nonapi.io.github.classgraph.json.JSONParser
-
final class JSONParser extends Parser
A JSON parser, based on the PEG grammar found at: https://github.com/azatoth/PanPG/blob/master/grammars/JSON.peg
-
-
Constructor Summary
Constructors Modifier Constructor Description privateJSONParser(java.lang.String string)Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private intgetAndParseHexChar()Get and parse a hexadecimal digit character.private java.lang.ObjectparseJSON()Parse a JSON type (object / array / value).(package private) static java.lang.ObjectparseJSON(java.lang.String str)Parse a JSON object, array, string, value or object reference.private JSONArrayparseJSONArray()Array ← "[" ( JSON ( "," JSON )* / S? ) "]"private JSONObjectparseJSONObject()Parse a JSON Object.private java.lang.NumberparseNumber()Parses and returns Integer, Long or Double type.private java.lang.CharSequenceparseString()Parse a quoted/escaped JSON string.-
Methods inherited from class nonapi.io.github.classgraph.types.Parser
advance, appendToToken, appendToToken, currToken, expect, getc, getPosition, getPositionInfo, getState, getSubsequence, getSubstring, hasMore, next, peek, peekExpect, peekMatches, setPosition, setState, skipWhitespace, toString
-
-
-
-
Constructor Detail
-
JSONParser
private JSONParser(java.lang.String string) throws ParseExceptionConstructor.- Parameters:
string- the string- Throws:
ParseException- if parsing fails
-
-
Method Detail
-
getAndParseHexChar
private int getAndParseHexChar() throws ParseExceptionGet and parse a hexadecimal digit character.- Returns:
- the hex char
- Throws:
ParseException- if the character was not hexadecimal
-
parseString
private java.lang.CharSequence parseString() throws ParseExceptionParse a quoted/escaped JSON string.String ← S? ["] ( [^ " \ U+0000-U+001F ] / Escape )* ["] S? Escape ← [\] ( [ " / \ b f n r t ] / UnicodeEscape ) UnicodeEscape ← "u" [0-9A-Fa-f]{4}- Returns:
- the char sequence
- Throws:
ParseException- if the escape sequence was invalid
-
parseNumber
private java.lang.Number parseNumber() throws ParseExceptionParses and returns Integer, Long or Double type.Number ← Minus? IntegralPart FractionalPart? ExponentPart? Minus ← "-" IntegralPart ← "0" / [1-9] [0-9]* FractionalPart ← "." [0-9]+ ExponentPart ← ( "e" / "E" ) ( "+" / "-" )? [0-9]+- Returns:
- the number
- Throws:
ParseException- if parsing fails
-
parseJSONArray
private JSONArray parseJSONArray() throws ParseException
Array ← "[" ( JSON ( "," JSON )* / S? ) "]".- Returns:
- the JSON array
- Throws:
ParseException- if parsing fails
-
parseJSONObject
private JSONObject parseJSONObject() throws ParseException
Parse a JSON Object.Object ← "{" ( String ":" JSON ( "," String ":" JSON )* / S? ) "}"- Returns:
- the JSON object
- Throws:
ParseException- if parsing fails
-
parseJSON
private java.lang.Object parseJSON() throws ParseExceptionParse a JSON type (object / array / value).String values will have CharSequence type. Numerical values will have Integer, Long or Double type. Can return null for JSON null value.
JSON ← S? ( Object / Array / String / True / False / Null / Number ) S?- Returns:
- the parsed JSON object
- Throws:
ParseException- if parsing fails
-
parseJSON
static java.lang.Object parseJSON(java.lang.String str) throws ParseExceptionParse a JSON object, array, string, value or object reference.- Parameters:
str- the str- Returns:
- the parsed JSON object
- Throws:
ParseException- if parsing fails
-
-