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

Method parseRelationTypeStatement

pkg/dsl/parser/parser.go:497–522  ·  view source on GitHub ↗

parseRelationTypeStatement method parses a single relation type within a RELATION statement and returns a RelationTypeStatement AST node

()

Source from the content-addressed store, hash-verified

495
496// parseRelationTypeStatement method parses a single relation type within a RELATION statement and returns a RelationTypeStatement AST node
497func (p *Parser) parseRelationTypeStatement() (*ast.RelationTypeStatement, error) {
498 // expect the currentToken to be a SIGN token, indicating the start of the relation type
499 if !p.expectAndNext(token.SIGN) {
500 return nil, p.Error()
501 }
502 // create a new RelationTypeStatement object and set its Sign field to the SIGN token
503 stmt := &ast.RelationTypeStatement{Sign: p.currentToken}
504
505 // expect the next token to be an identifier token, and set the RelationTypeStatement's Type field to the identifier's value
506 if !p.expectAndNext(token.IDENT) {
507 return nil, p.Error()
508 }
509 stmt.Type = p.currentToken
510
511 // if the next token is a HASH token, indicating that a specific relation within the relation type is being referenced, parse it and set the RelationTypeStatement's Relation field to the identifier's value
512 if p.peekTokenIs(token.HASH) {
513 p.next()
514 if !p.expectAndNext(token.IDENT) {
515 return nil, p.Error()
516 }
517 stmt.Relation = p.currentToken
518 }
519
520 // return the parsed RelationTypeStatement and nil for the error value
521 return stmt, nil
522}
523
524// parsePermissionStatement method parses an PERMISSION statement and returns an PermissionStatement AST node
525func (p *Parser) parsePermissionStatement(entityName string) (ast.Statement, error) {

Callers 1

Calls 4

expectAndNextMethod · 0.95
ErrorMethod · 0.95
peekTokenIsMethod · 0.95
nextMethod · 0.95

Tested by

no test coverage detected