MCPcopy Create free account
hub / github.com/apache/cloudberry / json_lex

Function json_lex

src/common/jsonapi.c:525–674  ·  view source on GitHub ↗

* Lex one token from the input stream. */

Source from the content-addressed store, hash-verified

523 * Lex one token from the input stream.
524 */
525JsonParseErrorType
526json_lex(JsonLexContext *lex)
527{
528 char *s;
529 int len;
530 JsonParseErrorType result;
531
532 /* Skip leading whitespace. */
533 s = lex->token_terminator;
534 len = s - lex->input;
535 while (len < lex->input_length &&
536 (*s == ' ' || *s == '\t' || *s == '\n' || *s == '\r'))
537 {
538 if (*s++ == '\n')
539 {
540 ++lex->line_number;
541 lex->line_start = s;
542 }
543 len++;
544 }
545 lex->token_start = s;
546
547 /* Determine token type. */
548 if (len >= lex->input_length)
549 {
550 lex->token_start = NULL;
551 lex->prev_token_terminator = lex->token_terminator;
552 lex->token_terminator = s;
553 lex->token_type = JSON_TOKEN_END;
554 }
555 else
556 {
557 switch (*s)
558 {
559 /* Single-character token, some kind of punctuation mark. */
560 case '{':
561 lex->prev_token_terminator = lex->token_terminator;
562 lex->token_terminator = s + 1;
563 lex->token_type = JSON_TOKEN_OBJECT_START;
564 break;
565 case '}':
566 lex->prev_token_terminator = lex->token_terminator;
567 lex->token_terminator = s + 1;
568 lex->token_type = JSON_TOKEN_OBJECT_END;
569 break;
570 case '[':
571 lex->prev_token_terminator = lex->token_terminator;
572 lex->token_terminator = s + 1;
573 lex->token_type = JSON_TOKEN_ARRAY_START;
574 break;
575 case ']':
576 lex->prev_token_terminator = lex->token_terminator;
577 lex->token_terminator = s + 1;
578 lex->token_type = JSON_TOKEN_ARRAY_END;
579 break;
580 case ',':
581 lex->prev_token_terminator = lex->token_terminator;
582 lex->token_terminator = s + 1;

Callers 8

json_typeofFunction · 0.85
lex_expectFunction · 0.85
pg_parse_jsonFunction · 0.85
parse_scalarFunction · 0.85
parse_object_fieldFunction · 0.85
parse_objectFunction · 0.85
parse_arrayFunction · 0.85

Calls 2

json_lex_stringFunction · 0.85
json_lex_numberFunction · 0.85

Tested by

no test coverage detected