ezEngine  Milestone 7
ezJSONParser Class Referenceabstract

A low level JSON parser that can incrementally parse the structure of a JSON document. More...

#include <JSONParser.h>

Inheritance diagram for ezJSONParser:

Classes

struct  JSONState
 

Public Member Functions

 ezJSONParser ()
 Constructor.
 
void SetLogInterface (ezLogInterface *pLog)
 Allows to specify an ezLogInterface through which errors and warnings are reported.
 

Protected Member Functions

void SetInputStream (ezStreamReaderBase &stream, ezUInt32 uiFirstLineOffset=0)
 Resets the parser to the start state and configures it to read from the given stream.
 
bool ContinueParsing ()
 Does one parsing step. More...
 
void ParseAll ()
 Calls ContinueParsing() in a loop until that returns false.
 
void SkipObject ()
 Skips the rest of the currently open object. No OnEndArray() and OnEndObject() calls will be done for this object, cleanup must be done manually.
 
void SkipArray ()
 Skips the rest of the currently open array. No OnEndArray() and OnEndObject() calls will be done for this object, cleanup must be done manually.
 
void ParsingError (const char *szMessage, bool bFatal)
 Outputs that a parsing error was detected (via OnParsingError) and stops further parsing, if bFatal is set to true.
 

Protected Attributes

ezLogInterfacem_pLogInterface
 

Private Types

enum  State {
  NotStarted, Finished, ReadingObject, ReadingArray,
  ReadingValue, ReadingVariable, ExpectSeparator
}
 

Private Member Functions

virtual bool OnVariable (const char *szVarName)=0
 Called whenever a new variable is encountered. The variable name is passed along. At this point the type of the variable (simple, array, object) is not yet determined. More...
 
virtual void OnReadValue (const char *szValue)=0
 Called whenever a new value is read. More...
 
virtual void OnReadValue (double fValue)=0
 Called whenever a new value is read. More...
 
virtual void OnReadValue (bool bValue)=0
 Called whenever a new value is read. More...
 
virtual void OnReadValueNULL ()=0
 Called whenever a new value is read. More...
 
virtual void OnBeginObject ()=0
 Called when a new object is encountered. More...
 
virtual void OnEndObject ()=0
 Called when the end of an object is encountered.
 
virtual void OnBeginArray ()=0
 Called when a new array is encountered. More...
 
virtual void OnEndArray ()=0
 Called when the end of an array is encountered.
 
virtual void OnParsingError (const char *szMessage, bool bFatal, ezUInt32 uiLine, ezUInt32 uiColumn)
 Called when something unexpected is encountered in the JSON document. More...
 
void StartParsing ()
 
void SkipWhitespace ()
 
void SkipString ()
 
void ReadString ()
 
double ReadNumber ()
 
void ReadWord ()
 
void ContinueObject ()
 
void ContinueArray ()
 
void ContinueVariable ()
 
void ContinueValue ()
 
void ContinueSeparator ()
 
bool ReadCharacter (bool bSkipComments)
 
void ReadNextByte ()
 
void SkipStack (State s)
 

Private Attributes

ezUInt8 m_uiCurByte
 
ezUInt8 m_uiNextByte
 
ezUInt32 m_uiCurLine
 
ezUInt32 m_uiCurColumn
 
ezStreamReaderBasem_pInput
 
ezHybridArray< JSONState, 32 > m_StateStack
 
ezHybridArray< ezUInt8, 4096 > m_TempString
 
bool m_bSkippingMode
 

Detailed Description

A low level JSON parser that can incrementally parse the structure of a JSON document.

The document structure is returned through virtual functions that need to be overridden.

Member Function Documentation

bool ezJSONParser::ContinueParsing ( )
protected

Does one parsing step.

While this function returns true, the document has not been parsed completely. This function may call any of the OnSomething functions through which the structure of the document is obtained. This function calls at most one such callback, but there is no guarantee that it calls any at all, it might just advance its internal state.

virtual void ezJSONParser::OnBeginArray ( )
privatepure virtual

Called when a new array is encountered.

Directly following a call to OnVariable(), this means the variable is of type 'array' (and has a name). In between calls to OnBeginArray() and OnEndArray() it is another value in the array.

Implemented in ezJSONReader.

virtual void ezJSONParser::OnBeginObject ( )
privatepure virtual

Called when a new object is encountered.

Directly following a call to OnVariable(), this means the variable is of type 'object' (and has a name). In between calls to OnBeginArray() and OnEndArray() it is another value in the array.

Implemented in ezJSONReader.

virtual void ezJSONParser::OnParsingError ( const char *  szMessage,
bool  bFatal,
ezUInt32  uiLine,
ezUInt32  uiColumn 
)
inlineprivatevirtual

Called when something unexpected is encountered in the JSON document.

The error message describes what was expected and what was encountered. If bFatal is true, the error has left the parser in an unrecoverable state and thus it not continue parsing. In that case client code will need to clean up it's open state, as no further OnEndObject() / OnEndArray() will be called. If bFatal is false, the document does not contain valid JSON, but the parser is able to continue still.

Reimplemented in ezJSONReader.

virtual void ezJSONParser::OnReadValue ( const char *  szValue)
privatepure virtual

Called whenever a new value is read.

Directly following a call to OnVariable(), this means that the variable is a simple variable. In between calls to OnBeginArray() and OnEndArray() it is another value in the array.

Implemented in ezJSONReader.

virtual void ezJSONParser::OnReadValue ( double  fValue)
privatepure virtual

Called whenever a new value is read.

Directly following a call to OnVariable(), this means that the variable is a simple variable. In between calls to OnBeginArray() and OnEndArray() it is another value in the array.

Implemented in ezJSONReader.

virtual void ezJSONParser::OnReadValue ( bool  bValue)
privatepure virtual

Called whenever a new value is read.

Directly following a call to OnVariable(), this means that the variable is a simple variable. In between calls to OnBeginArray() and OnEndArray() it is another value in the array.

Implemented in ezJSONReader.

virtual void ezJSONParser::OnReadValueNULL ( )
privatepure virtual

Called whenever a new value is read.

Directly following a call to OnVariable(), this means that the variable is a simple variable. In between calls to OnBeginArray() and OnEndArray() it is another value in the array.

Implemented in ezJSONReader.

virtual bool ezJSONParser::OnVariable ( const char *  szVarName)
privatepure virtual

Called whenever a new variable is encountered. The variable name is passed along. At this point the type of the variable (simple, array, object) is not yet determined.

The entire variable (independent of whether it is a simple value, an array or an object) can be skipped by returning false.

Implemented in ezJSONReader.

void ezJSONParser::ReadString ( )
private
Todo:
Support escaped Unicode literals? ()

The documentation for this class was generated from the following files: