static void parse_namespace(fb_parser_t *P) { fb_ref_t *ref = 0; fb_token_t *t = P->token; parse_ref(P, &ref); advance(P, ';', "missing ';' expected by namespace at", t); P->current_scope = fb_add_scope(P, ref); }
static void parse_namespace(fb_parser_t *P) { fb_ref_t *ref = 0; fb_token_t *t = P->token; if (optional(P, ';') && t) { /* Revert to global namespace. */ P->current_scope = 0; return; } if (P->token->id != LEX_TOK_ID) { error_tok(P, P->token, "namespace expects an identifier"); recover(P, ';', 1); return; } parse_ref(P, &ref); advance(P, ';', "missing ';' expected by namespace at", t); P->current_scope = fb_add_scope(P, ref); }
/* Root schema `rs` is null for top level parser. */ int fb_init_parser(fb_parser_t *P, fb_options_t *opts, const char *name, fb_error_fun error_out, void *error_ctx, fb_root_schema_t *rs) { int i, n, name_len; char *s; memset(P, 0, sizeof(*P)); if (error_out) { P->error_out = error_out; P->error_ctx = error_ctx; } else { P->error_out = fb_default_error_out; } if (opts) { memcpy(&P->opts, opts, sizeof(*opts)); } else { flatcc_init_options(&P->opts); } P->schema.root_schema = rs ? rs : &P->schema.root_schema_instance; switch (P->opts.offset_size) { case 2: case 4: case 8: break; default: error(P, "invalid offset configured, must be 2, 4 (default), or 8"); return -1; } switch (P->opts.voffset_size) { case 2: case 4: case 8: break; default: error(P, "invalid voffset configured, must be 2 (default), 4, or 8"); return -1; } if (!name) { /* Mostly for testing, just so we always have a name. */ name = FLATCC_DEFAULT_FILENAME; } if (name == 0) { name = ""; } name_len = strlen(name); checkmem((P->schema.basename = fb_create_basename(name, name_len, opts->default_schema_ext))); n = strlen(P->schema.basename); checkmem(s = fb_copy_path(P->schema.basename, n)); for (i = 0; i < n; ++i) { s[i] = toupper(s[i]); } P->schema.basenameup = s; P->schema.name.name.s.s = s; P->schema.name.name.s.len = n; checkmem((P->schema.errorname = fb_create_basename(name, name_len, ""))); if (opts->ns) { P->schema.prefix.s = (char *)opts->ns; P->schema.prefix.len = strlen(opts->ns); } P->current_scope = fb_add_scope(P, 0); assert(P->current_scope == fb_scope_table_find(&P->schema.root_schema->scope_index, 0, 0)); return 0; }