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

Method parseExpression

Rewrite-Parser.beta.js:3094–3223  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

3092 }
3093
3094 parseExpression() {
3095 const token = this.peek()
3096 // console.log(`Parsing expression at position ${this.position}: ${token ? token.value : 'EOF'}`)
3097
3098 if (!token) {
3099 throw new Error('意外的输入结束')
3100 }
3101
3102 if (token.type === 'LPAREN') {
3103 this.consume() // 消费 '('
3104 const exprList = this.parseExpressionList()
3105 this.expect('RPAREN') // 消费 ')'
3106
3107 // 如果表达式列表只有一个元素,返回该元素,否则返回列表
3108 if (exprList.length === 1) {
3109 return exprList[0]
3110 } else {
3111 return exprList
3112 }
3113 } else if (token.type === 'WORD') {
3114 const operator = this.consume().value.toUpperCase()
3115
3116 // 检查是否是逻辑运算符
3117 if (operator in this.LOGICAL_OPERATORS) {
3118 const node = { operator, type: 'LOGICAL', children: [] }
3119
3120 // 消费逗号
3121 this.expect('COMMA')
3122
3123 // 解析参数列表
3124 while (true) {
3125 const arg = this.parseExpression()
3126 node.children.push(arg)
3127
3128 const nextToken = this.peek()
3129 if (nextToken && nextToken.type === 'COMMA') {
3130 // 前瞻检查逗号后是否为匹配参数或路由策略
3131 if (
3132 this.peek(1) &&
3133 this.peek(1).type === 'WORD' &&
3134 (this.ROUTING_POLICIES.includes(this.peek(1).value.toUpperCase()) ||
3135 this.isMatchingParameter(this.peek(1).value))
3136 ) {
3137 break
3138 } else {
3139 this.consume()
3140 }
3141 } else {
3142 break
3143 }
3144 }
3145
3146 // 处理匹配参数或路由策略
3147 while (this.peek() && this.peek().type === 'COMMA') {
3148 this.consume()
3149 const paramToken = this.consume()
3150 const paramName = paramToken.value.toLowerCase()
3151

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