nlohmann::detail::lexer
nlohmann::detail::lexer_base< BasicJsonType >
json.hpp
typename BasicJsonType BasicJsonType
typename InputAdapterType InputAdapterType
typename BasicJsonType::number_integer_t using nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::number_integer_t = typename BasicJsonType::number_integer_t number_integer_t
typename BasicJsonType::number_unsigned_t using nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::number_unsigned_t = typename BasicJsonType::number_unsigned_t number_unsigned_t
typename BasicJsonType::number_float_t using nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::number_float_t = typename BasicJsonType::number_float_t number_float_t
typename BasicJsonType::string_t using nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::string_t = typename BasicJsonType::string_t string_t
typename InputAdapterType::char_type using nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::char_type = typename InputAdapterType::char_type char_type
typename std::char_traits< char_type >::int_type using nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::char_int_type = typename std::char_traits<char_type>::int_type char_int_type
typename lexer_base< BasicJsonType >::token_type using nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::token_type = typename lexer_base<BasicJsonType>::token_type token_type
InputAdapterType InputAdapterType nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::ia ia

input adapter

const bool const bool nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::ignore_comments ignore_comments = false

whether comments should be ignored (true) or signaled as errors (false)

char_int_type char_int_type nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::current current = std::char_traits<char_type>::eof()

the current character

bool bool nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::next_unget next_unget = false

whether the next get() call should just return current

position_t position_t nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::position position {}

the start position of the current token

std::vector< char_type > std::vector<char_type> nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::token_string token_string {}

raw input token string (for error messages)

string_t string_t nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::token_buffer token_buffer {}

buffer for variable-length tokens (numbers, strings)

const char * const char* nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::error_message error_message = ""

a description of occurred lexer errors

number_integer_t number_integer_t nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::value_integer value_integer = 0
number_unsigned_t number_unsigned_t nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::value_unsigned value_unsigned = 0
number_float_t number_float_t nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::value_float value_float = 0
const char_int_type const char_int_type nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::decimal_point_char decimal_point_char = '.'

the decimal point

nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::lexer
(InputAdapterType &&adapter, bool ignore_comments_=false) noexcept
lexer
InputAdapterType && adapter
bool ignore_comments_ false
JSON_HEDLEY_PURE
nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::lexer
(const lexer &)=delete
lexer
const lexer &
nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::lexer
(lexer &&)=default
lexer
lexer &&
lexer & lexer& nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::operator= (lexer &)=delete operator= lexer &
lexer & lexer& nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::operator= (lexer &&)=default operator= lexer &&
nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::~lexer
()=default
~lexer
constexpr number_integer_t constexpr number_integer_t nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::get_number_integer () const noexcept get_number_integer

return integer value

constexpr number_unsigned_t constexpr number_unsigned_t nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::get_number_unsigned () const noexcept get_number_unsigned

return unsigned integer value

constexpr number_float_t constexpr number_float_t nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::get_number_float () const noexcept get_number_float

return floating-point value

string_t & string_t& nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::get_string () get_string

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

constexpr position_t constexpr position_t nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::get_position () const noexcept get_position

return position of last read token

std::string std::string nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::get_token_string () const get_token_string

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.

JSON_HEDLEY_RETURNS_NON_NULL
nlohmann::detail::string
JSON_HEDLEY_RETURNS_NON_NULL constexpr const char * JSON_HEDLEY_RETURNS_NON_NULL constexpr const char* nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::get_error_message () const noexcept get_error_message

return syntax error message

bool bool nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::skip_bom () skip_bom

skip the UTF-8 byte order mark

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

void void nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::skip_whitespace () skip_whitespace
token_type token_type nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::scan () scan nlohmann::detail::binary_reader< BasicJsonType, InputAdapterType, SAX >::get_ubjson_high_precision_number
JSON_HEDLEY_PURE char static JSON_HEDLEY_PURE char nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::get_decimal_point () noexcept get_decimal_point

return the locale-dependent decimal point

JSON_ASSERT
void static void nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::strtof (float &f, const char *str, char **endptr) noexcept strtof float & f const char * str char ** endptr JSON_HEDLEY_NON_NULL
void static void nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::strtof (double &f, const char *str, char **endptr) noexcept strtof double & f const char * str char ** endptr JSON_HEDLEY_NON_NULL
void static void nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::strtof (long double &f, const char *str, char **endptr) noexcept strtof long double & f const char * str char ** endptr
int int nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::get_codepoint () get_codepoint

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.

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

JSON_ASSERT
bool bool nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::next_byte_in_range (std::initializer_list< char_int_type > ranges) next_byte_in_range std::initializer_list< char_int_type > ranges

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.

ranges

list of integers; interpreted as list of pairs of inclusive lower and upper bound, respectively

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.

true if and only if no range violation was detected

JSON_ASSERT
JSON_HEDLEY_LIKELY
token_type token_type nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::scan_string () scan_string

