ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
nlohmann::detail::lexer< BasicJsonType > Class Template Reference

lexical analysis More...

#include <acts/blob/master/thirdparty/nlohmann_json/single_include/nlohmann/json.hpp>

+ Collaboration diagram for nlohmann::detail::lexer< BasicJsonType >:

Public Types

enum  token_type
 token types for the parser More...
 

Public Member Functions

 lexer (detail::input_adapter_t &&adapter)
 
 lexer (const lexer &)=delete
 
 lexer (lexer &&)=delete
 
lexeroperator= (lexer &)=delete
 
lexeroperator= (lexer &&)=delete
 
 ~lexer ()=default
 
constexpr number_integer_t get_number_integer () const noexcept
 return integer value
 
constexpr number_unsigned_t get_number_unsigned () const noexcept
 return unsigned integer value
 
constexpr number_float_t get_number_float () const noexcept
 return floating-point value
 
string_tget_string ()
 return current string value (implicitly resets the token; useful only once)
 
constexpr position_t get_position () const noexcept
 return position of last read token
 
std::string get_token_string () const
 
JSON_HEDLEY_RETURNS_NON_NULL
constexpr const char * 
get_error_message () const noexcept
 return syntax error message
 
bool skip_bom ()
 skip the UTF-8 byte order mark
 
token_type scan ()
 

Static Public Member Functions

JSON_HEDLEY_RETURNS_NON_NULL
static JSON_HEDLEY_CONST const
char * 
token_type_name (const token_type t) noexcept
 return name of values of type token_type (only used for errors)
 

Private Types

using number_integer_t = typename BasicJsonType::number_integer_t
 
using number_unsigned_t = typename BasicJsonType::number_unsigned_t
 
using number_float_t = typename BasicJsonType::number_float_t
 
using string_t = typename BasicJsonType::string_t
 

Private Member Functions

int get_codepoint ()
 get codepoint from 4 hex characters following \u
 
bool next_byte_in_range (std::initializer_list< int > ranges)
 check if the next byte(s) are inside a given range
 
token_type scan_string ()
 scan a string literal
 
token_type scan_number ()
 scan a number literal
 
token_type scan_literal (const char *literal_text, const std::size_t length, token_type return_type)
 
void reset () noexcept
 reset token_buffer; current character is beginning of token
 
std::char_traits< char >::int_type get ()
 
void unget ()
 unget current character (read it again on next get)
 
void add (int c)
 add a character to token_buffer
 

Static Private Member Functions

static JSON_HEDLEY_PURE char get_decimal_point () noexcept
 return the locale-dependent decimal point
 
static void strtof (float &f, const char *str, char **endptr) noexcept
 
static void strtof (double &f, const char *str, char **endptr) noexcept
 
static void strtof (long double &f, const char *str, char **endptr) noexcept
 

Private Attributes

detail::input_adapter_t ia = nullptr
 input adapter
 
std::char_traits< char >::int_type current = std::char_traits<char>::eof()
 the current character
 
bool next_unget = false
 whether the next get() call should just return current
 
position_t position {}
 the start position of the current token
 
std::vector< char > token_string {}
 raw input token string (for error messages)
 
string_t token_buffer {}
 buffer for variable-length tokens (numbers, strings)
 
const char * error_message = ""
 a description of occurred lexer errors
 
number_integer_t value_integer = 0
 
number_unsigned_t value_unsigned = 0
 
number_float_t value_float = 0
 
const char decimal_point_char = '.'
 the decimal point
 

Detailed Description

template<typename BasicJsonType>
class nlohmann::detail::lexer< BasicJsonType >

lexical analysis

This class organizes the lexical analysis during JSON deserialization.

Definition at line 7161 of file json.hpp.

View newest version in sPHENIX GitHub at line 7161 of file json.hpp

Member Typedef Documentation

template<typename BasicJsonType >
using nlohmann::detail::lexer< BasicJsonType >::number_float_t = typename BasicJsonType::number_float_t
private

Definition at line 7165 of file json.hpp.

