<div dir="ltr">+1 for option 3.<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Apr 25, 2015 at 1:18 PM, Yury Selivanov <span dir="ltr"><<a href="mailto:yselivanov.ml@gmail.com" target="_blank">yselivanov.ml@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Guido,<span class=""><br>
<br>
On 2015-04-24 1:03 PM, Guido van Rossum wrote:<br>
</span><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">
*3. syntactic priority of `await`*<br>
<br></span><span class="">
Yury, could you tweak the syntax for `await` so that we can write the most<br>
common usages without parentheses? In particular I'd like to be able to<br>
write<br>
```<br>
return await foo()<br>
with await foo() as bar: ...<br>
foo(await bar(), await bletch())<br>
```<br>
(I don't care about `await foo() + await bar()` but it would be okay.)<br>
```<br>
I think this is reasonable with some tweaks of the grammar (similar to what<br>
Greg did for cocall, but without requiring call syntax at the end).<br>
</span></blockquote>
<br>
I've done some experiments with grammar, and it looks like<br>
we indeed can parse await quite differently from yield. Three<br>
different options:<br>
<br>
<br>
Option #1. Parse 'await' exactly like we parse 'yield'.<br>
This how we parse 'await' in the latest version of reference<br>
implementation.<br>
<br>
Required grammar changes:<br>
<a href="https://gist.github.com/1st1/cb0bd257b04adb87e167#file-option-1-patch" target="_blank">https://gist.github.com/1st1/cb0bd257b04adb87e167#file-option-1-patch</a><br>
<br>
Repo to play with:<br>
<a href="https://github.com/1st1/cpython/tree/await" target="_blank">https://github.com/1st1/cpython/tree/await</a><br>
<br>
Syntax:<br>
<br>
 await a()<br>
 res = (await a()) + (await b())<br>
 res = (await (await a()))<br>
 if (await a()): pass<br>
 return (await a())<br>
 print((await a()))<br>
 func(arg=(await a()))<br>
 await a() * b()<br>
<br>
<br>
Option #2. Keep 'await_expr' in 'atom' terminal, but don't<br>
require parentheses.<br>
<br>
Required grammar changes:<br>
<a href="https://gist.github.com/1st1/cb0bd257b04adb87e167#file-option-2-patch" target="_blank">https://gist.github.com/1st1/cb0bd257b04adb87e167#file-option-2-patch</a><br>
<br>
Repo to play with (parser module is broken atm):<br>
<a href="https://github.com/1st1/cpython/tree/await_noparens" target="_blank">https://github.com/1st1/cpython/tree/await_noparens</a><br>
<br>
Syntax:<br>
<br>
 await a()<br>
 res = (await a()) + await b() # w/o parens (a() + await b())<br>
 res = await await a()<br>
 if await a(): pass<br>
 return await a()<br>
 print(await a())<br>
 func(arg=await a())<br>
 await a() * b()<br>
<br>
<br>
Option #3. Create a new terminal for await expression between<br>
'atom' and 'power'.<br>
<br>
Required grammar changes:<br>
<a href="https://gist.github.com/1st1/cb0bd257b04adb87e167#file-option-3-patch" target="_blank">https://gist.github.com/1st1/cb0bd257b04adb87e167#file-option-3-patch</a><br>
<br>
Repo to play with (parser module is broken atm):<br>
<a href="https://github.com/1st1/cpython/tree/await_noparens2" target="_blank">https://github.com/1st1/cpython/tree/await_noparens2</a><br>
<br>
Syntax:<br>
<br>
 await a()<br>
 res = await a() + await b()<br>
 res = await (await a()) # invalid syntax w/o parens<br>
 if await a(): pass<br>
 return await a()<br>
 print(await a())<br>
 func(arg=await a())<br>
 await (a() * b()) # w/o parens '(await a() * b())<br>
<br>
<br>
I think that Option #3 is a clear winner.<br>
<br>
Thanks,<br>
Yury<br>
<br>
</blockquote></div><br><br clear="all"><br>-- <br><div class="gmail_signature">--Guido van Rossum (<a href="http://python.org/~guido" target="_blank">python.org/~guido</a>)</div>
</div>