<div dir="ltr">Thanks, I had tried it and got the ambiguities, but I wasn't sure if those would disappear with editing some peripheral file.<div><br></div><div>Yes, you're right about the set branch.</div><div><br></div><div>Thank you,</div><div><br></div><div>Neil</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Jan 24, 2015 at 10:29 PM, Guido van Rossum <span dir="ltr"><<a href="mailto:guido@python.org" target="_blank">guido@python.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><div>Have you tried it yet?<br><br>I think you have to inline dictpopulator, because dictpopulator can start with the same tokens as test, and the parser doesn't backtrack. So it wouldn't know how to decide whether to take the dictpopulator branch or the set branch. If you inline it, the parser will know, because it does something clever within the rule.<br><br>As-is, I get a lot of errors from pgen about ambiguity. This one seems to work (but you still have to adjust the code generator of course):<br><br><span style="font-family:monospace,monospace">dictorsetmaker: ( ((test ':' test | '**' test) (comp_for | (',' (test ':' test | '**' test))* [','])) |<span class=""><br>                   (test (comp_for | (',' test)* [','])) )</span></span><br><br></div>Also I presume you want a similar treatment for the set branch (replace both tests with (test | '*' test).<br><br></div>Good luck! There's plenty of code to crib from for the code generation.<br><br></div>--Guido<br></div><div class="gmail_extra"><br><div class="gmail_quote"><div><div class="h5">On Sat, Jan 24, 2015 at 6:10 PM, Neil Girdhar <span dir="ltr"><<a href="mailto:mistersheik@gmail.com" target="_blank">mistersheik@gmail.com</a>></span> wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5"><div dir="ltr">To finish PEP 448, I need to update the grammar for syntax such as<div><br></div><div>{**x for x in it}</div><div><br></div><div>and</div><div><br></div><div>{1:2, 3:4, **a}</div><div><br></div><div>It's been a long time since I've looked at grammars and I could really use the advice of an expert.  I'm considering replacing:</div><div><div><br></div><div><div>dictorsetmaker: ( (test ':' test (comp_for | (',' test ':' test)* [','])) |</div><div>                  (test (comp_for | (',' test)* [','])) )</div></div><div><br></div><div>with:</div><div><br></div><div>dictpopulator: test ':' test | '**' test</div><div>dictorsetmaker: ( (dictpopulator (comp_for | (',' dictpopulator)* [','])) |</div><div>                   (test (comp_for | (',' test)* [','])) )</div></div><div><br></div><div>Am I headed in the right direction?  Of course I will need to edit parsermodule.c and ast.c.</div><div><br></div><div>Best,</div><div><br></div><div>Neil</div></div>
<br></div></div>_______________________________________________<br>
Python-Dev mailing list<br>
<a href="mailto:Python-Dev@python.org" target="_blank">Python-Dev@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-dev" target="_blank">https://mail.python.org/mailman/listinfo/python-dev</a><br>
Unsubscribe: <a href="https://mail.python.org/mailman/options/python-dev/guido%40python.org" target="_blank">https://mail.python.org/mailman/options/python-dev/guido%40python.org</a><br>
<br></blockquote></div><span class="HOEnZb"><font color="#888888"><br><br clear="all"><br>-- <br><div>--Guido van Rossum (<a href="http://python.org/~guido" target="_blank">python.org/~guido</a>)</div>
</font></span></div>
</blockquote></div><br></div>