From f9a2f9f095bb01eb41482b663ba381b5ebffe47f Mon Sep 17 00:00:00 2001 From: Griatch Date: Thu, 8 Apr 2021 20:44:53 +0200 Subject: [PATCH] Minor refactor of exception to top of module --- docs/source/Components/FuncParser.md | 12 ++++++++---- evennia/commands/command.py | 14 +++++++------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/docs/source/Components/FuncParser.md b/docs/source/Components/FuncParser.md index 696b20c3be..e17e23bf15 100644 --- a/docs/source/Components/FuncParser.md +++ b/docs/source/Components/FuncParser.md @@ -1,5 +1,9 @@ # The Inline Function Parser +``` + +``` + The [FuncParser](api:evennia.utils.funcparser#evennia.utils.funcparser.FuncParser) extracts and executes 'inline functions' embedded in a string on the form `$funcname(args, kwargs)`. Under the hood, this will @@ -65,7 +69,7 @@ The FuncParser can be applied to any string. Out of the box it's applied in a fe ## Using the FuncParser You can apply inline function parsing to any string. The -[FuncParser](api:evennia.utils.funcparser.FuncParser) is found in `evennia.utils.funcparser.py`. +[FuncParser](api:evennia.utils.funcparser.FuncParser) is imported as `evennia.utils.funcparser`. ```python from evennia.utils import funcparser @@ -85,7 +89,7 @@ available to the parser as you parse strings with it. It can either be to include and how they should be named. Do you want a callable to be available under more than one name? Just add it multiple times to the dict, with a different key. - A `module` or (more commonly) a `python-path` to a module. This module can define a dict - `FUNCPARSER_CALLABLES = {"funcname": callable, ...}` - this will be imported and used like ther `dict` above. + `FUNCPARSER_CALLABLES = {"funcname": callable, ...}` - this will be imported and used like the `dict` above. If no such variable is defined, _every_ top-level function in the module (whose name doesn't start with an underscore `_`) will be considered a suitable callable. The name of the function will be the `$funcname` by which it can be called. @@ -123,7 +127,7 @@ Here the callable will be called as ```python _test('foo', bar='4', mydefault=2, myreserved=[1, 2, 3], - funcparser=, raise_errrors=False) + funcparser=, raise_errors=False) ``` The `mydefault=2` kwarg could be overwritten if we made the call as `$test(mydefault=...)` @@ -379,4 +383,4 @@ all the defaults (like `$toint()`). The parsed result of the above would be something like this: This is the current uptime: - ------- 343 seconds ------- \ No newline at end of file + ------- 343 seconds ------- diff --git a/evennia/commands/command.py b/evennia/commands/command.py index b8736e0475..4ca9af7e69 100644 --- a/evennia/commands/command.py +++ b/evennia/commands/command.py @@ -16,6 +16,13 @@ from evennia.utils.evtable import EvTable from evennia.utils.ansi import ANSIString +class InterruptCommand(Exception): + + """Cleanly interrupt a command.""" + + pass + + def _init_command(cls, **kwargs): """ Helper command. @@ -666,10 +673,3 @@ Command {self} has no defined `func()` - showing on-command variables: if "mode" not in kwargs: kwargs["mode"] = "footer" return self._render_decoration(*args, **kwargs) - - -class InterruptCommand(Exception): - - """Cleanly interrupt a command.""" - - pass