parsePrimaryExpression parses literals and parenthesized expressions
()
| 240 | |
| 241 | // parsePrimaryExpression parses literals and parenthesized expressions |
| 242 | func (p *ExpressionParser) parsePrimaryExpression() (ConditionNode, error) { |
| 243 | if expressionsLog.Enabled() { |
| 244 | expressionsLog.Printf("Parsing primary expression at token: %s", p.current().value) |
| 245 | } |
| 246 | switch p.current().kind { |
| 247 | case tokenLeftParen: |
| 248 | p.advance() // consume ( |
| 249 | expr, err := p.parseOrExpression() |
| 250 | if err != nil { |
| 251 | return nil, err |
| 252 | } |
| 253 | if p.current().kind != tokenRightParen { |
| 254 | return nil, fmt.Errorf("expected ')' at position %d", p.current().pos) |
| 255 | } |
| 256 | p.advance() // consume ) |
| 257 | return expr, nil |
| 258 | |
| 259 | case tokenLiteral: |
| 260 | literal := p.current().value |
| 261 | p.advance() |
| 262 | return &ExpressionNode{Expression: literal}, nil |
| 263 | |
| 264 | default: |
| 265 | return nil, fmt.Errorf("unexpected token '%s' at position %d", p.current().value, p.current().pos) |
| 266 | } |
| 267 | } |
| 268 | |
| 269 | // current returns the current token |
| 270 | func (p *ExpressionParser) current() token { |
no test coverage detected