expect method checks if the next token is of the expected type, without advancing the lexer. It returns true if the next token is of the expected type, and false otherwise.
(t token.Type)
| 587 | |
| 588 | // expect method checks if the next token is of the expected type, without advancing the lexer. It returns true if the next token is of the expected type, and false otherwise. |
| 589 | func (p *Parser) expect(t token.Type) bool { |
| 590 | // if the next token is of the expected type, return true |
| 591 | if p.peekTokenIs(t) { |
| 592 | return true |
| 593 | } |
| 594 | // otherwise, generate an error message indicating that the expected token type was not found and return false |
| 595 | p.peekError(t) |
| 596 | return false |
| 597 | } |
| 598 | |
| 599 | // parseExpression method parses an expression with a given precedence level and returns the parsed expression as an AST node. It takes an integer value indicating the precedence level. |
| 600 | func (p *Parser) parseExpression(precedence int) (ast.Expression, error) { |
no test coverage detected