View newest version in sPHENIX GitHub at line 7165 of file json.hpp

template<typename BasicJsonType >
using nlohmann::detail::lexer< BasicJsonType >::number_integer_t = typename BasicJsonType::number_integer_t
private

Definition at line 7163 of file json.hpp.

View newest version in sPHENIX GitHub at line 7163 of file json.hpp

template<typename BasicJsonType >
using nlohmann::detail::lexer< BasicJsonType >::number_unsigned_t = typename BasicJsonType::number_unsigned_t
private

Definition at line 7164 of file json.hpp.

View newest version in sPHENIX GitHub at line 7164 of file json.hpp

template<typename BasicJsonType >
using nlohmann::detail::lexer< BasicJsonType >::string_t = typename BasicJsonType::string_t
private

Definition at line 7166 of file json.hpp.

View newest version in sPHENIX GitHub at line 7166 of file json.hpp

Member Enumeration Documentation

template<typename BasicJsonType >
enum nlohmann::detail::lexer::token_type

token types for the parser

Definition at line 7170 of file json.hpp.

View newest version in sPHENIX GitHub at line 7170 of file json.hpp

Constructor & Destructor Documentation

template<typename BasicJsonType >
nlohmann::detail::lexer< BasicJsonType >::lexer ( detail::input_adapter_t &&  adapter)
inlineexplicit

Definition at line 7237 of file json.hpp.

View newest version in sPHENIX GitHub at line 7237 of file json.hpp

template<typename BasicJsonType >
nlohmann::detail::lexer< BasicJsonType >::lexer ( const lexer< BasicJsonType > &  )
delete
template<typename BasicJsonType >
nlohmann::detail::lexer< BasicJsonType >::lexer ( lexer< BasicJsonType > &&  )
delete
template<typename BasicJsonType >
nlohmann::detail::lexer< BasicJsonType >::~lexer ( )
default

Member Function Documentation

template<typename BasicJsonType >
void nlohmann::detail::lexer< BasicJsonType >::add ( int  c)
inlineprivate

add a character to token_buffer

Definition at line 8441 of file json.hpp.

View newest version in sPHENIX GitHub at line 8441 of file json.hpp

template<typename BasicJsonType >
std::char_traits<char>::int_type nlohmann::detail::lexer< BasicJsonType >::get ( )
inlineprivate

Definition at line 8377 of file json.hpp.

View newest version in sPHENIX GitHub at line 8377 of file json.hpp

References JSON_HEDLEY_LIKELY.

template<typename BasicJsonType >
int nlohmann::detail::lexer< BasicJsonType >::get_codepoint ( )
inlineprivate

get codepoint from 4 hex characters following \u

For input "\u c1 c2 c3 c4" the codepoint is: (c1 * 0x1000) + (c2 * 0x0100) + (c3 * 0x0010) + c4 = (c1 << 12) + (c2 << 8) + (c3 << 4) + (c4 << 0)

Furthermore, the possible characters '0'..'9', 'A'..'F', and 'a'..'f' must be converted to the integers 0x0..0x9, 0xA..0xF, 0xA..0xF, resp. The conversion is done by subtracting the offset (0x30, 0x37, and 0x57) between the ASCII value of the character and the desired integer value.

Returns
codepoint (0x0000..0xFFFF) or -1 in case of an error (e.g. EOF or non-hex character)

Definition at line 7280 of file json.hpp.

View newest version in sPHENIX GitHub at line 7280 of file json.hpp

References Acts::UnitConstants::u.

template<typename BasicJsonType >
static JSON_HEDLEY_PURE char nlohmann::detail::lexer< BasicJsonType >::get_decimal_point ( )
inlinestaticprivatenoexcept

return the locale-dependent decimal point

Definition at line 7254 of file json.hpp.

View newest version in sPHENIX GitHub at line 7254 of file json.hpp

template<typename BasicJsonType >
JSON_HEDLEY_RETURNS_NON_NULL constexpr const char* nlohmann::detail::lexer< BasicJsonType >::get_error_message ( ) const
inlinenoexcept

