()
| 4154 | } |
| 4155 | |
| 4156 | func (p *Parser) isYieldExpression() bool { |
| 4157 | if p.token == ast.KindYieldKeyword { |
| 4158 | // If we have a 'yield' keyword, and this is a context where yield expressions are |
| 4159 | // allowed, then definitely parse out a yield expression. |
| 4160 | if p.inYieldContext() { |
| 4161 | return true |
| 4162 | } |
| 4163 | |
| 4164 | // We're in a context where 'yield expr' is not allowed. However, if we can |
| 4165 | // definitely tell that the user was trying to parse a 'yield expr' and not |
| 4166 | // just a normal expr that start with a 'yield' identifier, then parse out |
| 4167 | // a 'yield expr'. We can then report an error later that they are only |
| 4168 | // allowed in generator expressions. |
| 4169 | // |
| 4170 | // for example, if we see 'yield(foo)', then we'll have to treat that as an |
| 4171 | // invocation expression of something called 'yield'. However, if we have |
| 4172 | // 'yield foo' then that is not legal as a normal expression, so we can |
| 4173 | // definitely recognize this as a yield expression. |
| 4174 | // |
| 4175 | // for now we just check if the next token is an identifier. More heuristics |
| 4176 | // can be added here later as necessary. We just need to make sure that we |
| 4177 | // don't accidentally consume something legal. |
| 4178 | return p.lookAhead((*Parser).nextTokenIsIdentifierOrKeywordOrLiteralOnSameLine) |
| 4179 | } |
| 4180 | return false |
| 4181 | } |
| 4182 | |
| 4183 | func (p *Parser) parseYieldExpression() *ast.Node { |
| 4184 | pos := p.nodePos() |
no test coverage detected