isStructCreationAhead checks whether the current identifier is the root of a struct/message creation expression (`CreateMessage` in grammar: `'.'? IDENTIFIER ('.' IDENTIFIER)* '{' ... '}'`). Unlike standalone identifiers or selector chains, reserved identifiers (e.g. `import{}` or `import.Foo{}`) ar
()
| 218 | // Unlike standalone identifiers or selector chains, reserved identifiers (e.g. `import{}` or `import.Foo{}`) |
| 219 | // are permitted in message type names. |
| 220 | func (p *prattParserWorker) isStructCreationAhead() bool { |
| 221 | if p.peekTok.kind == tokLeftBrace { |
| 222 | return true |
| 223 | } |
| 224 | if p.peekTok.kind != tokDot { |
| 225 | return false |
| 226 | } |
| 227 | savedPos := p.lexer.SavePosition() |
| 228 | defer p.lexer.RestorePosition(savedPos) |
| 229 | |
| 230 | tok := p.peekTok |
| 231 | for tok.kind == tokDot { |
| 232 | tok = p.scanNextSignificantToken() |
| 233 | if tok.kind != tokIdent && tok.kind != tokReservedWord { |
| 234 | return false |
| 235 | } |
| 236 | // Quoted identifiers are not allowed in struct creation expressions. |
| 237 | text := p.tokenText(tok) |
| 238 | if len(text) > 0 && text[0] == '`' { |
| 239 | return false |
| 240 | } |
| 241 | tok = p.scanNextSignificantToken() |
| 242 | } |
| 243 | return tok.kind == tokLeftBrace |
| 244 | } |
| 245 | |
| 246 | func (p *prattParserWorker) nextToken() token { |
| 247 | p.currTok = p.peekTok |
no test coverage detected