return syntax error message

Definition at line 8513 of file json.hpp.

View newest version in sPHENIX GitHub at line 8513 of file json.hpp

template<typename BasicJsonType >
constexpr number_float_t nlohmann::detail::lexer< BasicJsonType >::get_number_float ( ) const
inlinenoexcept

return floating-point value

Definition at line 8464 of file json.hpp.

View newest version in sPHENIX GitHub at line 8464 of file json.hpp

template<typename BasicJsonType >
constexpr number_integer_t nlohmann::detail::lexer< BasicJsonType >::get_number_integer ( ) const
inlinenoexcept

return integer value

Definition at line 8452 of file json.hpp.

View newest version in sPHENIX GitHub at line 8452 of file json.hpp

template<typename BasicJsonType >
constexpr number_unsigned_t nlohmann::detail::lexer< BasicJsonType >::get_number_unsigned ( ) const
inlinenoexcept

return unsigned integer value

Definition at line 8458 of file json.hpp.

View newest version in sPHENIX GitHub at line 8458 of file json.hpp

template<typename BasicJsonType >
constexpr position_t nlohmann::detail::lexer< BasicJsonType >::get_position ( ) const
inlinenoexcept

return position of last read token

Definition at line 8480 of file json.hpp.

View newest version in sPHENIX GitHub at line 8480 of file json.hpp

References position.

template<typename BasicJsonType >
string_t& nlohmann::detail::lexer< BasicJsonType >::get_string ( )
inline

return current string value (implicitly resets the token; useful only once)

Definition at line 8470 of file json.hpp.

View newest version in sPHENIX GitHub at line 8470 of file json.hpp

template<typename BasicJsonType >
std::string nlohmann::detail::lexer< BasicJsonType >::get_token_string ( ) const
inline

return the last read token (for errors only). Will never contain EOF (an arbitrary value that is not a valid char value, often -1), because 255 may legitimately occur. May contain NUL, which should be escaped.

Definition at line 8488 of file json.hpp.

View newest version in sPHENIX GitHub at line 8488 of file json.hpp

References c.

template<typename BasicJsonType >
bool nlohmann::detail::lexer< BasicJsonType >::next_byte_in_range ( std::initializer_list< int ranges)
inlineprivate

check if the next byte(s) are inside a given range

Adds the current byte and, for each passed range, reads a new byte and checks if it is inside the range. If a violation was detected, set up an error message and return false. Otherwise, return true.

Parameters
[in]rangeslist of integers; interpreted as list of pairs of inclusive lower and upper bound, respectively
Precondition
The passed list ranges must have 2, 4, or 6 elements; that is, 1, 2, or 3 pairs. This precondition is enforced by an assertion.
Returns
true if and only if no range violation was detected

Definition at line 7328 of file json.hpp.

View newest version in sPHENIX GitHub at line 7328 of file json.hpp

References JSON_HEDLEY_LIKELY.

template<typename BasicJsonType >
lexer& nlohmann::detail::lexer< BasicJsonType >::operator= ( lexer< BasicJsonType > &  )
delete
template<typename BasicJsonType >
lexer& nlohmann::detail::lexer< BasicJsonType >::operator= ( lexer< BasicJsonType > &&  )
delete
template<typename BasicJsonType >
void nlohmann::detail::lexer< BasicJsonType >::reset ( )
inlineprivatenoexcept

reset token_buffer; current character is beginning of token

Definition at line 8360 of file json.hpp.

View newest version in sPHENIX GitHub at line 8360 of file json.hpp

template<typename BasicJsonType >
token_type nlohmann::detail::lexer< BasicJsonType >::scan ( )
inline

Definition at line 8540 of file json.hpp.

View newest version in sPHENIX GitHub at line 8540 of file json.hpp

Referenced by init(), and medinit().

+ Here is the caller graph for this function:

template<typename BasicJsonType >
token_type nlohmann::detail::lexer< BasicJsonType >::scan_literal ( const char *  literal_text,
const std::size_t  length,
token_type  return_type 
)
inlineprivate
Parameters
[in]literal_textthe literal text to expect
[in]lengththe length of the passed literal text
[in]return_typethe token type to return on success

