| 2653 | } |
| 2654 | |
| 2655 | parse() { |
| 2656 | // console.log('=== 开始语法分析 ===') |
| 2657 | if (this.tokens.length === 0) { |
| 2658 | throw new Error('输入为空') |
| 2659 | } |
| 2660 | const expr = this.parseExpression() |
| 2661 | |
| 2662 | // 检查是否有剩余的路由策略 |
| 2663 | if (this.position < this.tokens.length) { |
| 2664 | const remainingTokens = this.tokens.slice(this.position) |
| 2665 | if ( |
| 2666 | remainingTokens.length >= 2 && |
| 2667 | remainingTokens[0].type === 'COMMA' && |
| 2668 | this.ROUTING_POLICIES.includes(remainingTokens[1].value.toUpperCase()) |
| 2669 | ) { |
| 2670 | this.consume() // 消费逗号 |
| 2671 | const routingPolicyToken = this.consume() |
| 2672 | expr.routingPolicy = routingPolicyToken.value.toUpperCase() |
| 2673 | } else { |
| 2674 | throw new Error(`意外的令牌 '${this.peek().value}' 在位置 ${this.position}`) |
| 2675 | } |
| 2676 | } |
| 2677 | |
| 2678 | // console.log('=== 语法分析完成 ===') |
| 2679 | return expr |
| 2680 | } |
| 2681 | |
| 2682 | parseExpression() { |
| 2683 | const token = this.peek() |