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

Method normalizeIdent

parser/pratt_parser.go:401–443  ·  view source on GitHub ↗
(tok token, allowQuoted bool, isQuoted *bool)

Source from the content-addressed store, hash-verified

399}
400
401func (p *prattParserWorker) normalizeIdent(tok token, allowQuoted bool, isQuoted *bool) string {
402 if isQuoted != nil {
403 *isQuoted = false
404 }
405 text := p.tokenText(tok)
406 if len(text) == 0 {
407 return ""
408 }
409 if text[0] == '`' {
410 if isQuoted != nil {
411 *isQuoted = true
412 }
413 if !allowQuoted {
414 p.reportError(tok, "unexpected quoted identifier")
415 return ""
416 }
417 if !p.enableIdentEscapeSyntax {
418 p.reportError(tok, "unsupported syntax: '`'")
419 }
420 if len(text) < 2 || text[len(text)-1] != '`' {
421 p.reportError(tok, "unterminated quoted identifier")
422 return ""
423 }
424 // Validate the quoted identifier syntax:
425 // ESC_IDENTIFIER : '`' (LETTER | DIGIT | '_' | '.' | '-' | '/' | ' ')+ '`';
426 inner := text[1 : len(text)-1]
427 if len(inner) == 0 {
428 p.reportError(tok, "unexpected quoted identifier")
429 return ""
430 }
431 for _, c := range inner {
432 if !isAlpha(c) && !isDigit(c) && c != '_' && c != '.' && c != '-' && c != '/' && c != ' ' {
433 if c == '@' && p.enableCallEscapeSyntax {
434 continue
435 }
436 p.reportError(tok, "unexpected quoted identifier")
437 return ""
438 }
439 }
440 return inner
441 }
442 return text
443}
444
445func (p *prattParserWorker) parse() ast.Expr {
446 expr := p.parseExpr()

Callers 3

parseStructMethod · 0.95
parseIdentOrCallMethod · 0.95

Calls 4

tokenTextMethod · 0.95
reportErrorMethod · 0.95
isAlphaFunction · 0.70
isDigitFunction · 0.70

Tested by

no test coverage detected