MCPcopy Create free account
hub / github.com/cel-expr/cel-go / isStructCreationAhead

Method isStructCreationAhead

parser/pratt_parser.go:220–244  ·  view source on GitHub ↗

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

()

Source from the content-addressed store, hash-verified

218// Unlike standalone identifiers or selector chains, reserved identifiers (e.g. `import{}` or `import.Foo{}`)
219// are permitted in message type names.
220func (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
246func (p *prattParserWorker) nextToken() token {
247 p.currTok = p.peekTok

Callers 1

parseIdentOrCallMethod · 0.95

Calls 4

tokenTextMethod · 0.95
SavePositionMethod · 0.80
RestorePositionMethod · 0.80

Tested by

no test coverage detected