cmdparser.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. """
  2. Changing the default command parser
  3. The cmdparser is responsible for parsing the raw text inserted by the
  4. user, identifying which command/commands match and return one or more
  5. matching command objects. It is called by Evennia's cmdhandler and
  6. must accept input and return results on the same form. The default
  7. handler is very generic so you usually don't need to overload this
  8. unless you have very exotic parsing needs; advanced parsing is best
  9. done at the Command.parse level.
  10. The default cmdparser understands the following command combinations
  11. (where [] marks optional parts.)
  12. [cmdname[ cmdname2 cmdname3 ...] [the rest]
  13. A command may consist of any number of space-separated words of any
  14. length, and contain any character. It may also be empty.
  15. The parser makes use of the cmdset to find command candidates. The
  16. parser return a list of matches. Each match is a tuple with its first
  17. three elements being the parsed cmdname (lower case), the remaining
  18. arguments, and the matched cmdobject from the cmdset.
  19. This module is not accessed by default. To tell Evennia to use it
  20. instead of the default command parser, add the following line to
  21. your settings file:
  22. COMMAND_PARSER = "server.conf.cmdparser.cmdparser"
  23. """
  24. def cmdparser(raw_string, cmdset, caller, match_index=None):
  25. """
  26. This function is called by the cmdhandler once it has
  27. gathered and merged all valid cmdsets valid for this particular parsing.
  28. raw_string - the unparsed text entered by the caller.
  29. cmdset - the merged, currently valid cmdset
  30. caller - the caller triggering this parsing
  31. match_index - an optional integer index to pick a given match in a
  32. list of same-named command matches.
  33. Returns:
  34. list of tuples: [(cmdname, args, cmdobj, cmdlen, mratio), ...]
  35. where cmdname is the matching command name and args is
  36. everything not included in the cmdname. Cmdobj is the actual
  37. command instance taken from the cmdset, cmdlen is the length
  38. of the command name and the mratio is some quality value to
  39. (possibly) separate multiple matches.
  40. """
  41. # Your implementation here