MCPcopy Create free account
hub / github.com/ForestHubAI/edge-agents / parseAddSub

Method parseAddSub

go/engine/expr/parser.go:158–188  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

156}
157
158func (p *parser) parseAddSub() (Value, error) {
159 left, err := p.parseMulDiv()
160 if err != nil {
161 return Value{}, err
162 }
163 for {
164 ch := p.peek()
165 if ch != '+' && ch != '-' {
166 break
167 }
168 p.pos++
169 right, err := p.parseMulDiv()
170 if err != nil {
171 return Value{}, err
172 }
173 if left.Type == workflowapi.Float || right.Type == workflowapi.Float {
174 if ch == '+' {
175 left = FloatVal(left.AsFloat() + right.AsFloat())
176 } else {
177 left = FloatVal(left.AsFloat() - right.AsFloat())
178 }
179 } else {
180 if ch == '+' {
181 left = IntVal(left.AsInt() + right.AsInt())
182 } else {
183 left = IntVal(left.AsInt() - right.AsInt())
184 }
185 }
186 }
187 return left, nil
188}
189
190func (p *parser) parseMulDiv() (Value, error) {
191 left, err := p.parseUnary()

Callers 1

parseComparisonMethod · 0.95

Calls 6

parseMulDivMethod · 0.95
peekMethod · 0.95
FloatValFunction · 0.85
IntValFunction · 0.85
AsFloatMethod · 0.80
AsIntMethod · 0.80

Tested by

no test coverage detected