()
| 180 | } |
| 181 | |
| 182 | func (p *Parser) parseSliceExpression() (ASTNode, error) { |
| 183 | parts := []*int{nil, nil, nil} |
| 184 | index := 0 |
| 185 | current := p.current() |
| 186 | for current != tRbracket && index < 3 { |
| 187 | if current == tColon { |
| 188 | index++ |
| 189 | p.advance() |
| 190 | } else if current == tNumber { |
| 191 | parsedInt, err := strconv.Atoi(p.lookaheadToken(0).value) |
| 192 | if err != nil { |
| 193 | return ASTNode{}, err |
| 194 | } |
| 195 | parts[index] = &parsedInt |
| 196 | p.advance() |
| 197 | } else { |
| 198 | return ASTNode{}, p.syntaxError( |
| 199 | "Expected tColon or tNumber" + ", received: " + p.current().String()) |
| 200 | } |
| 201 | current = p.current() |
| 202 | } |
| 203 | if err := p.match(tRbracket); err != nil { |
| 204 | return ASTNode{}, err |
| 205 | } |
| 206 | return ASTNode{ |
| 207 | nodeType: ASTSlice, |
| 208 | value: parts, |
| 209 | }, nil |
| 210 | } |
| 211 | |
| 212 | func (p *Parser) match(tokenType tokType) error { |
| 213 | if p.current() == tokenType { |
no test coverage detected