static ZZJSON *parse_value(ZZJSON_CONFIG *config) { ZZJSON *retval = NULL; int c; SKIPWS(); c = GETC(); UNGETC(c); switch (c) { case '"': retval = parse_string2(config); break; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case '-': retval = parse_number(config); break; case '{': retval = parse_object(config); break; case '[': retval = parse_array(config); break; case 't': retval = parse_true(config); break; case 'f': retval = parse_false(config); break; case 'n': retval = parse_null(config); break; } if (!retval) { ERROR("value: invalid value"); return retval; } return retval; }
json parser::parse_next( const std::string& input, size_t& offset, std::error_code& error) { char value; consume_white_space(input, offset, error); value = input[offset]; switch (value) { case '[': return parse_array(input, offset, error); case '{': return parse_object(input, offset, error); case '\"': return parse_string(input, offset, error); case 't': case 'f': return parse_bool(input, offset, error); case 'n': return parse_null(input, offset, error); default: { if ((value <= '9' && value >= '0') || value == '-') { return parse_number(input, offset, error); } } } // Error: Unknown starting character error = std::make_error_code(std::errc::invalid_argument); return json(); }
closure *parse_null(FILE *file, closure *accum) { //printf("parse null\n"); wchar_t c = fgetwc(file); if(iswspace(c)){ return parse_null(file, nil()); } else if(c == L'$'){ return parse_character(file, nil()); } else if(c == L'#'){ parse_comment(file, nil()); return parse_null(file, accum); } else if(c == L'\"'){ return parse_string(file, nil()); } else if(c == L'\''){ wchar_t c = fgetwc(file); if (!iswspace(c)){ ungetwc(c, file); closure *boo = parse_null(file, nil()); if (boo != NULL) return quote(boo); } return symbol(QUOTE); } else if(c == L'@'){ wchar_t c = fgetwc(file); if (!iswspace(c)){ ungetwc(c, file); closure *boo = parse_null(file, nil()); if (boo != NULL) return list(2, symbol(ATPEND), boo); } return symbol(ATPEND); } else if(c == L','){ wchar_t c = fgetwc(file); if (!iswspace(c)){ ungetwc(c, file); closure *boo = parse_null(file, nil()); if (boo != NULL) return list(2, symbol(COMMA), boo); } return symbol(COMMA); } else if(c == L'*'){ wchar_t c = fgetwc(file); if (!iswspace(c)){ ungetwc(c, file); closure *boo = parse_null(file, nil()); if (boo != NULL) return list(2, symbol(ASTERIX), boo); } return symbol(ASTERIX); } else if(iswdigit(c)){ ungetwc(c, file); return parse_number(file, nil()); } else if(c == L'('){ return parse_list(file, nil()); } else if(c == L')'){ ungetwc(c, file); return NULL; } else if(c == WEOF || c == EOF){ return NULL; } else { return parse_symbol(file, cons(character(c), nil())); } }
int parse_value(const char** input, JzonValue* output, JzonAllocator* allocator) { skip_whitespace(input); char ch = current(input); switch (ch) { case '{': return parse_object(input, output, false, allocator); case '[': return parse_array(input, output, allocator); case '"': return parse_string(input, output, allocator); case '-': return parse_number(input, output); case 'f': return parse_false(input, output); case 't': return parse_true(input, output); case 'n': return parse_null(input, output); default: return ch >= '0' && ch <= '9' ? parse_number(input, output) : -1; } }
closure *parse_list(FILE *file, closure *accum) { //printf("parse list\n"); //print_closure(accum); wchar_t c = fgetwc(file); if(c == L')'){ return reverse(accum); } else { ungetwc(c, file); closure *boo = parse_null(file, nil()); if (boo != NULL){ return parse_list(file, cons(boo, accum)); } else { return parse_list(file, accum); } } }
void json::parse_value( std::istream_iterator<char> &it, std::istream_iterator<char> &end, int &line ) { skip_whitespace( it, end, line ); if ( it == end ) { clear(); return; } switch ( *it ) { case '[': parse_array( it, end, line ); break; case '{': parse_object( it, end, line ); break; case '"': parse_string( it, end, line ); break; case 't': parse_true( it, end, line ); break; case 'f': parse_false( it, end, line ); break; case 'n': parse_null( it, end, line ); break; default: parse_number( it, end, line ); } }
void json_parser<_Handler>::value() { char c = cur_char(); if (is_numeric(c)) { number(); return; } switch (c) { case '-': number(); break; case '[': array(); break; case '{': object(); break; case 't': parse_true(); m_handler.boolean_true(); break; case 'f': parse_false(); m_handler.boolean_false(); break; case 'n': parse_null(); m_handler.null(); break; case '"': string(); break; default: json::parse_error::throw_with("value: failed to parse '", cur_char(), "'.", offset()); } }
static int parse_value(lua_State *L, parse_state *state) { eat_whitespace(state); char c = *state->ptr; switch (c) { case '"': return parse_string(L, state); case '{': return parse_object(L, state); case '[': return parse_array(L, state); case 't': case 'f': return parse_boolean(L, state); case 'n': return parse_null(L, state); case '-': case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': return parse_number(L, state); default: return push_parse_error(L, state, "unexpected character"); } }
bool parser::parse_value(context& ctx, value_type& value, IteratorType& ch, IteratorType end) { bool result = false; if (ch != end) { switch (*ch) { case '{': { object_type object; result = parse_object(ctx, object, ch, end); if (result) { value = object; } break; } case '[': { array_type array; result = parse_array(ctx, array, ch, end); if (result) { value = array; } break; } case '"': { string_type str; result = parse_string(ctx, str, ch, end); if (result) { value = str; } break; } case 't': case 'f': { boolean_type bt; result = parse_boolean(ctx, bt, ch, end); if (result) { value = bt; } break; } case 'n': { null_type nt; result = parse_null(ctx, nt, ch, end); if (result) { value = nt; } break; } default: { number_type nb; result = parse_number(ctx, nb, ch, end); if (result) { value = nb; } break; } } } return result; }
closure *parse_file(FILE *file) { closure *boo = parse_null(file, nil()); return boo; }