()
| 3065 | } |
| 3066 | |
| 3067 | parse() { |
| 3068 | // console.log('=== 开始语法分析 ===') |
| 3069 | if (this.tokens.length === 0) { |
| 3070 | throw new Error('输入为空') |
| 3071 | } |
| 3072 | const expr = this.parseExpression() |
| 3073 | |
| 3074 | // 检查是否有剩余的路由策略 |
| 3075 | if (this.position < this.tokens.length) { |
| 3076 | const remainingTokens = this.tokens.slice(this.position) |
| 3077 | if ( |
| 3078 | remainingTokens.length >= 2 && |
| 3079 | remainingTokens[0].type === 'COMMA' && |
| 3080 | this.ROUTING_POLICIES.includes(remainingTokens[1].value.toUpperCase()) |
| 3081 | ) { |
| 3082 | this.consume() // 消费逗号 |
| 3083 | const routingPolicyToken = this.consume() |
| 3084 | expr.routingPolicy = routingPolicyToken.value.toUpperCase() |
| 3085 | } else { |
| 3086 | throw new Error(`意外的令牌 '${this.peek().value}' 在位置 ${this.position}`) |
| 3087 | } |
| 3088 | } |
| 3089 | |
| 3090 | // console.log('=== 语法分析完成 ===') |
| 3091 | return expr |
| 3092 | } |
| 3093 | |
| 3094 | parseExpression() { |
| 3095 | const token = this.peek() |
no test coverage detected