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