Method code for $command_lib.validate_command_template()

[Turn off line numbering]
  1: arg str;
  2: var cmd, tmp, loc, types, part, relations;
  3: 
  4: [tmp, types] = str.explode_delimited("<", ">");
  5: loc = [];
  6: cmd = [];
  7: relations = #[];
  8: for part in (tmp) {
  9:     if (type(part) == 'string)
 10:         cmd += part.explode();
 11:     else
 12:         cmd += [part];
 13: }
 14: 
 15: // clean
 16: for part in [1 .. cmd.length()] {
 17:     if (type(cmd[part]) == 'string) {
 18:         cmd = cmd.replace(part, cmd[part].trim());
 19:     } else {
 20:         relations = relations.add(part - 1, (> .get_argument_type(types[cmd[part]]) <));
 21:         cmd = cmd.replace(part, "*");
 22:     }
 23: }
 24: cmd = [cmd[1], cmd.subrange(2).join()];
 25: if ((| "* *" in cmd[2] |))
 26:     throw(~parse, "Invalid template: two args cannot be next to each other (<> <>)");
 27: return [cmd, relations];

// Created 27-Mar-1995 as a part of ColdCore, see: @help Credit

Tlon