next retrieves the next non-ignored token from the Parser's lexer and updates the Parser's currentToken and peekToken fields
()
| 79 | |
| 80 | // next retrieves the next non-ignored token from the Parser's lexer and updates the Parser's currentToken and peekToken fields |
| 81 | func (p *Parser) next() { |
| 82 | for { |
| 83 | // retrieve the next token from the lexer |
| 84 | peek := p.l.NextToken() |
| 85 | // if the token is not an ignored token (e.g. whitespace or comments), update the currentToken and peekToken fields and exit the loop |
| 86 | if !token.IsIgnores(peek.Type) { |
| 87 | // store the current token as previous before advancing |
| 88 | p.previousToken = p.currentToken // save current token for lookahead |
| 89 | // set the currentToken field to the previous peekToken value |
| 90 | p.currentToken = p.peekToken |
| 91 | // set the peekToken field to the new peek value |
| 92 | p.peekToken = peek |
| 93 | // exit the loop |
| 94 | break |
| 95 | } |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | // nextWithIgnores advances the parser's token stream by one position. |
| 100 | // It updates the currentToken and peekToken of the Parser. |
no test coverage detected