expect returns the next token if it matches the expectation t, and nil otherwise.
(t tokenizer.TokenType)
| 124 | // expect returns the next token if it matches the expectation t, and |
| 125 | // nil otherwise. |
| 126 | func (p *parser) expect(t tokenizer.TokenType) *tokenizer.Token { |
| 127 | p.expected = t |
| 128 | |
| 129 | if p.current == nil { |
| 130 | p.current = p.tokenizer.Next() |
| 131 | } |
| 132 | |
| 133 | if p.current != nil && p.current.Type == t { |
| 134 | tok := p.current |
| 135 | p.current = nil |
| 136 | return tok |
| 137 | } |
| 138 | |
| 139 | return nil |
| 140 | } |