Definition at line 8340 of file json.hpp.

View newest version in sPHENIX GitHub at line 8340 of file json.hpp

References JSON_HEDLEY_UNLIKELY, and BTOF::length.

template<typename BasicJsonType >
token_type nlohmann::detail::lexer< BasicJsonType >::scan_number ( )
inlineprivate

scan a number literal

This function scans a string according to Sect. 6 of RFC 7159.

The function is realized with a deterministic finite state machine derived from the grammar described in RFC 7159. Starting in state "init", the input is read and used to determined the next state. Only state "done" accepts the number. State "error" is a trap state to model errors. In the table below, "anything" means any character but the ones listed before.

state 0 1-9 e E + - . anything
init zero any1 [error] [error] minus [error] [error]
minus zero any1 [error] [error] [error] [error] [error]
zero done done exponent done done decimal1 done
any1 any1 any1 exponent done done decimal1 done
decimal1 decimal2 [error] [error] [error] [error] [error] [error]
decimal2 decimal2 decimal2 exponent done done done done
exponent any2 any2 [error] sign sign [error] [error]
sign any2 any2 [error] [error] [error] [error] [error]
any2 any2 any2 done done done done done

The state machine is realized with one label per state (prefixed with "scan_number_") and goto statements between them. The state machine contains cycles, but any cycle can be left when EOF is read. Therefore, the function is guaranteed to terminate.

During scanning, the read bytes are stored in token_buffer. This string is then converted to a signed integer, an unsigned integer, or a floating-point number.

Returns
token_type::value_unsigned, token_type::value_integer, or token_type::value_float if number could be successfully scanned, token_type::parse_error otherwise
Note
The scanner is independent of the current locale. Internally, the locale's decimal point is used instead of . to work with the locale-dependent converters.

Definition at line 8009 of file json.hpp.

View newest version in sPHENIX GitHub at line 8009 of file json.hpp

References x.

template<typename BasicJsonType >
token_type nlohmann::detail::lexer< BasicJsonType >::scan_string ( )
inlineprivate

scan a string literal

This function scans a string according to Sect. 7 of RFC 7159. While scanning, bytes are escaped and copied into buffer token_buffer. Then the function returns successfully, token_buffer is not null-terminated (as it may contain \0 bytes), and token_buffer.size() is the number of bytes in the string.

Returns
token_type::value_string if string could be successfully scanned, token_type::parse_error otherwise
Note
In case of errors, variable error_message contains a textual description.

Definition at line 7365 of file json.hpp.

View newest version in sPHENIX GitHub at line 7365 of file json.hpp

References JSON_HEDLEY_LIKELY, JSON_HEDLEY_UNLIKELY, and Acts::UnitConstants::u.

template<typename BasicJsonType >
bool nlohmann::detail::lexer< BasicJsonType >::skip_bom ( )
inline

skip the UTF-8 byte order mark

Returns
true iff there is no BOM or the correct BOM has been skipped

Definition at line 8526 of file json.hpp.

View newest version in sPHENIX GitHub at line 8526 of file json.hpp

template<typename BasicJsonType >
static void nlohmann::detail::lexer< BasicJsonType >::strtof ( float &  f,
const char *  str,
char **  endptr 
)
inlinestaticprivatenoexcept

Definition at line 7952 of file json.hpp.

View newest version in sPHENIX GitHub at line 7952 of file json.hpp

template<typename BasicJsonType >
static void nlohmann::detail::lexer< BasicJsonType >::strtof ( double &  f,
const char *  str,
char **  endptr 
)
inlinestaticprivatenoexcept

Definition at line 7958 of file json.hpp.

View newest version in sPHENIX GitHub at line 7958 of file json.hpp

template<typename BasicJsonType >
static void nlohmann::detail::lexer< BasicJsonType >::strtof ( long double &  f,
const char *  str,
char **  endptr 
)
inlinestaticprivatenoexcept

