mirror of
https://github.com/evennia/evennia.git
synced 2026-03-18 13:56:30 +01:00
271 lines
No EOL
15 KiB
HTML
271 lines
No EOL
15 KiB
HTML
|
||
<!DOCTYPE html>
|
||
|
||
<html>
|
||
<head>
|
||
<meta charset="utf-8" />
|
||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
|
||
|
||
<title>evennia.commands.cmdparser — Evennia latest documentation</title>
|
||
<link rel="stylesheet" href="../_static/nature.css" type="text/css" />
|
||
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
|
||
<script id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
|
||
<script src="../_static/jquery.js"></script>
|
||
<script src="../_static/underscore.js"></script>
|
||
<script src="../_static/doctools.js"></script>
|
||
<script src="../_static/language_data.js"></script>
|
||
<link rel="shortcut icon" href="../_static/favicon.ico"/>
|
||
<link rel="index" title="Index" href="../genindex.html" />
|
||
<link rel="search" title="Search" href="../search.html" />
|
||
<link rel="next" title="evennia.commands.cmdset" href="evennia.commands.cmdset.html" />
|
||
<link rel="prev" title="evennia.commands.cmdhandler" href="evennia.commands.cmdhandler.html" />
|
||
</head><body>
|
||
|
||
|
||
<div class="admonition important">
|
||
<p class="first admonition-title">Note</p>
|
||
<p class="last">You are reading an old version of the Evennia documentation. <a href="https://www.evennia.com/docs/latest/index.html">The latest version is here</a></p>.
|
||
</div>
|
||
|
||
|
||
|
||
<div class="related" role="navigation" aria-label="related navigation">
|
||
<h3>Navigation</h3>
|
||
<ul>
|
||
<li class="right" style="margin-right: 10px">
|
||
<a href="../genindex.html" title="General Index"
|
||
accesskey="I">index</a></li>
|
||
<li class="right" >
|
||
<a href="../py-modindex.html" title="Python Module Index"
|
||
>modules</a> |</li>
|
||
<li class="right" >
|
||
<a href="evennia.commands.cmdset.html" title="evennia.commands.cmdset"
|
||
accesskey="N">next</a> |</li>
|
||
<li class="right" >
|
||
<a href="evennia.commands.cmdhandler.html" title="evennia.commands.cmdhandler"
|
||
accesskey="P">previous</a> |</li>
|
||
<li class="nav-item nav-item-0"><a href="../index.html">Evennia latest</a> »</li>
|
||
<li class="nav-item nav-item-1"><a href="../Evennia-API.html" >API Summary</a> »</li>
|
||
<li class="nav-item nav-item-2"><a href="evennia-api.html" >evennia</a> »</li>
|
||
<li class="nav-item nav-item-3"><a href="evennia.html" >evennia</a> »</li>
|
||
<li class="nav-item nav-item-4"><a href="evennia.commands.html" accesskey="U">evennia.commands</a> »</li>
|
||
<li class="nav-item nav-item-this"><a href="">evennia.commands.cmdparser</a></li>
|
||
</ul>
|
||
</div>
|
||
|
||
<div class="document">
|
||
|
||
<div class="documentwrapper">
|
||
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
|
||
<div class="sphinxsidebarwrapper">
|
||
<p class="logo"><a href="../index.html">
|
||
<img class="logo" src="../_static/evennia_logo.png" alt="Logo"/>
|
||
</a></p>
|
||
<div id="searchbox" style="display: none" role="search">
|
||
<h3 id="searchlabel">Quick search</h3>
|
||
<div class="searchformwrapper">
|
||
<form class="search" action="../search.html" method="get">
|
||
<input type="text" name="q" aria-labelledby="searchlabel" />
|
||
<input type="submit" value="Go" />
|
||
</form>
|
||
</div>
|
||
</div>
|
||
<script>$('#searchbox').show(0);</script>
|
||
<h4>Previous topic</h4>
|
||
<p class="topless"><a href="evennia.commands.cmdhandler.html"
|
||
title="previous chapter">evennia.commands.cmdhandler</a></p>
|
||
<h4>Next topic</h4>
|
||
<p class="topless"><a href="evennia.commands.cmdset.html"
|
||
title="next chapter">evennia.commands.cmdset</a></p>
|
||
<div role="note" aria-label="source link">
|
||
<!--h3>This Page</h3-->
|
||
<ul class="this-page-menu">
|
||
<li><a href="../_sources/api/evennia.commands.cmdparser.md.txt"
|
||
rel="nofollow">Show Page Source</a></li>
|
||
</ul>
|
||
</div><h3>Links</h3>
|
||
<ul>
|
||
<li><a href="https://www.evennia.com/docs/latest/index.html">Documentation Top</a> </li>
|
||
<li><a href="https://www.evennia.com">Evennia Home</a> </li>
|
||
<li><a href="https://github.com/evennia/evennia">Github</a> </li>
|
||
<li><a href="http://games.evennia.com">Game Index</a> </li>
|
||
<li>
|
||
<a href="https://discord.gg/AJJpcRUhtF">Discord</a> -
|
||
<a href="https://github.com/evennia/evennia/discussions">Discussions</a> -
|
||
<a href="https://evennia.blogspot.com/">Blog</a>
|
||
</li>
|
||
</ul>
|
||
</div>
|
||
</div>
|
||
<div class="bodywrapper">
|
||
<div class="body" role="main">
|
||
|
||
<section id="module-evennia.commands.cmdparser">
|
||
<span id="evennia-commands-cmdparser"></span><h1>evennia.commands.cmdparser<a class="headerlink" href="#module-evennia.commands.cmdparser" title="Permalink to this headline">¶</a></h1>
|
||
<p>The default command parser. Use your own by assigning
|
||
<strong>settings.COMMAND_PARSER</strong> to a Python path to a module containing the
|
||
replacing cmdparser function. The replacement parser must accept the
|
||
same inputs as the default one.</p>
|
||
<dl class="py function">
|
||
<dt id="evennia.commands.cmdparser.create_match">
|
||
<code class="sig-prename descclassname">evennia.commands.cmdparser.</code><code class="sig-name descname">create_match</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">cmdname</span></em>, <em class="sig-param"><span class="n">string</span></em>, <em class="sig-param"><span class="n">cmdobj</span></em>, <em class="sig-param"><span class="n">raw_cmdname</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/evennia/commands/cmdparser.html#create_match"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#evennia.commands.cmdparser.create_match" title="Permalink to this definition">¶</a></dt>
|
||
<dd><p>Builds a command match by splitting the incoming string and
|
||
evaluating the quality of the match.</p>
|
||
<dl class="field-list simple">
|
||
<dt class="field-odd">Parameters</dt>
|
||
<dd class="field-odd"><ul class="simple">
|
||
<li><p><strong>cmdname</strong> (<em>str</em>) – Name of command to check for.</p></li>
|
||
<li><p><strong>string</strong> (<em>str</em>) – The string to match against.</p></li>
|
||
<li><p><strong>cmdobj</strong> (<em>str</em>) – The full Command instance.</p></li>
|
||
<li><p><strong>raw_cmdname</strong> (<em>str</em><em>, </em><em>optional</em>) – If CMD_IGNORE_PREFIX is set and the cmdname starts with
|
||
one of the prefixes to ignore, this contains the raw, unstripped cmdname,
|
||
otherwise it is None.</p></li>
|
||
</ul>
|
||
</dd>
|
||
<dt class="field-even">Returns</dt>
|
||
<dd class="field-even"><p><p><em>match (tuple)</em> –</p>
|
||
<dl class="simple">
|
||
<dt>This is on the form (cmdname, args, cmdobj, cmdlen, mratio, raw_cmdname),</dt><dd><p>where <strong>cmdname</strong> is the command’s name and <strong>args</strong> is the rest of the incoming
|
||
string, without said command name. <strong>cmdobj</strong> is
|
||
the Command instance, the cmdlen is the same as len(cmdname) and mratio
|
||
is a measure of how big a part of the full input string the cmdname
|
||
takes up - an exact match would be 1.0. Finally, the <strong>raw_cmdname</strong> is
|
||
the cmdname unmodified by eventual prefix-stripping.</p>
|
||
</dd>
|
||
</dl>
|
||
</p>
|
||
</dd>
|
||
</dl>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt id="evennia.commands.cmdparser.build_matches">
|
||
<code class="sig-prename descclassname">evennia.commands.cmdparser.</code><code class="sig-name descname">build_matches</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">raw_string</span></em>, <em class="sig-param"><span class="n">cmdset</span></em>, <em class="sig-param"><span class="n">include_prefixes</span><span class="o">=</span><span class="default_value">False</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/evennia/commands/cmdparser.html#build_matches"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#evennia.commands.cmdparser.build_matches" title="Permalink to this definition">¶</a></dt>
|
||
<dd><p>Build match tuples by matching raw_string against available commands.</p>
|
||
<dl class="field-list simple">
|
||
<dt class="field-odd">Parameters</dt>
|
||
<dd class="field-odd"><ul class="simple">
|
||
<li><p><strong>raw_string</strong> (<em>str</em>) – Input string that can look in any way; the only assumption is
|
||
that the sought command’s name/alias must be <em>first</em> in the string.</p></li>
|
||
<li><p><strong>cmdset</strong> (<a class="reference internal" href="evennia.commands.cmdset.html#evennia.commands.cmdset.CmdSet" title="evennia.commands.cmdset.CmdSet"><em>CmdSet</em></a>) – The current cmdset to pick Commands from.</p></li>
|
||
<li><p><strong>include_prefixes</strong> (<em>bool</em>) – If set, include prefixes like @, ! etc (specified in settings)
|
||
in the match, otherwise strip them before matching.</p></li>
|
||
</ul>
|
||
</dd>
|
||
<dt class="field-even">Returns</dt>
|
||
<dd class="field-even"><p>matches (list) A list of match tuples created by <strong>cmdparser.create_match</strong>.</p>
|
||
</dd>
|
||
</dl>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt id="evennia.commands.cmdparser.try_num_differentiators">
|
||
<code class="sig-prename descclassname">evennia.commands.cmdparser.</code><code class="sig-name descname">try_num_differentiators</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">raw_string</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/evennia/commands/cmdparser.html#try_num_differentiators"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#evennia.commands.cmdparser.try_num_differentiators" title="Permalink to this definition">¶</a></dt>
|
||
<dd><p>Test if user tried to separate multi-matches with a number separator
|
||
(default 1-name, 2-name etc). This is usually called last, if no other
|
||
match was found.</p>
|
||
<dl class="field-list simple">
|
||
<dt class="field-odd">Parameters</dt>
|
||
<dd class="field-odd"><p><strong>raw_string</strong> (<em>str</em>) – The user input to parse.</p>
|
||
</dd>
|
||
<dt class="field-even">Returns</dt>
|
||
<dd class="field-even"><p><p><em>mindex, new_raw_string (tuple)</em> –</p>
|
||
<dl class="simple">
|
||
<dt>If a multimatch-separator was detected,</dt><dd><p>this is stripped out as an integer to separate between the matches. The
|
||
new_raw_string is the result of stripping out that identifier. If no
|
||
such form was found, returns (None, None).</p>
|
||
</dd>
|
||
</dl>
|
||
</p>
|
||
</dd>
|
||
</dl>
|
||
<p class="rubric">Example</p>
|
||
<p>In the default configuration, entering 2-ball (e.g. in a room will more
|
||
than one ‘ball’ object), will lead to a multimatch and this function
|
||
will parse <strong>“2-ball”</strong> and return <strong>(2, “ball”)</strong>.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt id="evennia.commands.cmdparser.cmdparser">
|
||
<code class="sig-prename descclassname">evennia.commands.cmdparser.</code><code class="sig-name descname">cmdparser</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">raw_string</span></em>, <em class="sig-param"><span class="n">cmdset</span></em>, <em class="sig-param"><span class="n">caller</span></em>, <em class="sig-param"><span class="n">match_index</span><span class="o">=</span><span class="default_value">None</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/evennia/commands/cmdparser.html#cmdparser"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#evennia.commands.cmdparser.cmdparser" title="Permalink to this definition">¶</a></dt>
|
||
<dd><p>This function is called by the cmdhandler once it has
|
||
gathered and merged all valid cmdsets valid for this particular parsing.</p>
|
||
<dl class="field-list simple">
|
||
<dt class="field-odd">Parameters</dt>
|
||
<dd class="field-odd"><ul class="simple">
|
||
<li><p><strong>raw_string</strong> (<em>str</em>) – The unparsed text entered by the caller.</p></li>
|
||
<li><p><strong>cmdset</strong> (<a class="reference internal" href="evennia.commands.cmdset.html#evennia.commands.cmdset.CmdSet" title="evennia.commands.cmdset.CmdSet"><em>CmdSet</em></a>) – The merged, currently valid cmdset</p></li>
|
||
<li><p><strong>caller</strong> (<a class="reference internal" href="evennia.server.session.html#evennia.server.session.Session" title="evennia.server.session.Session"><em>Session</em></a><em>, </em><em>Account</em><em> or </em><em>Object</em>) – The caller triggering this parsing.</p></li>
|
||
<li><p><strong>match_index</strong> (<em>int</em><em>, </em><em>optional</em>) – Index to pick a given match in a
|
||
list of same-named command matches. If this is given, it suggests
|
||
this is not the first time this function was called: normally
|
||
the first run resulted in a multimatch, and the index is given
|
||
to select between the results for the second run.</p></li>
|
||
</ul>
|
||
</dd>
|
||
<dt class="field-even">Returns</dt>
|
||
<dd class="field-even"><p><p><em>matches (list)</em> –</p>
|
||
<dl class="simple">
|
||
<dt>This is a list of match-tuples as returned by <strong>create_match</strong>.</dt><dd><p>If no matches were found, this is an empty list.</p>
|
||
</dd>
|
||
</dl>
|
||
</p>
|
||
</dd>
|
||
</dl>
|
||
<p class="rubric">Notes</p>
|
||
<p>The cmdparser understand the following command combinations (where
|
||
[] marks optional parts.</p>
|
||
<p>[cmdname[ cmdname2 cmdname3 …] [the rest]</p>
|
||
<p>A command may consist of any number of space-separated words of any
|
||
length, and contain any character. It may also be empty.</p>
|
||
<p>The parser makes use of the cmdset to find command candidates. The
|
||
parser return a list of matches. Each match is a tuple with its
|
||
first three elements being the parsed cmdname (lower case),
|
||
the remaining arguments, and the matched cmdobject from the cmdset.</p>
|
||
</dd></dl>
|
||
|
||
</section>
|
||
|
||
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
</div>
|
||
<div class="related" role="navigation" aria-label="related navigation">
|
||
<h3>Navigation</h3>
|
||
<ul>
|
||
<li class="right" style="margin-right: 10px">
|
||
<a href="../genindex.html" title="General Index"
|
||
>index</a></li>
|
||
<li class="right" >
|
||
<a href="../py-modindex.html" title="Python Module Index"
|
||
>modules</a> |</li>
|
||
<li class="right" >
|
||
<a href="evennia.commands.cmdset.html" title="evennia.commands.cmdset"
|
||
>next</a> |</li>
|
||
<li class="right" >
|
||
<a href="evennia.commands.cmdhandler.html" title="evennia.commands.cmdhandler"
|
||
>previous</a> |</li>
|
||
<li class="nav-item nav-item-0"><a href="../index.html">Evennia latest</a> »</li>
|
||
<li class="nav-item nav-item-1"><a href="../Evennia-API.html" >API Summary</a> »</li>
|
||
<li class="nav-item nav-item-2"><a href="evennia-api.html" >evennia</a> »</li>
|
||
<li class="nav-item nav-item-3"><a href="evennia.html" >evennia</a> »</li>
|
||
<li class="nav-item nav-item-4"><a href="evennia.commands.html" >evennia.commands</a> »</li>
|
||
<li class="nav-item nav-item-this"><a href="">evennia.commands.cmdparser</a></li>
|
||
</ul>
|
||
</div>
|
||
|
||
|
||
<div class="admonition important">
|
||
<p class="first admonition-title">Note</p>
|
||
<p class="last">You are reading an old version of the Evennia documentation. <a href="https://www.evennia.com/docs/latest/index.html">The latest version is here</a></p>.
|
||
</div>
|
||
|
||
|
||
<div class="footer" role="contentinfo">
|
||
© Copyright 2023, The Evennia developer community.
|
||
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.2.1.
|
||
</div>
|
||
</body>
|
||
</html> |