PostgreSQL Source Code
git master
|
#include "postgres.h"
#include "common/jsonapi.h"
#include "mb/pg_wchar.h"
#include "port/pg_lfind.h"
#include "miscadmin.h"
Go to the source code of this file.
Data Structures | |
struct | JsonParserStack |
struct | JsonIncrementalState |
struct | td_entry |
Macros | |
#define | JSON_NUM_TERMINALS 13 |
#define | JSON_NUM_NONTERMINALS 5 |
#define | JSON_NT_OFFSET JSON_NT_JSON |
#define | OFS(NT) (NT) - JSON_NT_OFFSET |
#define | IS_SEM(x) ((x) & 0x40) |
#define | IS_NT(x) ((x) & 0x20) |
#define | TD_ENTRY(PROD) { sizeof(PROD) - 1, (PROD) } |
#define | JSON_ALPHANUMERIC_CHAR(c) |
#define | JS_STACK_CHUNK_SIZE 64 |
#define | JS_MAX_PROD_LEN 10 /* more than we need */ |
#define | JSON_TD_MAX_STACK |
#define | FAIL_OR_INCOMPLETE_AT_CHAR_START(code) |
#define | FAIL_AT_CHAR_END(code) |
#define | json_token_error(lex, format) |
#define FAIL_AT_CHAR_END | ( | code | ) |
#define FAIL_OR_INCOMPLETE_AT_CHAR_START | ( | code | ) |
#define JSON_ALPHANUMERIC_CHAR | ( | c | ) |
#define JSON_NT_OFFSET JSON_NT_JSON |
#define JSON_TD_MAX_STACK |
#define json_token_error | ( | lex, | |
format | |||
) |
#define OFS | ( | NT | ) | (NT) - JSON_NT_OFFSET |
enum JsonNonTerminal |
enum JsonParseContext |
enum JsonParserSem |
|
inlinestatic |
Definition at line 418 of file jsonapi.c.
References JsonLexContext::lex_level.
Referenced by pg_parse_json_incremental().
void freeJsonLexContext | ( | JsonLexContext * | lex | ) |
Definition at line 482 of file jsonapi.c.
References StringInfoData::data, destroyStringInfo(), JsonLexContext::errormsg, JsonLexContext::flags, JsonParserStack::fnames, JsonParserStack::fnull, JsonLexContext::inc_state, JsonLexContext::incremental, JSONLEX_FREE_STRUCT, JSONLEX_FREE_STRVAL, JsonIncrementalState::partial_token, pfree(), JsonParserStack::prediction, JsonLexContext::pstack, and JsonLexContext::strval.
Referenced by datum_to_jsonb_internal(), each_worker(), elements_worker(), get_json_object_as_hash(), get_worker(), iterate_json_values(), json_object_keys(), json_parse_manifest(), json_parse_manifest_incremental_shutdown(), json_validate(), main(), populate_array_json(), populate_recordset_worker(), and transform_json_string_values().
|
inlinestatic |
Definition at line 457 of file jsonapi.c.
References JsonParserStack::fnames, JsonLexContext::lex_level, and JsonLexContext::pstack.
Referenced by pg_parse_json_incremental().
|
inlinestatic |
Definition at line 469 of file jsonapi.c.
References JsonParserStack::fnull, JsonLexContext::lex_level, and JsonLexContext::pstack.
Referenced by pg_parse_json_incremental().
|
inlinestatic |
Definition at line 445 of file jsonapi.c.
References JsonParserStack::pred_index.
Referenced by pg_parse_json_incremental().
|
inlinestatic |
Definition at line 397 of file jsonapi.c.
References JsonParserStack::fnames, JsonParserStack::fnull, JsonLexContext::incremental, JS_MAX_PROD_LEN, JS_STACK_CHUNK_SIZE, JsonLexContext::lex_level, JsonParserStack::prediction, JsonLexContext::pstack, repalloc(), and JsonParserStack::stack_size.
Referenced by pg_parse_json_incremental().
bool IsValidJsonNumber | ( | const char * | str, |
size_t | len | ||
) |
Definition at line 272 of file jsonapi.c.
References JsonLexContext::inc_state, JsonLexContext::incremental, JsonLexContext::input, JsonLexContext::input_length, json_lex_number(), len, JsonLexContext::pstack, str, and JsonLexContext::token_start.
Referenced by hstore_to_json_loose(), and hstore_to_jsonb_loose().
JsonParseErrorType json_count_array_elements | ( | JsonLexContext * | lex, |
int * | elements | ||
) |
Definition at line 587 of file jsonapi.c.
References json_lex(), JSON_PARSE_ARRAY_NEXT, JSON_PARSE_ARRAY_START, JSON_SUCCESS, JSON_TOKEN_ARRAY_END, JSON_TOKEN_ARRAY_START, JSON_TOKEN_COMMA, lex_expect(), JsonLexContext::lex_level, lex_peek(), nullSemAction, parse_array_element(), JsonLexContext::strval, and JsonLexContext::token_type.
Referenced by get_array_start().
char* json_errdetail | ( | JsonParseErrorType | error, |
JsonLexContext * | lex | ||
) |
Definition at line 2096 of file jsonapi.c.
References _, appendStringInfo(), Assert, StringInfoData::data, error(), JsonLexContext::errormsg, GetDatabaseEncodingName(), JsonLexContext::incremental, JSON_ESCAPING_INVALID, JSON_ESCAPING_REQUIRED, JSON_EXPECTED_ARRAY_FIRST, JSON_EXPECTED_ARRAY_NEXT, JSON_EXPECTED_COLON, JSON_EXPECTED_END, JSON_EXPECTED_JSON, JSON_EXPECTED_MORE, JSON_EXPECTED_OBJECT_FIRST, JSON_EXPECTED_OBJECT_NEXT, JSON_EXPECTED_STRING, JSON_INCOMPLETE, JSON_INVALID_LEXER_TYPE, JSON_INVALID_TOKEN, JSON_NESTING_TOO_DEEP, JSON_SEM_ACTION_FAILED, JSON_SUCCESS, json_token_error, JSON_UNICODE_CODE_POINT_ZERO, JSON_UNICODE_ESCAPE_FORMAT, JSON_UNICODE_HIGH_ESCAPE, JSON_UNICODE_HIGH_SURROGATE, JSON_UNICODE_LOW_SURROGATE, JSON_UNICODE_UNTRANSLATABLE, StringInfoData::len, makeStringInfo(), psprintf(), resetStringInfo(), and JsonLexContext::token_terminator.
Referenced by json_errsave_error(), json_parse_manifest(), json_parse_manifest_incremental_chunk(), and main().
JsonParseErrorType json_lex | ( | JsonLexContext * | lex | ) |
Definition at line 1308 of file jsonapi.c.
References appendBinaryStringInfo(), appendStringInfoCharMacro, Assert, StringInfoData::data, i, JsonLexContext::inc_state, JsonLexContext::incremental, JsonLexContext::input, JsonLexContext::input_encoding, JsonLexContext::input_length, JsonIncrementalState::is_last_chunk, JSON_ALPHANUMERIC_CHAR, JSON_INCOMPLETE, JSON_INVALID_TOKEN, json_lex_number(), json_lex_string(), JSON_SUCCESS, JSON_TOKEN_ARRAY_END, JSON_TOKEN_ARRAY_START, JSON_TOKEN_COLON, JSON_TOKEN_COMMA, JSON_TOKEN_END, JSON_TOKEN_FALSE, JSON_TOKEN_NULL, JSON_TOKEN_NUMBER, JSON_TOKEN_OBJECT_END, JSON_TOKEN_OBJECT_START, JSON_TOKEN_STRING, JSON_TOKEN_TRUE, StringInfoData::len, JsonLexContext::line_number, JsonLexContext::line_start, JsonIncrementalState::partial_completed, JsonIncrementalState::partial_token, JsonLexContext::prev_token_terminator, resetStringInfo(), JsonLexContext::strval, JsonLexContext::token_start, JsonLexContext::token_terminator, and JsonLexContext::token_type.
Referenced by json_count_array_elements(), json_get_first_token(), json_typeof(), lex_expect(), parse_array(), parse_object(), parse_object_field(), parse_scalar(), pg_parse_json(), and pg_parse_json_incremental().
|
inlinestatic |
Definition at line 1942 of file jsonapi.c.
References appendBinaryStringInfo(), error(), JsonLexContext::inc_state, JsonLexContext::incremental, JsonLexContext::input, JsonLexContext::input_length, JsonIncrementalState::is_last_chunk, JSON_ALPHANUMERIC_CHAR, JSON_INCOMPLETE, JSON_INVALID_TOKEN, JSON_SUCCESS, len, JsonIncrementalState::partial_token, JsonLexContext::prev_token_terminator, JsonLexContext::token_start, and JsonLexContext::token_terminator.
Referenced by IsValidJsonNumber(), and json_lex().
|
inlinestatic |
Definition at line 1671 of file jsonapi.c.
References appendBinaryStringInfo(), appendStringInfoChar(), appendStringInfoString(), Assert, FAIL_AT_CHAR_END, FAIL_OR_INCOMPLETE_AT_CHAR_START, i, JsonLexContext::input, JsonLexContext::input_encoding, JsonLexContext::input_length, is_utf16_surrogate_first(), is_utf16_surrogate_second(), JSON_ESCAPING_INVALID, JSON_ESCAPING_REQUIRED, JSON_INVALID_TOKEN, JSON_SUCCESS, JSON_UNICODE_CODE_POINT_ZERO, JSON_UNICODE_ESCAPE_FORMAT, JSON_UNICODE_HIGH_ESCAPE, JSON_UNICODE_HIGH_SURROGATE, JSON_UNICODE_LOW_SURROGATE, JSON_UNICODE_UNTRANSLATABLE, MAX_UNICODE_EQUIVALENT_STRING, pg_lfind8(), pg_lfind8_le(), pg_unicode_to_server_noerror(), PG_UTF8, pg_utf_mblen, JsonLexContext::prev_token_terminator, resetStringInfo(), JsonLexContext::strval, surrogate_pair_to_codepoint(), JsonLexContext::token_start, JsonLexContext::token_terminator, and unicode_to_utf8().
Referenced by json_lex().
|
inlinestatic |
Definition at line 250 of file jsonapi.c.
References json_lex(), lex_peek(), report_parse_error(), and token.
Referenced by json_count_array_elements(), parse_array(), parse_object(), parse_object_field(), and pg_parse_json().
|
inlinestatic |
Definition at line 238 of file jsonapi.c.
References JsonLexContext::token_type.
Referenced by json_count_array_elements(), lex_expect(), parse_array(), parse_array_element(), parse_object(), parse_object_field(), parse_scalar(), pg_parse_json(), and pg_parse_json_incremental().
JsonLexContext* makeJsonLexContextCstringLen | ( | JsonLexContext * | lex, |
const char * | json, | ||
size_t | len, | ||
int | encoding, | ||
bool | need_escapes | ||
) |
Definition at line 326 of file jsonapi.c.
References encoding, JsonLexContext::errormsg, JsonLexContext::flags, JsonLexContext::input, JsonLexContext::input_encoding, JsonLexContext::input_length, JSONLEX_FREE_STRUCT, JSONLEX_FREE_STRVAL, len, JsonLexContext::line_number, JsonLexContext::line_start, makeStringInfo(), palloc0(), JsonLexContext::strval, and JsonLexContext::token_terminator.
Referenced by get_json_object_as_hash(), json_parse_manifest(), json_recv(), jsonb_from_cstring(), main(), makeJsonLexContext(), and populate_array_json().
JsonLexContext* makeJsonLexContextIncremental | ( | JsonLexContext * | lex, |
int | encoding, | ||
bool | need_escapes | ||
) |
Definition at line 366 of file jsonapi.c.
References encoding, JsonLexContext::flags, JsonParserStack::fnames, JsonParserStack::fnull, JsonLexContext::inc_state, JsonLexContext::incremental, initStringInfo(), JsonLexContext::input_encoding, JS_MAX_PROD_LEN, JS_STACK_CHUNK_SIZE, JSONLEX_FREE_STRUCT, JSONLEX_FREE_STRVAL, JsonLexContext::line_number, makeStringInfo(), palloc(), palloc0(), JsonIncrementalState::partial_token, JsonParserStack::pred_index, JsonParserStack::prediction, JsonLexContext::pstack, JsonParserStack::stack_size, and JsonLexContext::strval.
Referenced by json_parse_manifest_incremental_init(), and main().
|
inlinestatic |
Definition at line 438 of file jsonapi.c.
References Assert, JsonParserStack::pred_index, and JsonParserStack::prediction.
Referenced by pg_parse_json_incremental().
|
static |
Definition at line 1231 of file jsonapi.c.
References JsonSemAction::array_end, JsonSemAction::array_start, check_stack_depth(), json_lex(), JSON_PARSE_ARRAY_NEXT, JSON_PARSE_ARRAY_START, JSON_SUCCESS, JSON_TOKEN_ARRAY_END, JSON_TOKEN_ARRAY_START, JSON_TOKEN_COMMA, lex_expect(), JsonLexContext::lex_level, lex_peek(), parse_array_element(), sem, and JsonSemAction::semstate.
Referenced by parse_array_element(), parse_object_field(), and pg_parse_json().
|
static |
Definition at line 1187 of file jsonapi.c.
References JsonSemAction::array_element_end, JsonSemAction::array_element_start, JSON_SUCCESS, JSON_TOKEN_ARRAY_START, JSON_TOKEN_NULL, JSON_TOKEN_OBJECT_START, lex_peek(), parse_array(), parse_object(), parse_scalar(), sem, and JsonSemAction::semstate.
Referenced by json_count_array_elements(), and parse_array().
|
static |
Definition at line 1113 of file jsonapi.c.
References Assert, check_stack_depth(), json_lex(), JSON_PARSE_OBJECT_NEXT, JSON_PARSE_OBJECT_START, JSON_SUCCESS, JSON_TOKEN_COMMA, JSON_TOKEN_OBJECT_END, JSON_TOKEN_OBJECT_START, JSON_TOKEN_STRING, lex_expect(), JsonLexContext::lex_level, lex_peek(), JsonSemAction::object_end, JsonSemAction::object_start, parse_object_field(), report_parse_error(), sem, and JsonSemAction::semstate.
Referenced by parse_array_element(), parse_object_field(), and pg_parse_json().
|
static |
Definition at line 1051 of file jsonapi.c.
References StringInfoData::data, json_lex(), JSON_PARSE_OBJECT_LABEL, JSON_PARSE_STRING, JSON_SUCCESS, JSON_TOKEN_ARRAY_START, JSON_TOKEN_COLON, JSON_TOKEN_NULL, JSON_TOKEN_OBJECT_START, JSON_TOKEN_STRING, lex_expect(), lex_peek(), JsonSemAction::object_field_end, JsonSemAction::object_field_start, parse_array(), parse_object(), parse_scalar(), pstrdup(), report_parse_error(), sem, JsonSemAction::semstate, and JsonLexContext::strval.
Referenced by parse_object().
|
inlinestatic |
Definition at line 1007 of file jsonapi.c.
References StringInfoData::data, json_lex(), JSON_PARSE_VALUE, JSON_SUCCESS, JSON_TOKEN_FALSE, JSON_TOKEN_NULL, JSON_TOKEN_NUMBER, JSON_TOKEN_STRING, JSON_TOKEN_TRUE, len, lex_peek(), palloc(), pstrdup(), report_parse_error(), JsonSemAction::scalar, sem, JsonSemAction::semstate, JsonLexContext::strval, JsonLexContext::token_start, JsonLexContext::token_terminator, and val.
Referenced by parse_array_element(), parse_object_field(), and pg_parse_json().
JsonParseErrorType pg_parse_json | ( | JsonLexContext * | lex, |
const JsonSemAction * | sem | ||
) |
Definition at line 521 of file jsonapi.c.
References JsonParserStack::fnames, JsonParserStack::fnull, JsonLexContext::inc_state, JsonLexContext::incremental, initStringInfo(), JsonLexContext::input, JsonLexContext::input_length, JS_MAX_PROD_LEN, JS_STACK_CHUNK_SIZE, JSON_INVALID_LEXER_TYPE, json_lex(), JSON_PARSE_END, JSON_SUCCESS, JSON_TOKEN_ARRAY_START, JSON_TOKEN_END, JSON_TOKEN_OBJECT_START, lex_expect(), lex_peek(), palloc(), palloc0(), parse_array(), parse_object(), parse_scalar(), JsonIncrementalState::partial_token, pg_parse_json_incremental(), JsonParserStack::pred_index, JsonParserStack::prediction, JsonLexContext::pstack, sem, and JsonParserStack::stack_size.
Referenced by json_parse_manifest(), json_validate(), main(), and pg_parse_json_or_errsave().
JsonParseErrorType pg_parse_json_incremental | ( | JsonLexContext * | lex, |
const JsonSemAction * | sem, | ||
const char * | json, | ||
size_t | len, | ||
bool | is_last | ||
) |
Definition at line 649 of file jsonapi.c.
References JsonSemAction::array_element_end, JsonSemAction::array_element_start, JsonSemAction::array_end, JsonSemAction::array_start, Assert, StringInfoData::data, dec_lex_level(), get_fname(), get_fnull(), have_prediction(), inc_lex_level(), JsonLexContext::inc_state, JsonLexContext::incremental, JsonLexContext::input, JsonLexContext::input_length, JsonIncrementalState::is_last_chunk, IS_NT, IS_SEM, JSON_INVALID_LEXER_TYPE, json_lex(), JSON_NESTING_TOO_DEEP, JSON_NT_ARRAY_ELEMENTS, JSON_NT_KEY_PAIRS, JSON_NT_MORE_ARRAY_ELEMENTS, JSON_NT_MORE_KEY_PAIRS, JSON_PARSE_ARRAY_NEXT, JSON_PARSE_ARRAY_START, JSON_PARSE_END, JSON_PARSE_OBJECT_LABEL, JSON_PARSE_OBJECT_NEXT, JSON_PARSE_OBJECT_START, JSON_PARSE_STRING, JSON_PARSE_VALUE, JSON_PROD_GOAL, JSON_SEM_AELEM_END, JSON_SEM_AELEM_START, JSON_SEM_AEND, JSON_SEM_ASTART, JSON_SEM_OEND, JSON_SEM_OFIELD_END, JSON_SEM_OFIELD_INIT, JSON_SEM_OFIELD_START, JSON_SEM_OSTART, JSON_SEM_SCALAR_CALL, JSON_SEM_SCALAR_INIT, JSON_SUCCESS, JSON_TD_MAX_STACK, JSON_TOKEN_ARRAY_END, JSON_TOKEN_ARRAY_START, JSON_TOKEN_COLON, JSON_TOKEN_COMMA, JSON_TOKEN_END, JSON_TOKEN_FALSE, JSON_TOKEN_NULL, JSON_TOKEN_NUMBER, JSON_TOKEN_OBJECT_END, JSON_TOKEN_OBJECT_START, JSON_TOKEN_STRING, JSON_TOKEN_TRUE, len, JsonLexContext::lex_level, lex_peek(), JsonLexContext::line_start, next_prediction(), JsonSemAction::object_end, JsonSemAction::object_field_end, JsonSemAction::object_field_start, JsonSemAction::object_start, OFS, palloc(), pop_prediction(), JsonLexContext::pstack, pstrdup(), push_prediction(), report_parse_error(), JsonSemAction::scalar, JsonParserStack::scalar_tok, JsonParserStack::scalar_val, sem, JsonSemAction::semstate, set_fname(), set_fnull(), JsonLexContext::strval, TD_ENTRY, td_parser_table, JsonLexContext::token_start, and JsonLexContext::token_terminator.
Referenced by json_parse_manifest_incremental_chunk(), main(), and pg_parse_json().
|
inlinestatic |
Definition at line 431 of file jsonapi.c.
References Assert, JsonParserStack::pred_index, and JsonParserStack::prediction.
Referenced by pg_parse_json_incremental().
|
inlinestatic |
Definition at line 424 of file jsonapi.c.
References td_entry::len, JsonParserStack::pred_index, JsonParserStack::prediction, and td_entry::prod.
Referenced by pg_parse_json_incremental().
|
static |
Definition at line 2052 of file jsonapi.c.
References Assert, JSON_EXPECTED_ARRAY_FIRST, JSON_EXPECTED_ARRAY_NEXT, JSON_EXPECTED_COLON, JSON_EXPECTED_END, JSON_EXPECTED_JSON, JSON_EXPECTED_MORE, JSON_EXPECTED_OBJECT_FIRST, JSON_EXPECTED_OBJECT_NEXT, JSON_EXPECTED_STRING, JSON_PARSE_ARRAY_NEXT, JSON_PARSE_ARRAY_START, JSON_PARSE_END, JSON_PARSE_OBJECT_COMMA, JSON_PARSE_OBJECT_LABEL, JSON_PARSE_OBJECT_NEXT, JSON_PARSE_OBJECT_START, JSON_PARSE_STRING, JSON_PARSE_VALUE, JSON_SUCCESS, JSON_TOKEN_END, JsonLexContext::token_start, and JsonLexContext::token_type.
Referenced by lex_expect(), parse_object(), parse_object_field(), parse_scalar(), and pg_parse_json_incremental().
|
inlinestatic |
Definition at line 451 of file jsonapi.c.
References JsonParserStack::fnames, JsonLexContext::lex_level, and JsonLexContext::pstack.
Referenced by pg_parse_json_incremental().
|
inlinestatic |
Definition at line 463 of file jsonapi.c.
References JsonParserStack::fnull, JsonLexContext::lex_level, and JsonLexContext::pstack.
Referenced by pg_parse_json_incremental().
|
static |
|
static |
|
static |
Definition at line 211 of file jsonapi.c.
Referenced by pg_parse_json_incremental().
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
const JsonSemAction nullSemAction |
Definition at line 224 of file jsonapi.c.
Referenced by json_count_array_elements(), json_in(), json_recv(), json_validate(), and main().
|
static |
Definition at line 180 of file jsonapi.c.
Referenced by pg_parse_json_incremental().