Definition at line 7964 of file json.hpp.

View newest version in sPHENIX GitHub at line 7964 of file json.hpp

template<typename BasicJsonType >
JSON_HEDLEY_RETURNS_NON_NULL static JSON_HEDLEY_CONST const char* nlohmann::detail::lexer< BasicJsonType >::token_type_name ( const token_type  t)
inlinestaticnoexcept

return name of values of type token_type (only used for errors)

Definition at line 7194 of file json.hpp.

View newest version in sPHENIX GitHub at line 7194 of file json.hpp

References t.

template<typename BasicJsonType >
void nlohmann::detail::lexer< BasicJsonType >::unget ( )
inlineprivate

unget current character (read it again on next get)

We implement unget by setting variable next_unget to true. The input is not changed - we just simulate ungetting by modifying chars_read_total, chars_read_current_line, and token_string. The next call to get() will behave as if the unget character is read again.

Definition at line 8414 of file json.hpp.

View newest version in sPHENIX GitHub at line 8414 of file json.hpp

References JSON_HEDLEY_LIKELY.

Member Data Documentation

template<typename BasicJsonType >
std::char_traits<char>::int_type nlohmann::detail::lexer< BasicJsonType >::current = std::char_traits<char>::eof()
private

the current character

Definition at line 8616 of file json.hpp.

View newest version in sPHENIX GitHub at line 8616 of file json.hpp

template<typename BasicJsonType >
const char nlohmann::detail::lexer< BasicJsonType >::decimal_point_char = '.'
private

the decimal point

Definition at line 8639 of file json.hpp.

View newest version in sPHENIX GitHub at line 8639 of file json.hpp

template<typename BasicJsonType >
const char* nlohmann::detail::lexer< BasicJsonType >::error_message = ""
private

a description of occurred lexer errors

Definition at line 8631 of file json.hpp.

View newest version in sPHENIX GitHub at line 8631 of file json.hpp

template<typename BasicJsonType >
detail::input_adapter_t nlohmann::detail::lexer< BasicJsonType >::ia = nullptr
private

input adapter

Definition at line 8613 of file json.hpp.

View newest version in sPHENIX GitHub at line 8613 of file json.hpp

template<typename BasicJsonType >
bool nlohmann::detail::lexer< BasicJsonType >::next_unget = false
private

whether the next get() call should just return current

Definition at line 8619 of file json.hpp.

View newest version in sPHENIX GitHub at line 8619 of file json.hpp

template<typename BasicJsonType >
position_t nlohmann::detail::lexer< BasicJsonType >::position {}
private

the start position of the current token

Definition at line 8622 of file json.hpp.

View newest version in sPHENIX GitHub at line 8622 of file json.hpp

template<typename BasicJsonType >
string_t nlohmann::detail::lexer< BasicJsonType >::token_buffer {}
private

buffer for variable-length tokens (numbers, strings)

Definition at line 8628 of file json.hpp.

View newest version in sPHENIX GitHub at line 8628 of file json.hpp

template<typename BasicJsonType >
std::vector<char> nlohmann::detail::lexer< BasicJsonType >::token_string {}
private

raw input token string (for error messages)

Definition at line 8625 of file json.hpp.

View newest version in sPHENIX GitHub at line 8625 of file json.hpp

template<typename BasicJsonType >
number_float_t nlohmann::detail::lexer< BasicJsonType >::value_float = 0
private

Definition at line 8636 of file json.hpp.

View newest version in sPHENIX GitHub at line 8636 of file json.hpp

template<typename BasicJsonType >
number_integer_t nlohmann::detail::lexer< BasicJsonType >::value_integer = 0
private

Definition at line 8634 of file json.hpp.

View newest version in sPHENIX GitHub at line 8634 of file json.hpp

template<typename BasicJsonType >
number_unsigned_t nlohmann::detail::lexer< BasicJsonType >::value_unsigned = 0
private

Definition at line 8635 of file json.hpp.

View newest version in sPHENIX GitHub at line 8635 of file json.hpp


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