PostgreSQL Source Code: src/include/common/jsonapi.h File Reference (original) (raw)

Go to the source code of this file.

Macros
#define jsonapi_StrValType StringInfoData
#define JSONLEX_FREE_STRUCT (1 << 0)
#define JSONLEX_FREE_STRVAL (1 << 1)
#define JSONLEX_CTX_OWNS_TOKENS (1 << 2)
Typedefs
typedef enum JsonTokenType JsonTokenType
typedef enum JsonParseErrorType JsonParseErrorType
typedef struct JsonParserStack JsonParserStack
typedef struct JsonIncrementalState JsonIncrementalState
typedef struct JsonLexContext JsonLexContext
typedef JsonParseErrorType(* json_struct_action) (void *state)
typedef JsonParseErrorType(* json_ofield_action) (void *state, char *fname, bool isnull)
typedef JsonParseErrorType(* json_aelem_action) (void *state, bool isnull)
typedef JsonParseErrorType(* json_scalar_action) (void *state, char *token, JsonTokenType tokentype)
typedef struct JsonSemAction JsonSemAction
Enumerations
enum JsonTokenType { JSON_TOKEN_INVALID, JSON_TOKEN_STRING, JSON_TOKEN_NUMBER, JSON_TOKEN_OBJECT_START, JSON_TOKEN_OBJECT_END, JSON_TOKEN_ARRAY_START, JSON_TOKEN_ARRAY_END, JSON_TOKEN_COMMA, JSON_TOKEN_COLON, JSON_TOKEN_TRUE, JSON_TOKEN_FALSE, JSON_TOKEN_NULL, JSON_TOKEN_END }
enum JsonParseErrorType { JSON_SUCCESS, JSON_INCOMPLETE, JSON_INVALID_LEXER_TYPE, JSON_NESTING_TOO_DEEP, 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_INVALID_TOKEN, JSON_OUT_OF_MEMORY, JSON_UNICODE_CODE_POINT_ZERO, JSON_UNICODE_ESCAPE_FORMAT, JSON_UNICODE_HIGH_ESCAPE, JSON_UNICODE_UNTRANSLATABLE, JSON_UNICODE_HIGH_SURROGATE, JSON_UNICODE_LOW_SURROGATE, JSON_SEM_ACTION_FAILED }
Functions
JsonParseErrorType pg_parse_json (JsonLexContext *lex, const JsonSemAction *sem)
JsonParseErrorType pg_parse_json_incremental (JsonLexContext *lex, const JsonSemAction *sem, const char *json, size_t len, bool is_last)
JsonParseErrorType json_count_array_elements (JsonLexContext *lex, int *elements)
JsonLexContext * makeJsonLexContextCstringLen (JsonLexContext *lex, const char *json, size_t len, int encoding, bool need_escapes)
JsonLexContext * makeJsonLexContextIncremental (JsonLexContext *lex, int encoding, bool need_escapes)
void setJsonLexContextOwnsTokens (JsonLexContext *lex, bool owned_by_context)
void freeJsonLexContext (JsonLexContext *lex)
JsonParseErrorType json_lex (JsonLexContext *lex)
char * json_errdetail (JsonParseErrorType error, JsonLexContext *lex)
bool IsValidJsonNumber (const char *str, size_t len)

jsonapi_StrValType

JSONLEX_CTX_OWNS_TOKENS

#define JSONLEX_CTX_OWNS_TOKENS (1 << 2)

JSONLEX_FREE_STRUCT

#define JSONLEX_FREE_STRUCT (1 << 0)

JSONLEX_FREE_STRVAL

#define JSONLEX_FREE_STRVAL (1 << 1)

json_aelem_action

json_ofield_action

json_scalar_action

json_struct_action

JsonIncrementalState

JsonLexContext

JsonParseErrorType

JsonParserStack

JsonSemAction

JsonTokenType

JsonParseErrorType

Enumerator
JSON_SUCCESS
JSON_INCOMPLETE
JSON_INVALID_LEXER_TYPE
JSON_NESTING_TOO_DEEP
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_INVALID_TOKEN
JSON_OUT_OF_MEMORY
JSON_UNICODE_CODE_POINT_ZERO
JSON_UNICODE_ESCAPE_FORMAT
JSON_UNICODE_HIGH_ESCAPE
JSON_UNICODE_UNTRANSLATABLE
JSON_UNICODE_HIGH_SURROGATE
JSON_UNICODE_LOW_SURROGATE
JSON_SEM_ACTION_FAILED

