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

Method parseRelationStatement

pkg/dsl/parser/parser.go:457–494  ·  view source on GitHub ↗

parseRelationStatement method parses a RELATION statement and returns a RelationStatement AST node

(entityName string)

Source from the content-addressed store, hash-verified

455
456// parseRelationStatement method parses a RELATION statement and returns a RelationStatement AST node
457func (p *Parser) parseRelationStatement(entityName string) (*ast.RelationStatement, error) {
458 // create a new RelationStatement object and set its Relation field to the currentToken
459 stmt := &ast.RelationStatement{Relation: p.currentToken}
460
461 // expect the next token to be an identifier token, and set the RelationStatement's Name field to the identifier's value
462 if !p.expectAndNext(token.IDENT) {
463 return nil, p.Error()
464 }
465 stmt.Name = p.currentToken
466 relationName := stmt.Name.Literal
467
468 // expect the next token to be a SIGN token, indicating the start of the relation type(s)
469 if !p.expect(token.SIGN) {
470 return nil, p.Error()
471 }
472
473 // loop through the relation types until no more SIGN tokens are encountered
474 for p.peekTokenIs(token.SIGN) {
475 // parse a RelationTypeStatement and append it to the RelationStatement's RelationTypes field
476 relationStatement, err := p.parseRelationTypeStatement()
477 if err != nil {
478 return nil, p.Error()
479 }
480 stmt.RelationTypes = append(stmt.RelationTypes, *relationStatement)
481 }
482
483 key := utils.Key(entityName, relationName)
484
485 // add the relation reference to the Parser's relationReferences and relationalReferences maps
486 err := p.references.AddRelationReferences(key, stmt.RelationTypes)
487 if err != nil {
488 p.duplicationError(key) // Generate an error message indicating a duplication error
489 return nil, p.Error()
490 }
491
492 // return the parsed RelationStatement and nil for the error value
493 return stmt, nil
494}
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) {

Callers 2

parsePartialStatementMethod · 0.95
parseEntityStatementMethod · 0.95

Calls 8

expectAndNextMethod · 0.95
ErrorMethod · 0.95
expectMethod · 0.95
peekTokenIsMethod · 0.95
duplicationErrorMethod · 0.95
KeyFunction · 0.92
AddRelationReferencesMethod · 0.80

Tested by

no test coverage detected