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

Method parseAttributeStatement

pkg/dsl/parser/parser.go:417–454  ·  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

415
416// parseRelationStatement method parses a RELATION statement and returns a RelationStatement AST node
417func (p *Parser) parseAttributeStatement(entityName string) (*ast.AttributeStatement, error) {
418 // create a new RelationStatement object and set its Relation field to the currentToken
419 stmt := &ast.AttributeStatement{Attribute: p.currentToken}
420
421 // expect the next token to be an identifier token, and set the RelationStatement's Name field to the identifier's value
422 if !p.expectAndNext(token.IDENT) {
423 return nil, p.Error()
424 }
425 stmt.Name = p.currentToken
426
427 if !p.expectAndNext(token.IDENT) {
428 return nil, p.Error()
429 }
430
431 atstmt := ast.AttributeTypeStatement{Type: p.currentToken}
432 atstmt.IsArray = false
433
434 if p.peekTokenIs(token.LSB) {
435 p.next()
436 if !p.expectAndNext(token.RSB) {
437 return nil, p.Error()
438 }
439 atstmt.IsArray = true
440 }
441
442 stmt.AttributeType = atstmt
443
444 key := utils.Key(entityName, stmt.Name.Literal)
445 // add the relation reference to the Parser's relationReferences and relationalReferences maps
446 err := p.references.AddAttributeReferences(key, atstmt)
447 if err != nil {
448 p.duplicationError(key) // Generate an error message indicating a duplication error
449 return nil, p.Error()
450 }
451
452 // return the parsed RelationStatement and nil for the error value
453 return stmt, nil
454}
455
456// parseRelationStatement method parses a RELATION statement and returns a RelationStatement AST node
457func (p *Parser) parseRelationStatement(entityName string) (*ast.RelationStatement, error) {

Callers 2

parsePartialStatementMethod · 0.95
parseEntityStatementMethod · 0.95

Calls 7

expectAndNextMethod · 0.95
ErrorMethod · 0.95
peekTokenIsMethod · 0.95
nextMethod · 0.95
duplicationErrorMethod · 0.95
KeyFunction · 0.92

Tested by

no test coverage detected