MCPcopy Create free account
hub / github.com/Script-Hub-Org/Script-Hub / parseExpression

Method parseExpression

Rewrite-Parser.js:2682–2811  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2680 }
2681
2682 parseExpression() {
2683 const token = this.peek()
2684 // console.log(`Parsing expression at position ${this.position}: ${token ? token.value : 'EOF'}`)
2685
2686 if (!token) {
2687 throw new Error('意外的输入结束')
2688 }
2689
2690 if (token.type === 'LPAREN') {
2691 this.consume() // 消费 '('
2692 const exprList = this.parseExpressionList()
2693 this.expect('RPAREN') // 消费 ')'
2694
2695 // 如果表达式列表只有一个元素,返回该元素,否则返回列表
2696 if (exprList.length === 1) {
2697 return exprList[0]
2698 } else {
2699 return exprList
2700 }
2701 } else if (token.type === 'WORD') {
2702 const operator = this.consume().value.toUpperCase()
2703
2704 // 检查是否是逻辑运算符
2705 if (operator in this.LOGICAL_OPERATORS) {
2706 const node = { operator, type: 'LOGICAL', children: [] }
2707
2708 // 消费逗号
2709 this.expect('COMMA')
2710
2711 // 解析参数列表
2712 while (true) {
2713 const arg = this.parseExpression()
2714 node.children.push(arg)
2715
2716 const nextToken = this.peek()
2717 if (nextToken && nextToken.type === 'COMMA') {
2718 // 前瞻检查逗号后是否为匹配参数或路由策略
2719 if (
2720 this.peek(1) &&
2721 this.peek(1).type === 'WORD' &&
2722 (this.ROUTING_POLICIES.includes(this.peek(1).value.toUpperCase()) ||
2723 this.isMatchingParameter(this.peek(1).value))
2724 ) {
2725 break
2726 } else {
2727 this.consume()
2728 }
2729 } else {
2730 break
2731 }
2732 }
2733
2734 // 处理匹配参数或路由策略
2735 while (this.peek() && this.peek().type === 'COMMA') {
2736 this.consume()
2737 const paramToken = this.consume()
2738 const paramName = paramToken.value.toLowerCase()
2739

Callers 2

parseMethod · 0.95
parseExpressionListMethod · 0.95

Calls 6

peekMethod · 0.95
consumeMethod · 0.95
parseExpressionListMethod · 0.95
expectMethod · 0.95
isMatchingParameterMethod · 0.95
collectValueMethod · 0.95

Tested by

no test coverage detected