MCPcopy Create free account
hub / github.com/Permify/permify / parseIdentifierExpression

Method parseIdentifierExpression

pkg/dsl/parser/parser.go:733–757  ·  view source on GitHub ↗

parseIdentifier parses an identifier expression that may consist of one or more dot-separated identifiers, such as "x", "foo.bar", or "a.b.c.d". It constructs a new Identifier expression with the first token as the prefix and subsequent tokens as identifiers, and returns the resulting expression and

()

Source from the content-addressed store, hash-verified

731// It constructs a new Identifier expression with the first token as the prefix and subsequent
732// tokens as identifiers, and returns the resulting expression and any error encountered.
733func (p *Parser) parseIdentifierExpression() (ast.Expression, error) {
734 // Ensure the current token is a valid identifier before proceeding.
735 if !p.currentTokenIs(token.IDENT) {
736 p.currentError(token.IDENT)
737 return nil, p.Error()
738 }
739
740 // Create a new Identifier expression with the first token as the prefix.
741 ident := &ast.Identifier{Idents: []token.Token{p.currentToken}}
742
743 // If the next token is a dot, consume it and continue parsing the next identifier.
744 for p.peekTokenIs(token.DOT) {
745 p.next() // Consume the dot token
746
747 // Check if the next token after the dot is a valid identifier
748 if !p.expectAndNext(token.IDENT) {
749 return nil, p.Error()
750 }
751
752 ident.Idents = append(ident.Idents, p.currentToken)
753 }
754
755 // Return the resulting Identifier expression.
756 return ident, nil
757}
758
759// call_func(variable1, variable2)
760func (p *Parser) parseCallExpression() (ast.Expression, error) {

Callers 2

parseIdentifierOrCallMethod · 0.95
parseCallExpressionMethod · 0.95

Calls 6

currentTokenIsMethod · 0.95
currentErrorMethod · 0.95
ErrorMethod · 0.95
peekTokenIsMethod · 0.95
nextMethod · 0.95
expectAndNextMethod · 0.95

Tested by

no test coverage detected