parseRelationStatement method parses a RELATION statement and returns a RelationStatement AST node
(entityName string)
| 455 | |
| 456 | // parseRelationStatement method parses a RELATION statement and returns a RelationStatement AST node |
| 457 | func (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 |
| 497 | func (p *Parser) parseRelationTypeStatement() (*ast.RelationTypeStatement, error) { |
no test coverage detected