parsePermissionStatement method parses an PERMISSION statement and returns an PermissionStatement AST node
(entityName string)
| 523 | |
| 524 | // parsePermissionStatement method parses an PERMISSION statement and returns an PermissionStatement AST node |
| 525 | func (p *Parser) parsePermissionStatement(entityName string) (ast.Statement, error) { |
| 526 | // create a new PermissionStatement object and set its Permission field to the currentToken |
| 527 | stmt := &ast.PermissionStatement{Permission: p.currentToken} |
| 528 | |
| 529 | // expect the next token to be an identifier token, and set the PermissionStatement's Name field to the identifier's value |
| 530 | if !p.expectAndNext(token.IDENT) { |
| 531 | return nil, p.Error() |
| 532 | } |
| 533 | stmt.Name = p.currentToken |
| 534 | |
| 535 | key := utils.Key(entityName, stmt.Name.Literal) |
| 536 | // add the action reference to the Parser's actionReferences and relationalReferences maps |
| 537 | err := p.references.AddPermissionReference(key) |
| 538 | if err != nil { |
| 539 | p.duplicationError(key) // Generate an error message indicating a duplication error |
| 540 | return nil, p.Error() |
| 541 | } |
| 542 | |
| 543 | // expect the next token to be an ASSIGN token, indicating the start of the expression to be assigned to the action |
| 544 | if !p.expectAndNext(token.ASSIGN) { |
| 545 | return nil, p.Error() |
| 546 | } |
| 547 | |
| 548 | p.next() |
| 549 | |
| 550 | // parse the expression statement and set it as the PermissionStatement's ExpressionStatement field |
| 551 | ex, err := p.parseExpressionStatement() |
| 552 | if err != nil { |
| 553 | return nil, p.Error() |
| 554 | } |
| 555 | stmt.ExpressionStatement = ex |
| 556 | |
| 557 | // return the parsed PermissionStatement and nil for the error value |
| 558 | return stmt, nil |
| 559 | } |
| 560 | |
| 561 | // parseExpressionStatement method parses an expression statement and returns an ExpressionStatement AST node |
| 562 | func (p *Parser) parseExpressionStatement() (*ast.ExpressionStatement, error) { |
no test coverage detected