Returning an empty list with 'or' syntax using Parsley
<p>I'm trying to match a word using Parsley. The grammar that I'm using only works when I make a rule for a generic word. However, I would like to know why it doesn't work the way it is shown from Allen Short's presentation and sample code here (<a href="http://bit.ly/1025Qxo" rel="nofollow">http://bit.ly/1025Qxo</a>) and here (<a href="http://bit.ly/17wzUYg" rel="nofollow">http://bit.ly/17wzUYg</a>). </p>

<p>In his code, he has:</p>

<pre><code>rule = (expr1 -&gt; returnval) | -&gt; []
</code></pre>

<p>But the only way I got it to work was:</p>

<pre><code>rule = (expr1 -&gt; returnval) | (expr2) -&gt; [] 
</code></pre>

<p>Here's my code:</p>

<pre class="lang-python prettyprint-override"><code>import parsley

grammar = r"""

myword = "hello"
myrule = (myword:word -&gt; word) | -&gt; []
"""

MyPar = parsley.makeGrammar(grammar,{})
print MyPar("hello").myrule() # works, returns myword
print MyPar("bye").myrule() # doesn't work, throws exception
</code></pre>

<p>The only way I got it to work was to make a rule for a generic word string using the built-in 'letter' variable.</p>

<pre class="lang-python prettyprint-override"><code>import parsley

grammar = r"""

myword = "hello"
anyword = &lt;letter+&gt;
myrule = (myword:word -&gt; word) | anyword -&gt; []
"""

MyPar = parsley.makeGrammar(grammar,{})
print MyPar("hello").myrule() # works
print MyPar("bye").myrule() # works, returns empty list
</code></pre>

<p>Any help would be appreciated. Thank you.</p>

<p>Paul</p>