Definition at line 34 of file jsonapi.h.

35{

@ JSON_EXPECTED_ARRAY_FIRST

@ JSON_UNICODE_HIGH_SURROGATE

@ JSON_EXPECTED_OBJECT_FIRST

@ JSON_UNICODE_CODE_POINT_ZERO

@ JSON_INVALID_LEXER_TYPE

@ JSON_UNICODE_ESCAPE_FORMAT

@ JSON_UNICODE_UNTRANSLATABLE

@ JSON_EXPECTED_OBJECT_NEXT

@ JSON_EXPECTED_ARRAY_NEXT

@ JSON_UNICODE_HIGH_ESCAPE

@ JSON_UNICODE_LOW_SURROGATE

JsonTokenType

Enumerator
JSON_TOKEN_INVALID
JSON_TOKEN_STRING
JSON_TOKEN_NUMBER
JSON_TOKEN_OBJECT_START
JSON_TOKEN_OBJECT_END
JSON_TOKEN_ARRAY_START
JSON_TOKEN_ARRAY_END
JSON_TOKEN_COMMA
JSON_TOKEN_COLON
JSON_TOKEN_TRUE
JSON_TOKEN_FALSE
JSON_TOKEN_NULL
JSON_TOKEN_END

Definition at line 17 of file jsonapi.h.

18{

@ JSON_TOKEN_OBJECT_START

freeJsonLexContext()

Definition at line 687 of file jsonapi.c.

689{

691

693 return;

694

697

700

702 {

706

708 {

709 int i;

710

711

714 }

715

720 }

721

724 else

725 *lex = empty;

#define jsonapi_destroyStringInfo

static JsonLexContext failed_oom

#define jsonapi_termStringInfo(s)

#define JSONLEX_FREE_STRVAL

#define JSONLEX_FREE_STRUCT

#define JSONLEX_CTX_OWNS_TOKENS

jsonapi_StrValType partial_token

struct jsonapi_StrValType * strval

struct jsonapi_StrValType * errormsg

JsonIncrementalState * inc_state

References JsonLexContext::errormsg, failed_oom, JsonLexContext::flags, JsonParserStack::fnames, JsonParserStack::fnull, FREE, i, JsonLexContext::inc_state, JsonLexContext::incremental, jsonapi_destroyStringInfo, jsonapi_termStringInfo, JSONLEX_CTX_OWNS_TOKENS, JSONLEX_FREE_STRUCT, JSONLEX_FREE_STRVAL, JsonLexContext::lex_level, JsonIncrementalState::partial_token, JsonParserStack::prediction, JsonLexContext::pstack, JsonParserStack::scalar_val, and JsonLexContext::strval.

Referenced by datum_to_jsonb_internal(), each_worker(), elements_worker(), get_json_object_as_hash(), get_worker(), handle_oauth_sasl_error(), iterate_json_values(), json_object_keys(), json_parse_manifest(), json_parse_manifest_incremental_shutdown(), json_validate(), main(), parse_oauth_json(), populate_array_json(), populate_recordset_worker(), test_gb18030_json(), and transform_json_string_values().

IsValidJsonNumber()

bool IsValidJsonNumber ( const char * str,
size_t len
)

json_count_array_elements()

Definition at line 803 of file jsonapi.c.

805{

807 int count;

809

812

813

814

815

816

817

819 copylex.need_escapes = false;

821

822 count = 0;

826 return result;

828 {

829 while (1)

830 {

831 count++;

834 return result;

836 break;

839 return result;

840 }

841 }

845 return result;

846

847 *elements = count;

static JsonTokenType lex_peek(JsonLexContext *lex)

static JsonParseErrorType lex_expect(JsonParseContext ctx, JsonLexContext *lex, JsonTokenType token)

const JsonSemAction nullSemAction

JsonParseErrorType json_lex(JsonLexContext *lex)

static JsonParseErrorType parse_array_element(JsonLexContext *lex, const JsonSemAction *sem)

References failed_oom, json_lex(), JSON_OUT_OF_MEMORY, 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(), JsonLexContext::need_escapes, nullSemAction, parse_array_element(), and JsonLexContext::token_type.

Referenced by get_array_start().

json_errdetail()

Definition at line 2404 of file jsonapi.c.

2406{

2408 {

2409

2410 return _("out of memory");

2411 }

2412

2415 else

2417

2418

2419

2420

2421

2422#define json_token_error(lex, format) \

2423 jsonapi_appendStringInfo((lex)->errormsg, _(format), \

2424 (int) ((lex)->token_terminator - (lex)->token_start), \

2425 (lex)->token_start);

2426

2428 {

2431

2432 break;

2435 return _("Recursive descent parser cannot use incremental lexer.");

2436 else

2437 return _("Incremental parser requires incremental lexer.");

2439 return (_("JSON nested too deep, maximum permitted depth is 6400."));

2441 json_token_error(lex, "Escape sequence \"\\%.*s\" is invalid.");

2442 break;

2445 _("Character with value 0x%02x must be escaped."),

2447 break;

2449 json_token_error(lex, "Expected end of input, but found \"%.*s\".");

2450 break;

2452 json_token_error(lex, "Expected array element or \"]\", but found \"%.*s\".");

2453 break;

2455 json_token_error(lex, "Expected \",\" or \"]\", but found \"%.*s\".");

2456 break;

2458 json_token_error(lex, "Expected \":\", but found \"%.*s\".");

2459 break;

2461 json_token_error(lex, "Expected JSON value, but found \"%.*s\".");

2462 break;

2464 return _("The input string ended unexpectedly.");

2466 json_token_error(lex, "Expected string or \"}\", but found \"%.*s\".");

2467 break;

2469 json_token_error(lex, "Expected \",\" or \"}\", but found \"%.*s\".");

2470 break;

2472 json_token_error(lex, "Expected string, but found \"%.*s\".");

2473 break;

2476 break;

2478

2479 break;

2481 return _("\\u0000 cannot be converted to text.");

2483 return _("\"\\u\" must be followed by four hexadecimal digits.");

2485

2486 return _("Unicode escape values cannot be used for code point values above 007F when the encoding is not UTF8.");

2488

2489

2490

2491

2492

2493

2494#ifndef FRONTEND

2495 return psprintf(_("Unicode escape value could not be translated to the server's encoding %s."),

2497#else

2499 break;

2500#endif

2502 return _("Unicode high surrogate must not follow a high surrogate.");

2504 return _("Unicode low surrogate must follow a high surrogate.");

2506

2507 break;

2508 }

2509#undef json_token_error

2510

2511

2513 {

2514

2515

2516

2517

2518

2520 "unexpected json parse error type: %d",

2522 }

2523

2524#ifdef JSONAPI_USE_PQEXPBUFFER

2526 return _("out of memory while constructing error description");

2527#endif

2528

Assert(PointerIsAligned(start, uint64))

#define json_token_error(lex, format)

#define jsonapi_makeStringInfo

#define jsonapi_resetStringInfo

#define jsonapi_appendStringInfo

const char * GetDatabaseEncodingName(void)

#define PQExpBufferBroken(str)

char * psprintf(const char *fmt,...)

const char * token_terminator

References _, Assert(), error(), JsonLexContext::errormsg, failed_oom, 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_OUT_OF_MEMORY, 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, jsonapi_appendStringInfo, jsonapi_makeStringInfo, jsonapi_resetStringInfo, PQExpBufferBroken, psprintf(), and JsonLexContext::token_terminator.

Referenced by handle_oauth_sasl_error(), json_errsave_error(), json_parse_manifest(), json_parse_manifest_incremental_chunk(), main(), parse_oauth_json(), and test_gb18030_json().

json_lex()

Definition at line 1588 of file jsonapi.c.

1590{

1591 const char *s;

1594

1597

1599 {

1601 {

1602

1603

1604

1605

1609 }

1610

1611#ifdef JSONAPI_USE_PQEXPBUFFER

1612

1615#endif

1616 }

1617

1619

1621 {

1622

1623

1624

1625

1627 size_t added = 0;

1628 bool tok_done = false;

1631

1632 if (ptok->data[0] == '"')

1633 {

1634

1635

1636

1637

1638 int escapes = 0;

1639

1640 for (int i = ptok->len - 1; i > 0; i--)

1641 {

1642

1643 if (ptok->data[i] == '\\')

1644 escapes++;

1645 else

1646 break;

1647 }

1648

1650 {

1652

1654 added++;

1655 if (c == '"' && escapes % 2 == 0)

1656 {

1657 tok_done = true;

1658 break;

1659 }

1660 if (c == '\\')

1661 escapes++;

1662 else

1663 escapes = 0;

1664 }

1665 }

1666 else

1667 {

1668

1669 char c = ptok->data[0];

1670

1671 if (c == '-' || (c >= '0' && c <= '9'))

1672 {

1673

1674

1675 bool numend = false;

1676

1677 for (size_t i = 0; i < lex->input_length && !numend; i++)

1678 {

1679 char cc = lex->input[i];

1680

1681 switch (cc)

1682 {

1683 case '+':

1684 case '-':

1685 case 'e':

1686 case 'E':

1687 case '0':

1688 case '1':

1689 case '2':

1690 case '3':

1691 case '4':

1692 case '5':

1693 case '6':

1694 case '7':

1695 case '8':

1696 case '9':

1697 {

1699 added++;

1700 }

1701 break;

1702 default:

1703 numend = true;

1704 }

1705 }

1706 }

1707

1708

1709

1710

1711

1712

1714 {

1715 char cc = lex->input[i];

1716

1718 {

1720 added++;

1721 }

1722 else

1723 {

1724 tok_done = true;

1725 break;

1726 }

1727 }

1730 {

1731 tok_done = true;

1732 }

1733 }

1734

1735 if (!tok_done)

1736 {

1737

1739

1742

1743

1747 }

1748

1749

1750

1751

1752

1753 lex->input += added;

1755

1764

1765 partial_result = json_lex(&dummy_lex);

1766

1767

1768

1769

1770

1771

1772

1775

1776

1777

1778

1779

1781

1782

1783

1784

1785

1789 {

1790

1792 {

1795 }

1796

1798 }

1799 return partial_result;

1800

1801 }

1802

1803

1804 while (s < end && (*s == ' ' || *s == '\t' || *s == '\n' || *s == '\r'))

1805 {

1806 if (*s++ == '\n')

1807 {

1810 }

1811 }

1813

1814

1815 if (s >= end)

1816 {

1821 }

1822 else

1823 {

1824 switch (*s)

1825 {

1826

1827 case '{':

1831 break;

1832 case '}':

1836 break;

1837 case '[':

1841 break;

1842 case ']':

1846 break;

1847 case ',':

1851 break;

1852 case ':':

1856 break;

1857 case '"':

1858

1861 return result;

1863 break;

1864 case '-':

1865

1868 return result;

1870 break;

1871 case '0':

1872 case '1':

1873 case '2':

1874 case '3':

1875 case '4':

1876 case '5':

1877 case '6':

1878 case '7':

1879 case '8':

1880 case '9':

1881

1884 return result;

1886 break;

1887 default:

1888 {

1889 const char *p;

1890

1891

1892

1893

1894

1895

1896

1897

1898

1899

1901 ;

1902

1903

1904

1905

1906

1907

1908 if (p == s)

1909 {

1913 }

1914

1917 {

1920 }

1921

1922

1923

1924

1925

1926

1929 if (p - s == 4)

1930 {

1931 if (memcmp(s, "true", 4) == 0)

1933 else if (memcmp(s, "null", 4) == 0)

1935 else

1937 }

1938 else if (p - s == 5 && memcmp(s, "false", 5) == 0)

1940 else

1942 }

1943 }

1944 }

1945

1948 else

static JsonParseErrorType json_lex_string(JsonLexContext *lex)

#define JSON_ALPHANUMERIC_CHAR(c)

#define jsonapi_appendStringInfoCharMacro

static JsonIncrementalState failed_inc_oom

#define jsonapi_appendBinaryStringInfo

#define jsonapi_StrValType

#define PQExpBufferDataBroken(buf)

const char * prev_token_terminator

References Assert(), failed_inc_oom, failed_oom, 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(), json_lex_number(), json_lex_string(), JSON_OUT_OF_MEMORY, 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, jsonapi_appendBinaryStringInfo, jsonapi_appendStringInfoCharMacro, jsonapi_resetStringInfo, jsonapi_StrValType, JsonLexContext::line_number, JsonLexContext::line_start, JsonLexContext::need_escapes, JsonIncrementalState::partial_completed, JsonIncrementalState::partial_token, PQExpBufferDataBroken, JsonLexContext::prev_token_terminator, JsonLexContext::strval, JsonLexContext::token_start, JsonLexContext::token_terminator, and JsonLexContext::token_type.

Referenced by json_count_array_elements(), json_get_first_token(), json_lex(), json_typeof(), lex_expect(), parse_array(), parse_object(), parse_object_field(), parse_scalar(), pg_parse_json(), and pg_parse_json_incremental().

makeJsonLexContextCstringLen()

Definition at line 392 of file jsonapi.c.

394{

395 if (lex == NULL)

396 {

398 if (!lex)

401 }

402 else

404

411 if (need_escapes)

412 {

413

414

415

416

417

420 }

421

422 return lex;

423}

References ALLOC0, encoding, JsonLexContext::errormsg, failed_oom, JsonLexContext::flags, JsonLexContext::input, JsonLexContext::input_encoding, JsonLexContext::input_length, jsonapi_makeStringInfo, JSONLEX_FREE_STRUCT, JSONLEX_FREE_STRVAL, len, JsonLexContext::line_number, JsonLexContext::line_start, JsonLexContext::need_escapes, JsonLexContext::strval, and JsonLexContext::token_terminator.

Referenced by get_json_object_as_hash(), handle_oauth_sasl_error(), json_parse_manifest(), json_recv(), jsonb_from_cstring(), main(), makeJsonLexContext(), parse_oauth_json(), populate_array_json(), and test_gb18030_json().

makeJsonLexContextIncremental()

Definition at line 497 of file jsonapi.c.

500{

501 if (lex == NULL)

502 {

504 if (!lex)

506

508 }

509 else

511

514

516 {

518 {

521 }

522

523

524 return lex;

525 }

526

528 if (need_escapes)

529 {

530

531

532

533

534

537 }

538

539 return lex;

static bool allocate_incremental_state(JsonLexContext *lex)

References ALLOC0, allocate_incremental_state(), encoding, failed_oom, JsonLexContext::flags, FREE, JsonLexContext::input_encoding, jsonapi_makeStringInfo, JSONLEX_FREE_STRUCT, JSONLEX_FREE_STRVAL, JsonLexContext::line_number, JsonLexContext::need_escapes, and JsonLexContext::strval.

Referenced by json_parse_manifest_incremental_init(), and main().

pg_parse_json()

Definition at line 744 of file jsonapi.c.

746{

747#ifdef FORCE_JSON_PSTACK

748

749

750

751

752

755

757

758#else

759

762

767

768

771 return result;

772

774

775

776 switch (tok)

777 {

780 break;

783 break;

784 default:

785 result = parse_scalar(lex, sem);

786 }

787

790

791 return result;

792#endif

JsonParseErrorType pg_parse_json_incremental(JsonLexContext *lex, const JsonSemAction *sem, const char *json, size_t len, bool is_last)

static JsonParseErrorType parse_object(JsonLexContext *lex, const JsonSemAction *sem)

static JsonParseErrorType parse_scalar(JsonLexContext *lex, const JsonSemAction *sem)

static JsonParseErrorType parse_array(JsonLexContext *lex, const JsonSemAction *sem)

References allocate_incremental_state(), failed_oom, JsonLexContext::incremental, JsonLexContext::input, JsonLexContext::input_length, JSON_INVALID_LEXER_TYPE, json_lex(), JSON_OUT_OF_MEMORY, JSON_PARSE_END, JSON_SUCCESS, JSON_TOKEN_ARRAY_START, JSON_TOKEN_END, JSON_TOKEN_OBJECT_START, lex_expect(), lex_peek(), parse_array(), parse_object(), parse_scalar(), pg_parse_json_incremental(), and sem.

Referenced by handle_oauth_sasl_error(), json_parse_manifest(), json_validate(), main(), parse_oauth_json(), pg_parse_json_or_errsave(), and test_gb18030_json().

pg_parse_json_incremental()

Definition at line 868 of file jsonapi.c.

874{

879

884

889

890

893 return result;

894

896

897

898

900 {

902

904 }

905

907 {

910

911

912

913

914 if (top == tok)

915 {

916

917

918

919

921 {

924 return result;

926 }

927 }

929 {

930

931

932

933

934

936 }

937 else if (IS_SEM(top))

938 {

939

940

941

942

943

944

945

946 switch (top)

947 {

949 {

951

954

955 if (ostart != NULL)

956 {

959 return result;

960 }

961

964 }

965 break;

967 {

969

971 if (oend != NULL)

972 {

975 return result;

976 }

977 }

978 break;

980 {

982

985

986 if (astart != NULL)

987 {

990 return result;

991 }

992

995 }

996 break;

998 {

1000

1002 if (aend != NULL)

1003 {

1006 return result;

1007 }

1008 }

1009 break;

1011 {

1012

1013

1014

1015

1016

1017 char *fname = NULL;

1020

1021 if ((ostart != NULL || oend != NULL) && lex->need_escapes)

1022 {

1024 if (fname == NULL)

1026 }

1028 }

1029 break;

1031 {

1032

1033

1034

1035

1038

1040

1041 if (ostart != NULL)

1042 {

1044

1045 result = (*ostart) (sem->semstate, fname, isnull);

1047 return result;

1048 }

1049 }

1050 break;

1052 {

1054

1055 if (oend != NULL)

1056 {

1059

1060 result = (*oend) (sem->semstate, fname, isnull);

1062 return result;

1063 }

1064 }

1065 break;

1067 {

1070

1072

1073 if (astart != NULL)

1074 {

1075 result = (*astart) (sem->semstate, isnull);

1077 return result;

1078 }

1079 }

1080 break;

1082 {

1084

1085 if (aend != NULL)

1086 {

1088

1089 result = (*aend) (sem->semstate, isnull);

1091 return result;

1092 }

1093 }

1094 break;

1096 {

1098

1100

1101 if (sfunc != NULL)

1102 {

1103

1104

1105

1106

1107

1108

1109

1110

1112 {

1114 {

1118 }

1119 }

1120 else

1121 {

1123

1127

1130 }

1132 }

1133 }

1134 break;

1136 {

1137

1138

1139

1140

1141

1142

1143

1145

1146 if (sfunc != NULL)

1147 {

1149

1150

1151

1152

1153

1154

1155

1159

1161 return result;

1162 }

1163 }

1164 break;

1165 default:

1166

1167 break;

1168 }

1169 }

1170 else

1171 {

1172

1173

1174

1175

1176

1177

1178

1179

1180 switch (top)

1181 {

1185 else

1186 {

1189 }

1190 break;

1199 break;

1203 break;

1207 break;

1212 else

1214 break;

1217 break;

1220 break;

1223 break;

1226 break;

1229 break;

1232 break;

1233 default:

1235 }

1237 }

1238 }

1239

#define JSON_TD_MAX_STACK

@ JSON_PARSE_OBJECT_LABEL

@ JSON_PARSE_OBJECT_START

static void set_fnull(JsonLexContext *lex, bool fnull)

static bool inc_lex_level(JsonLexContext *lex)

static bool have_prediction(JsonParserStack *pstack)

static void set_fname(JsonLexContext *lex, char *fname)

static char next_prediction(JsonParserStack *pstack)

static void push_prediction(JsonParserStack *pstack, td_entry entry)

static char * get_fname(JsonLexContext *lex)

static char JSON_PROD_GOAL[]

static JsonParseErrorType report_parse_error(JsonParseContext ctx, JsonLexContext *lex)

static td_entry td_parser_table[JSON_NUM_NONTERMINALS][JSON_NUM_TERMINALS]

static char pop_prediction(JsonParserStack *pstack)

static bool get_fnull(JsonLexContext *lex)

@ JSON_NT_MORE_ARRAY_ELEMENTS

static void dec_lex_level(JsonLexContext *lex)

JsonParseErrorType(* json_struct_action)(void *state)

JsonParseErrorType(* json_aelem_action)(void *state, bool isnull)

JsonParseErrorType(* json_ofield_action)(void *state, char *fname, bool isnull)

JsonParseErrorType(* json_scalar_action)(void *state, char *token, JsonTokenType tokentype)

json_struct_action array_end

json_struct_action object_start

json_ofield_action object_field_start

json_aelem_action array_element_start

json_scalar_action scalar

json_aelem_action array_element_end

json_struct_action array_start

json_struct_action object_end

json_ofield_action object_field_end

References ALLOC, JsonSemAction::array_element_end, JsonSemAction::array_element_start, JsonSemAction::array_end, JsonSemAction::array_start, Assert(), dec_lex_level(), failed_inc_oom, failed_oom, JsonLexContext::flags, FREE, 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_OUT_OF_MEMORY, 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, JSONLEX_CTX_OWNS_TOKENS, len, JsonLexContext::lex_level, lex_peek(), JsonLexContext::line_start, JsonLexContext::need_escapes, next_prediction(), JsonSemAction::object_end, JsonSemAction::object_field_end, JsonSemAction::object_field_start, JsonSemAction::object_start, OFS, pop_prediction(), JsonLexContext::pstack, push_prediction(), report_parse_error(), JsonSemAction::scalar, JsonParserStack::scalar_tok, JsonParserStack::scalar_val, sem, JsonSemAction::semstate, set_fname(), set_fnull(), JsonIncrementalState::started, STRDUP, 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().

setJsonLexContextOwnsTokens()

void setJsonLexContextOwnsTokens ( JsonLexContext * lex,
bool owned_by_context
)

nullSemAction