diff options
author | jaby <peter.de.velder@ilias-solutions.com> | 2021-12-10 09:48:02 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-10 16:48:02 +0800 |
commit | b33e39369aa3898d2f6e079240545f9d84abec73 (patch) | |
tree | 6ba844451416c6a5407b1411d0ff3143038563b9 /calc.go | |
parent | 1b3040659d3155732961c45b0c2e13e39e0b2576 (diff) |
This closes #1090 (#1092)
Keep track of operators per function
Diffstat (limited to 'calc.go')
-rw-r--r-- | calc.go | 10 |
1 files changed, 6 insertions, 4 deletions
@@ -726,6 +726,7 @@ func (f *File) evalInfixExp(sheet, cell string, tokens []efp.Token) (efp.Token, if isFunctionStartToken(token) { opfStack.Push(token) argsStack.Push(list.New().Init()) + opftStack.Push(token) // to know which operators belong to a function use the function as a separator continue } @@ -738,7 +739,7 @@ func (f *File) evalInfixExp(sheet, cell string, tokens []efp.Token) (efp.Token, // current token is args or range, skip next token, order required: parse reference first if token.TSubType == efp.TokenSubTypeRange { - if !opftStack.Empty() { + if opftStack.Peek().(efp.Token) != opfStack.Peek().(efp.Token) { refTo := f.getDefinedNameRefTo(token.TValue, sheet) if refTo != "" { token.TValue = refTo @@ -783,7 +784,7 @@ func (f *File) evalInfixExp(sheet, cell string, tokens []efp.Token) (efp.Token, // current token is arg if token.TType == efp.TokenTypeArgument { - for !opftStack.Empty() { + for opftStack.Peek().(efp.Token) != opfStack.Peek().(efp.Token) { // calculate trigger topOpt := opftStack.Peek().(efp.Token) if err := calculate(opfdStack, topOpt); err != nil { @@ -826,7 +827,7 @@ func (f *File) evalInfixExpFunc(sheet, cell string, token, nextToken efp.Token, return nil } // current token is function stop - for !opftStack.Empty() { + for opftStack.Peek().(efp.Token) != opfStack.Peek().(efp.Token) { // calculate trigger topOpt := opftStack.Peek().(efp.Token) if err := calculate(opfdStack, topOpt); err != nil { @@ -847,9 +848,10 @@ func (f *File) evalInfixExpFunc(sheet, cell string, token, nextToken efp.Token, return errors.New(arg.Value()) } argsStack.Pop() + opftStack.Pop() // remove current function separator opfStack.Pop() if opfStack.Len() > 0 { // still in function stack - if nextToken.TType == efp.TokenTypeOperatorInfix { + if nextToken.TType == efp.TokenTypeOperatorInfix || opftStack.Len() > 1 { // mathematics calculate in formula function opfdStack.Push(efp.Token{TValue: arg.Value(), TType: efp.TokenTypeOperand, TSubType: efp.TokenSubTypeNumber}) } else { |