static const char* name_without_case(const char* name) { size_t len = strlen(name) + 1; VLA(char, buf, len); if(is_type_name(name)) { for(size_t i = 0; i < len; i++) buf[i] = (char)toupper(name[i]); } else { for(size_t i = 0; i < len; i++) buf[i] = (char)tolower(name[i]); } return stringtab(buf); }
static const char* name_without_case(const char* name) { size_t len = strlen(name) + 1; char* buf = (char*)pool_alloc_size(len); if(is_type_name(name)) { for(size_t i = 0; i < len; i++) buf[i] = (char)toupper(name[i]); } else { for(size_t i = 0; i < len; i++) buf[i] = (char)tolower(name[i]); } return stringtab_consume(buf, len); }
/* * collect_arguments() - local argument checking and collection */ static SETTINGS * collect_arguments( RULE* rule, FRAME* frame ) { SETTINGS *locals = 0; LOL * all_actual = frame->args; LOL * all_formal = rule->arguments ? rule->arguments->data : 0; if ( all_formal ) /* Nothing to set; nothing to check */ { int max = all_formal->count > all_actual->count ? all_formal->count : all_actual->count; int n; for ( n = 0; n < max ; ++n ) { LIST *actual = lol_get( all_actual, n ); char *type_name = 0; LIST *formal; for ( formal = lol_get( all_formal, n ); formal; formal = formal->next ) { char* name = formal->string; if ( is_type_name(name) ) { if ( type_name ) argument_error( "missing argument name before type name:", rule, frame, formal ); if ( !formal->next ) argument_error( "missing argument name after type name:", rule, frame, formal ); type_name = formal->string; } else { LIST* value = 0; char modifier; LIST* arg_name = formal; /* hold the argument name for type checking */ int multiple = 0; /* Stop now if a variable number of arguments are specified */ if ( name[0] == '*' && name[1] == 0 ) return locals; modifier = arg_modifier( formal ); if ( !actual && modifier != '?' && modifier != '*' ) argument_error( "missing argument", rule, frame, formal ); switch ( modifier ) { case '+': case '*': value = list_copy( 0, actual ); multiple = 1; actual = 0; /* skip an extra element for the modifier */ formal = formal->next; break; case '?': /* skip an extra element for the modifier */ formal = formal->next; /* fall through */ default: if ( actual ) /* in case actual is missing */ { value = list_new( 0, actual->string ); actual = actual->next; } } locals = addsettings(locals, VAR_SET, name, value); locals->multiple = multiple; type_check( type_name, value, frame, rule, arg_name ); type_name = 0; } } if ( actual ) { argument_error( "extra argument", rule, frame, actual ); } } } return locals; }
void record_struct::parse(proto_info &info, cursor &c) { pimpl->name = get_to_sep(c, ' ', struct_base_classes_separator, struct_body_open_char); skipws(c); // process list of base structs if ( curch(c) == struct_base_classes_separator ) { nextch(c); skipws(c); cursor tc = c; std::string base; bool flag = false; while ( ! flag ) { char ch = nextch(c); switch ( ch ) { case '/': { prevch(c); skipws(c); continue; } case ' ': case ',': { if ( ch == ',' && base.empty() ) YARMI_THROW( "bad char '%c', expected name of base struct in %s" ,ch ,c.format() ); if ( !struct_already_declared(info, base) ) YARMI_THROW( "base struct '%s'(%s) is not declared" ,base ,tc.format() ); pimpl->base.push_back(base); base.clear(); skipws(c); if ( curch(c) == ',' ) { nextch(c); skipws(c); } tc = c; continue; } case struct_body_open_char: { flag = true; prevch(c); break; } default: { base.push_back(ch); } } } } check_next(c, struct_body_open_char); skipws(c); for ( ;; ) { const iterator it = c.it; const std::string kword = get_to_sep(c, ' '); const bool is_type = is_type_name(kword); c.it = (is_type ? it : c.it); record_ptr o = record_factory((is_type ? "var" : kword)); if ( !o ) YARMI_THROW( "bad keyword \"%s\" in %s" ,kword ,c.format() ); o->parse(info, c); pimpl->members.push_back(std::move(o)); skipws(c); const char ch = curch(c); if ( ch == struct_body_close_char ) break; } check_next(c, struct_body_close_char); check_next(c, struct_body_close_dotcomma_char); }