Allow yield indented object (#5072)

* allow yield indented object

* allow await indented object

* fixes from code review
This commit is contained in:
Julian Rosse 2018-06-11 00:45:45 -04:00 committed by Geoffrey Booth
parent be702d67f3
commit 70f6cb70e2
6 changed files with 308 additions and 224 deletions

View File

@ -129,6 +129,11 @@
return new Op($1,
$2);
}),
o('YIELD INDENT Object OUTDENT',
function() {
return new Op($1,
$3);
}),
o('YIELD FROM Expression',
function() {
return new Op($1.concat($2),
@ -1958,6 +1963,11 @@
return new Op($1,
$2);
}),
o('AWAIT INDENT Object OUTDENT',
function() {
return new Op($1,
$3);
}),
o('-- SimpleAssignable',
function() {
return new Op('--',

File diff suppressed because one or more lines are too long

View File

@ -138,6 +138,7 @@ grammar =
Yield: [
o 'YIELD', -> new Op $1, new Value new Literal ''
o 'YIELD Expression', -> new Op $1, $2
o 'YIELD INDENT Object OUTDENT', -> new Op $1, $3
o 'YIELD FROM Expression', -> new Op $1.concat($2), $3
]
@ -817,7 +818,8 @@ grammar =
o '- Expression', (-> new Op '-', $2), prec: 'UNARY_MATH'
o '+ Expression', (-> new Op '+', $2), prec: 'UNARY_MATH'
o 'AWAIT Expression', -> new Op $1 , $2
o 'AWAIT Expression', -> new Op $1, $2
o 'AWAIT INDENT Object OUTDENT', -> new Op $1, $3
o '-- SimpleAssignable', -> new Op '--', $2
o '++ SimpleAssignable', -> new Op '++', $2

View File

@ -196,3 +196,11 @@ test "async methods in classes", ->
eq await Child.static(), 1
eq await new Child().method(), 2
test "#3199: await multiline implicit object", ->
do ->
y =
if no then await
type: 'a'
msg: 'b'
eq undefined, y

View File

@ -1796,6 +1796,50 @@ test "#3199: error message for throw indented comprehension", ->
^
'''
test "#3199: error message for yield indented non-object", ->
assertErrorFormat '''
->
yield
1
''', '''
[stdin]:3:5: error: unexpected number
1
^
'''
test "#3199: error message for yield indented comprehension", ->
assertErrorFormat '''
->
yield
x for x in [1, 2, 3]
''', '''
[stdin]:3:5: error: unexpected identifier
x for x in [1, 2, 3]
^
'''
test "#3199: error message for await indented non-object", ->
assertErrorFormat '''
->
await
1
''', '''
[stdin]:3:5: error: unexpected number
1
^
'''
test "#3199: error message for await indented comprehension", ->
assertErrorFormat '''
->
await
x for x in [1, 2, 3]
''', '''
[stdin]:3:5: error: unexpected identifier
x for x in [1, 2, 3]
^
'''
test "#3098: suppressed newline should be unsuppressed by semicolon", ->
assertErrorFormat '''
a = ; 5

View File

@ -417,6 +417,22 @@ test "#3199: throw multiline implicit object", ->
msg: 'b'
eq undefined, y
y = do ->
yield
type: 'a'
msg: 'b'
if no then yield
type: 'c'
msg: 'd'
1
{value, done} = y.next()
ok value.type is 'a' and done is no
{value, done} = y.next()
ok value is 1 and done is yes
test "#4576: multiple row function chaining", ->
->
eq @a, 3