Package de.marhali.json5.stream
Class Json5Lexer
- java.lang.Object
-
- de.marhali.json5.stream.Json5Lexer
-
public class Json5Lexer extends java.lang.ObjectThis 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 constructJson5Object's andJson5Array's.- See Also:
- Json5 Standard.
-
-
Field Summary
Fields Modifier and Type Field Description protected Json5Optionsoptionsprotected booleanrootwhether 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 specificReader.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidback()Forces the parser to re-read the last characterprotected static java.lang.StringcharToString(char c)Converts a character into a string representation: ifc == 0,"EOF"is returned ifcfulfills one of the following conditions,"'x'"is returned, wherexis the value returned byCharacter.toString(char): ifcis an extended ASCII character (U+0001-U+00FF), exceptcontrol charactersifcis aUnicode letterifcis aUnicode digitotherwise,"U+XXXX"is returned, whereXXXXis the uppercase hexadecimal representation ofc's Unicode codepoint, padded with zeros (0) to a length of 4 charactersjava.lang.StringconsumeComment()Returns the last comment that was read and clears it.charnextClean()Reads until encountering a character that is not a whitespace according to the JSON5 Specificationjava.lang.StringnextMemberName()Reads a member name from the source according to the JSON5 SpecificationJson5ElementnextValue()Reads a value from the source according to the JSON5 SpecificationJson5ExceptionsyntaxError(java.lang.String message)Constructs a newJson5Exceptionwith a detail messageJson5ExceptionsyntaxError(java.lang.String message, java.lang.Throwable cause)Constructs a newJson5Exceptionwith a detail message and a causing exceptionjava.lang.StringtoString()
-
-
-
Field Detail
-
options
protected final Json5Options options
-
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 specificReader.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
nullif 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
0if 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
-
nextValue
public Json5Element nextValue()
Reads a value from the source according to the JSON5 Specification- Returns:
- a
Json5Elementvalue
-
syntaxError
public Json5Exception syntaxError(java.lang.String message, java.lang.Throwable cause)
Constructs a newJson5Exceptionwith a detail message and a causing exception- Parameters:
message- the detail messagecause- the causing exception- Returns:
- a
Json5Exception
-
syntaxError
public Json5Exception syntaxError(java.lang.String message)
Constructs a newJson5Exceptionwith a detail message- Parameters:
message- the detail message- Returns:
- a
Json5Exception
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.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
cfulfills one of the following conditions,"'x'"is returned, wherexis the value returned byCharacter.toString(char):- if
cis an extended ASCII character (U+0001-U+00FF), exceptcontrol characters - if
cis aUnicode letter - if
cis aUnicode digit
- if
- otherwise,
"U+XXXX"is returned, whereXXXXis the uppercase hexadecimal representation ofc's Unicode codepoint, padded with zeros (0) to a length of 4 characters
- Parameters:
c- the character- Returns:
- the string representation
- if
-
-