scan a string literal

This function scans a string according to Sect. 7 of RFC 8259. 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.

token_type::value_string if string could be successfully scanned, token_type::parse_error otherwise

In case of errors, variable error_message contains a textual description.

JSON_ASSERT
JSON_HEDLEY_LIKELY
JSON_HEDLEY_UNLIKELY
bool bool nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::scan_comment () scan_comment

scan a comment

whether comment could be scanned successfully

JSON_HEDLEY_NON_NULL
token_type token_type nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::scan_number () scan_number

scan a number literal

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

The function is realized with a deterministic finite state machine derived from the grammar described in RFC 8259. 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 | decimal2 | [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.

token_type::value_unsigned, token_type::value_integer, or token_type::value_float if number could be successfully scanned, token_type::parse_error otherwise

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.

JSON_ASSERT
JSON_HEDLEY_NON_NULL
token_type token_type nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::scan_literal (const char_type *literal_text, const std::size_t length, token_type return_type) scan_literal const char_type * literal_text const std::size_t length token_type return_type

literal_text

the literal text to expect

length

the length of the passed literal text

return_type

the token type to return on success

JSON_ASSERT
JSON_HEDLEY_UNLIKELY
void void nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::reset () noexcept reset

reset token_buffer; current character is beginning of token

char_int_type char_int_type nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::get () get JSON_HEDLEY_LIKELY
void void nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::unget () unget

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.

JSON_ASSERT
JSON_HEDLEY_LIKELY
void void nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::add (char_int_type c) add char_int_type c

add a character to token_buffer

lexical analysis

This class organizes the lexical analysis during JSON deserialization.

nlohmann::detail::lexer< BasicJsonType, InputAdapterType >
nlohmann::detail::lexer_base< BasicJsonType >
number_float_t
size_t
T
std::vector< T >
+elements
char_type
nlohmann::detail::lexer< BasicJsonType, InputAdapterType >
-ia
-position
-value_float
-token_buffer
-value_unsigned
-current
-value_integer
-next_unget
-ignore_comments
-decimal_point_char
-error_message
-token_string
int_type
nlohmann::detail::lexer_base< BasicJsonType >
std::vector< char_type >
+elements
< char_type >
InputAdapterType
number_unsigned_t
const char *
string_t
const char_int_type
number_integer_t
bool
nlohmann::detail::position_t
+chars_read_total
+chars_read_current_line
+lines_read
- nlohmann::detail::lexer
  add
- nlohmann::detail::lexer
  char_int_type
- nlohmann::detail::lexer
  char_type
- nlohmann::detail::lexer
  current
- nlohmann::detail::lexer
  decimal_point_char
- nlohmann::detail::lexer
  error_message
- nlohmann::detail::lexer
  get
- nlohmann::detail::lexer
  get_codepoint
- nlohmann::detail::lexer
  get_decimal_point
- nlohmann::detail::lexer
  get_error_message
- nlohmann::detail::lexer
  get_number_float
- nlohmann::detail::lexer
  get_number_integer
- nlohmann::detail::lexer
  get_number_unsigned
- nlohmann::detail::lexer
  get_position
- nlohmann::detail::lexer
  get_string
- nlohmann::detail::lexer
  get_token_string
- nlohmann::detail::lexer
  ia
- nlohmann::detail::lexer
  ignore_comments
- nlohmann::detail::lexer
  lexer
- nlohmann::detail::lexer
  lexer
- nlohmann::detail::lexer
  lexer
- nlohmann::detail::lexer
  next_byte_in_range
- nlohmann::detail::lexer
  next_unget
- nlohmann::detail::lexer
  number_float_t
- nlohmann::detail::lexer
  number_integer_t
- nlohmann::detail::lexer
  number_unsigned_t
- nlohmann::detail::lexer
  operator=
- nlohmann::detail::lexer
  operator=
- nlohmann::detail::lexer
  position
- nlohmann::detail::lexer
  reset
- nlohmann::detail::lexer
  scan
- nlohmann::detail::lexer
  scan_comment
- nlohmann::detail::lexer
  scan_literal
- nlohmann::detail::lexer
  scan_number
- nlohmann::detail::lexer
  scan_string
- nlohmann::detail::lexer
  skip_bom
- nlohmann::detail::lexer
  skip_whitespace
- nlohmann::detail::lexer
  string_t
- nlohmann::detail::lexer
  strtof
- nlohmann::detail::lexer
  strtof
- nlohmann::detail::lexer
  strtof
- nlohmann::detail::lexer
  token_buffer
- nlohmann::detail::lexer
  token_string
- nlohmann::detail::lexer
  token_type
- nlohmann::detail::lexer
  token_type_name
- nlohmann::detail::lexer
  unget
- nlohmann::detail::lexer
  value_float
- nlohmann::detail::lexer
  value_integer
- nlohmann::detail::lexer
  value_unsigned
- nlohmann::detail::lexer
  ~lexer