tetengo 1.8.1
A multipurpose library set
Loading...
Searching...
No Matches
tetengo::json::json_grammar Class Reference

A JSON grammar. More...

#include <json_grammar.hpp>

+ Inheritance diagram for tetengo::json::json_grammar:
+ Collaboration diagram for tetengo::json::json_grammar:

Public Types

enum class  primitive_type_type { string , number , boolean , null }
 The primitive type type. More...
 
enum class  structure_type_type { object , member , array }
 The structure type type. More...
 
enum class  structure_open_close_type { open , close }
 The structure open-close type. More...
 
using primitive_handler_type = std::function< bool(primitive_type_type type, const std::string_view &value)>
 The primitive handler type.
 
using structure_handler_type = std::function< bool(structure_type_type type, structure_open_close_type open_close, const std::unordered_map< std::string_view, std::string_view > &attributes)>
 The structure handler type.
 

Public Member Functions

 json_grammar (primitive_handler_type primitive_handler, structure_handler_type structure_handler)
 Creates a JSON grammar.
 
 ~json_grammar ()
 Destroys the JSON grammar.
 
bool parse (reader &reader_) const
 Parses a text.
 

Detailed Description

A JSON grammar.

Based on RFC 8259.

Member Typedef Documentation

◆ primitive_handler_type

using tetengo::json::json_grammar::primitive_handler_type = std::function<bool(primitive_type_type type, const std::string_view& value)>

The primitive handler type.

Parameters

  • value: A value.
  • type: A type.
Return values
trueWhen the parsing is successful.
falseOtherwise.

◆ structure_handler_type

using tetengo::json::json_grammar::structure_handler_type = std::function<bool( structure_type_type type, structure_open_close_type open_close, const std::unordered_map<std::string_view, std::string_view>& attributes)>

The structure handler type.

Parameters

  • type: A type.
  • open_close: An open or close state.
  • value: A value.
Return values
trueWhen the parsing is successful.
falseOtherwise.

Member Enumeration Documentation

◆ primitive_type_type

The primitive type type.

Enumerator
string 

A string.

number 

A number.

boolean 

A boolean.

null 

A null.

◆ structure_open_close_type

The structure open-close type.

Enumerator
open 

Opening.

close 

Closing.

◆ structure_type_type

The structure type type.

Enumerator
object 

An object.

member 

A member.

array 

An array.

Constructor & Destructor Documentation

◆ json_grammar()

tetengo::json::json_grammar::json_grammar ( primitive_handler_type  primitive_handler,
structure_handler_type  structure_handler 
)

Creates a JSON grammar.

Parameters
primitive_handlerA primitive element handler.
structure_handlerA structure element handler.

Member Function Documentation

◆ parse()

bool tetengo::json::json_grammar::parse ( reader reader_) const

Parses a text.

Parameters
reader_A reader.
Return values
trueWhen parsing is successful.
falseOtherwise.

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