Crossfire Server, Trunk
|
lexical analysis More...
#include <json.hpp>
Public Types | |
using | token_type = typename lexer_base< BasicJsonType >::token_type |
Public Types inherited from nlohmann::detail::lexer_base< BasicJsonType > | |
enum | token_type { token_type::uninitialized, token_type::literal_true, token_type::literal_false, token_type::literal_null, token_type::value_string, token_type::value_unsigned, token_type::value_integer, token_type::value_float, token_type::begin_array, token_type::begin_object, token_type::end_array, token_type::end_object, token_type::name_separator, token_type::value_separator, token_type::parse_error, token_type::end_of_input, token_type::literal_or_value } |
token types for the parser More... | |
Public Member Functions | |
constexpr const JSON_HEDLEY_RETURNS_NON_NULL char * | get_error_message () const noexcept |
return syntax error message More... | |
constexpr number_float_t | get_number_float () const noexcept |
return floating-point value More... | |
constexpr number_integer_t | get_number_integer () const noexcept |
return integer value More... | |
constexpr number_unsigned_t | get_number_unsigned () const noexcept |
return unsigned integer value More... | |
constexpr position_t | get_position () const noexcept |
return position of last read token More... | |
string_t & | get_string () |
return current string value (implicitly resets the token; useful only once) More... | |
std::string | get_token_string () const |
lexer (const lexer &)=delete | |
lexer (InputAdapterType &&adapter, bool ignore_comments_=false) noexcept | |
lexer (lexer &&)=default | |
lexer & | operator= (lexer &&)=default |
lexer & | operator= (lexer &)=delete |
token_type | scan () |
bool | skip_bom () |
skip the UTF-8 byte order mark More... | |
void | skip_whitespace () |
~lexer ()=default | |
Private Types | |
using | char_int_type = typename std::char_traits< char_type >::int_type |
using | char_type = typename InputAdapterType::char_type |
using | number_float_t = typename BasicJsonType::number_float_t |
using | number_integer_t = typename BasicJsonType::number_integer_t |
using | number_unsigned_t = typename BasicJsonType::number_unsigned_t |
using | string_t = typename BasicJsonType::string_t |
Private Member Functions | |
void | add (char_int_type c) |
add a character to token_buffer More... | |
char_int_type | get () |
int | get_codepoint () |
get codepoint from 4 hex characters following \u More... | |
bool | next_byte_in_range (std::initializer_list< char_int_type > ranges) |
check if the next byte(s) are inside a given range More... | |
void | reset () noexcept |
reset token_buffer; current character is beginning of token More... | |
bool | scan_comment () |
scan a comment More... | |
token_type | scan_literal (const char_type *literal_text, const std::size_t length, token_type return_type) |
token_type | scan_number () |
scan a number literal More... | |
token_type | scan_string () |
scan a string literal More... | |
void | unget () |
unget current character (read it again on next get) More... | |
Static Private Member Functions | |
static JSON_HEDLEY_PURE char | get_decimal_point () noexcept |
return the locale-dependent decimal point More... | |
static void | strtof (double &f, const char *str, char **endptr) noexcept |
static void | strtof (float &f, const char *str, char **endptr) noexcept |
static void | strtof (long double &f, const char *str, char **endptr) noexcept |
Private Attributes | |
char_int_type | current = std::char_traits<char_type>::eof() |
the current character More... | |
const char_int_type | decimal_point_char = '.' |
the decimal point More... | |
const char * | error_message = "" |
a description of occurred lexer errors More... | |
InputAdapterType | ia |
input adapter More... | |
const bool | ignore_comments = false |
whether comments should be ignored (true) or signaled as errors (false) More... | |
bool | next_unget = false |
whether the next get() call should just return current More... | |
position_t | position {} |
the start position of the current token More... | |
string_t | token_buffer {} |
buffer for variable-length tokens (numbers, strings) More... | |
std::vector< char_type > | token_string {} |
raw input token string (for error messages) More... | |
number_float_t | value_float = 0 |
number_integer_t | value_integer = 0 |
number_unsigned_t | value_unsigned = 0 |
Additional Inherited Members | |
Static Public Member Functions inherited from nlohmann::detail::lexer_base< BasicJsonType > | |
JSON_HEDLEY_RETURNS_NON_NULL static const JSON_HEDLEY_CONST char * | token_type_name (const token_type t) noexcept |
return name of values of type token_type (only used for errors) More... | |
lexical analysis
This class organizes the lexical analysis during JSON deserialization.
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
using nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::token_type = typename lexer_base<BasicJsonType>::token_type |
|
inlineexplicitnoexcept |
|
delete |
|
default |
|
default |
|
inlineprivate |
add a character to token_buffer
Definition at line 7903 of file json.hpp.
References c, and nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::token_buffer.
Referenced by nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::next_byte_in_range(), nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::scan_number(), and nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::scan_string().
|
inlineprivate |
Definition at line 7839 of file json.hpp.
References nlohmann::detail::position_t::chars_read_current_line, nlohmann::detail::position_t::chars_read_total, nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::current, nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::ia, JSON_HEDLEY_LIKELY, nlohmann::detail::position_t::lines_read, nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::next_unget, nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::position, and nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::token_string.
Referenced by nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::get_codepoint(), nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::next_byte_in_range(), nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::scan_comment(), nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::scan_literal(), nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::scan_number(), nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::scan_string(), nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::skip_bom(), and nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::skip_whitespace().
|
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.
Definition at line 6671 of file json.hpp.
References nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::current, nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::get(), and JSON_ASSERT.
Referenced by nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::scan_string().
|
inlinestaticprivatenoexcept |
return the locale-dependent decimal point
Definition at line 6645 of file json.hpp.
References JSON_ASSERT.
|
inlineconstexprnoexcept |
return syntax error message
Definition at line 7975 of file json.hpp.
References nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::error_message.
Referenced by nlohmann::detail::parser< BasicJsonType, InputAdapterType >::exception_message().
|
inlineconstexprnoexcept |
return floating-point value
Definition at line 7926 of file json.hpp.
References nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::value_float.
Referenced by nlohmann::detail::parser< BasicJsonType, InputAdapterType >::sax_parse_internal().
|
inlineconstexprnoexcept |
return integer value
Definition at line 7914 of file json.hpp.
References nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::value_integer.
Referenced by nlohmann::detail::parser< BasicJsonType, InputAdapterType >::sax_parse_internal().
|
inlineconstexprnoexcept |
return unsigned integer value
Definition at line 7920 of file json.hpp.
References nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::value_unsigned.
Referenced by nlohmann::detail::parser< BasicJsonType, InputAdapterType >::sax_parse_internal().
|
inlineconstexprnoexcept |
return position of last read token
Definition at line 7942 of file json.hpp.
References nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::position.
Referenced by nlohmann::detail::parser< BasicJsonType, InputAdapterType >::parse(), nlohmann::detail::parser< BasicJsonType, InputAdapterType >::sax_parse(), and nlohmann::detail::parser< BasicJsonType, InputAdapterType >::sax_parse_internal().
|
inline |
return current string value (implicitly resets the token; useful only once)
Definition at line 7932 of file json.hpp.
References nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::token_buffer.
Referenced by nlohmann::detail::parser< BasicJsonType, InputAdapterType >::sax_parse_internal().
|
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 7950 of file json.hpp.
References c, rotate-tower::result, and nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::token_string.
Referenced by nlohmann::detail::parser< BasicJsonType, InputAdapterType >::exception_message(), nlohmann::detail::parser< BasicJsonType, InputAdapterType >::parse(), nlohmann::detail::parser< BasicJsonType, InputAdapterType >::sax_parse(), and nlohmann::detail::parser< BasicJsonType, InputAdapterType >::sax_parse_internal().
|
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.
[in] | ranges | list of integers; interpreted as list of pairs of inclusive lower and upper bound, respectively |
Definition at line 6719 of file json.hpp.
References nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::add(), nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::current, nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::error_message, nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::get(), JSON_ASSERT, and JSON_HEDLEY_LIKELY.
Referenced by nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::scan_string().
|
default |
|
delete |
|
inlineprivatenoexcept |
reset token_buffer; current character is beginning of token
Definition at line 7822 of file json.hpp.
References nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::current, nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::token_buffer, and nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::token_string.
Referenced by nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::scan_number(), and nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::scan_string().
|
inline |
Definition at line 8011 of file json.hpp.
References nlohmann::detail::position_t::chars_read_total, nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::current, nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::error_message, nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::ignore_comments, nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::position, nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::scan_comment(), nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::scan_literal(), nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::scan_number(), nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::scan_string(), nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::skip_bom(), and nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::skip_whitespace().
Referenced by nlohmann::detail::parser< BasicJsonType, InputAdapterType >::get_token().
|
inlineprivate |
scan a comment
Definition at line 7346 of file json.hpp.
References nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::error_message, nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::get(), and nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::unget().
Referenced by nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::scan().
|
inlineprivate |
[in] | literal_text | the literal text to expect |
[in] | length | the length of the passed literal text |
[in] | return_type | the token type to return on success |
Definition at line 7802 of file json.hpp.
References nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::current, nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::error_message, nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::get(), JSON_ASSERT, and JSON_HEDLEY_UNLIKELY.
Referenced by nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::scan().
|
inlineprivate |
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.
.
to work with the locale-dependent converters. Definition at line 7471 of file json.hpp.
References nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::add(), nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::current, nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::decimal_point_char, nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::error_message, nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::get(), JSON_ASSERT, nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::reset(), nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::strtof(), nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::token_buffer, nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::unget(), nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::value_float, nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::value_integer, nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::value_unsigned, and diamondslots::x.
Referenced by nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::scan().
|
inlineprivate |
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.
Definition at line 6756 of file json.hpp.
References nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::add(), nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::current, nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::error_message, nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::get(), nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::get_codepoint(), JSON_ASSERT, JSON_HEDLEY_LIKELY, JSON_HEDLEY_UNLIKELY, nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::next_byte_in_range(), and nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::reset().
Referenced by nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::scan().
|
inline |
skip the UTF-8 byte order mark
Definition at line 7988 of file json.hpp.
References nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::get(), and nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::unget().
Referenced by nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::scan().
|
inline |
Definition at line 8002 of file json.hpp.
References nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::current, and nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::get().
Referenced by nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::scan().
|
inlinestaticprivatenoexcept |
Definition at line 7420 of file json.hpp.
References make_face_from_files::str.
|
inlinestaticprivatenoexcept |
Definition at line 7414 of file json.hpp.
References make_face_from_files::str.
Referenced by nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::scan_number().
|
inlinestaticprivatenoexcept |
Definition at line 7426 of file json.hpp.
References make_face_from_files::str.
|
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 7876 of file json.hpp.
References nlohmann::detail::position_t::chars_read_current_line, nlohmann::detail::position_t::chars_read_total, nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::current, JSON_ASSERT, JSON_HEDLEY_LIKELY, nlohmann::detail::position_t::lines_read, nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::next_unget, nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::position, and nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::token_string.
Referenced by nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::scan_comment(), nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::scan_number(), and nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::skip_bom().
|
private |
the current character
Definition at line 8107 of file json.hpp.
Referenced by nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::get(), nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::get_codepoint(), nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::next_byte_in_range(), nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::reset(), nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::scan(), nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::scan_literal(), nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::scan_number(), nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::scan_string(), nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::skip_whitespace(), and nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::unget().
|
private |
the decimal point
Definition at line 8130 of file json.hpp.
Referenced by nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::scan_number().
|
private |
a description of occurred lexer errors
Definition at line 8122 of file json.hpp.
Referenced by nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::get_error_message(), nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::next_byte_in_range(), nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::scan(), nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::scan_comment(), nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::scan_literal(), nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::scan_number(), and nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::scan_string().
|
private |
input adapter
Definition at line 8101 of file json.hpp.
Referenced by nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::get().
|
private |
whether comments should be ignored (true) or signaled as errors (false)
Definition at line 8104 of file json.hpp.
Referenced by nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::scan().
|
private |
whether the next get() call should just return current
Definition at line 8110 of file json.hpp.
Referenced by nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::get(), and nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::unget().
|
private |
the start position of the current token
Definition at line 8113 of file json.hpp.
Referenced by nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::get(), nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::get_position(), nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::scan(), and nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::unget().
|
private |
buffer for variable-length tokens (numbers, strings)
Definition at line 8119 of file json.hpp.
Referenced by nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::add(), nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::get_string(), nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::reset(), and nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::scan_number().
|
private |
raw input token string (for error messages)
Definition at line 8116 of file json.hpp.
Referenced by nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::get(), nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::get_token_string(), nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::reset(), and nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::unget().
|
private |
Definition at line 8127 of file json.hpp.
Referenced by nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::get_number_float(), and nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::scan_number().
|
private |
Definition at line 8125 of file json.hpp.
Referenced by nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::get_number_integer(), and nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::scan_number().
|
private |
Definition at line 8126 of file json.hpp.
Referenced by nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::get_number_unsigned(), and nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::scan_number().