evennia/docs/0.x/api/evennia.commands.cmdparser.html
2023-12-20 19:10:09 +01:00

234 lines
No EOL
13 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!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 &#8212; Evennia 0.9.5 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>
<script async="async" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/latest.js?config=TeX-AMS-MML_HTMLorMML"></script>
<script type="text/x-mathjax-config">MathJax.Hub.Config({"tex2jax": {"processClass": "tex2jax_process|mathjax_process|math|output_area"}})</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" />
</head><body>
<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="nav-item nav-item-0"><a href="../index.html">Evennia 0.9.5</a> &#187;</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="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 commands 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 commands 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 &#64;, ! 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_prefixes">
<code class="sig-prename descclassname">evennia.commands.cmdparser.</code><code class="sig-name descname">try_num_prefixes</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_prefixes"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#evennia.commands.cmdparser.try_num_prefixes" 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 class="clearer"></div>
</div>
</div>
</div>
<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>
<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">Home page</a> </li>
<li><a href="https://github.com/evennia/evennia">Evennia Github</a> </li>
<li><a href="http://games.evennia.com">Game Index</a> </li>
<li><a href="http://webchat.freenode.net/?channels=evennia&uio=MT1mYWxzZSY5PXRydWUmMTE9MTk1JjEyPXRydWUbb">IRC</a> -
<a href="https://discord.gg/NecFePw">Discord</a> -
<a href="https://groups.google.com/forum/#%21forum/evennia">Forums</a>
</li>
<li><a href="http://evennia.blogspot.com/">Evennia Dev blog</a> </li>
</ul>
<h3>Versions</h3>
<ul>
<li><a href="../../1.0-dev/api/evennia.commands.cmdparser.html">1.0-dev (develop branch)</a></li>
<li><a href="evennia.commands.cmdparser.html">0.9.5 (v0.9.5 branch)</a></li>
</ul>
</div>
</div>
<div class="clearer"></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="nav-item nav-item-0"><a href="../index.html">Evennia 0.9.5</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">evennia.commands.cmdparser</a></li>
</ul>
</div>
<div class="footer" role="contentinfo">
&#169; Copyright 2020, The Evennia developer community.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.2.1.
</div>
</body>
</html>