Skip to content

Commit 561989d

Browse files
committed
v3.2.3
1 parent bd209ce commit 561989d

File tree

2 files changed

+337
-114
lines changed

2 files changed

+337
-114
lines changed

src/LO Basic/VBAExpressionsLib/VBAexpressions.xba

Lines changed: 168 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -2171,7 +2171,7 @@ Private Function Compute() As String
21712171
If Not EvalTree(B).CompArrCluster Then 'Function Argument
21722172
EvalTree(B).EvalResult = Join$(tmpResult, P_SEPARATORCHAR)
21732173
Else 'Array function Argument
2174-
EvalTree(B).EvalResult = JoinArrFunctArg(tmpResult, EvalTree(B).ClusterArrBounds(0), EvalTree(B).ClusterArrBounds(1))
2174+
EvalTree(B).EvalResult = JoinArrFunctArg(tmpResult, EvalTree(B).ClusterArrBounds)
21752175
End If
21762176
End If
21772177
Next B
@@ -2959,6 +2959,22 @@ Private Sub ExpandCBbuffer(ByRef aBuffer As ClusterBuffer)
29592959
aBuffer.Storage = tmpBuffer
29602960
End Sub
29612961

2962+
Private Sub ExpandCompositeArg(ByRef outBuffer As ClusterTree, ByRef tmpReplacement As String, _
2963+
ByRef ExpCopy As String, ByRef tmpArgs() As String, _
2964+
ByRef taIcounter As Long, ByRef OperationIndex As Long)
2965+
outBuffer.ClusterArrBounds = SplitArrBranch(ExpCopy, tmpArgs)
2966+
If outBuffer.ClusterArrBounds(0) <> -1 Then 'Splitting argument success
2967+
For taIcounter = LBound(tmpArgs) To UBound(tmpArgs)
2968+
GetRootedTree tmpArgs(taIcounter), tmpReplacement, OperationIndex, outBuffer
2969+
AddToMap outBuffer.aindex, outBuffer
2970+
Next taIcounter
2971+
outBuffer.CompCluster = True
2972+
outBuffer.CompArrCluster = True
2973+
Else
2974+
'Todo: Code here for trap error of missing {} in a composite array input
2975+
End If
2976+
End Sub
2977+
29622978
Private Function ExpEuler(ByRef expression As String, ByRef fName As String) As String
29632979
On Error GoTo err_Handler
29642980
ExpEuler = CStr(Exp(CDbl(expression)))
@@ -3198,10 +3214,12 @@ End Function
31983214

31993215
Private Function FormatEntry(expression As String) As String
32003216
FormatEntry = ReplaceImpliedMult( _
3201-
Replace(Replace(Replace(RemoveDupNegation(ApplyLawOfSigns _
3202-
(ReconstructLiteralStrings(CStr(expression), _
3203-
Join(Split(expression, d_Space), vbNullString)))), "()", "('')"), "{{", "({{"), "}}", "}})") _
3204-
)
3217+
Replace( _
3218+
RemoveDupNegation( _
3219+
ApplyLawOfSigns( _
3220+
ReconstructLiteralStrings( _
3221+
expression, Join$(Split(expression, d_Space), vbNullString)))), _
3222+
"()", "('')"))
32053223
End Function
32063224

32073225
Private Function FormatLiteralString(ByRef aString As String, _
@@ -5330,30 +5348,78 @@ err_Handler:
53305348
err.Clear
53315349
End Function
53325350

5333-
Private Function JoinArrFunctArg(ByRef DecompArray() As String, ByRef MaxRowIndex As Long, ByRef MaxColIndex As Long) As String
5351+
Private Function JoinArrFunctArg(ByRef DecompArray() As String, ByRef MapedIdx() As Long) As String
53345352
Dim tmpResult As String
5353+
Dim tmpArray As String
5354+
Dim MaxRowIndex As Long
5355+
Dim MaxColIndex As Long
53355356
Dim i As Long, j As Long
5336-
5337-
If MaxColIndex > -1 Then
5338-
For i = 0 To MaxRowIndex
5339-
For j = 0 To MaxColIndex
5340-
If j = 0 Then
5341-
tmpResult = tmpResult & d_lCurly & DecompArray(j + (i * (MaxColIndex + 1)))
5357+
Dim k As Long
5358+
Dim UB As Long
5359+
Dim wIdx As Long
5360+
5361+
UB = UBound(MapedIdx)
5362+
For k = LBound(MapedIdx) To UB
5363+
If MapedIdx(k) <> -2 Then
5364+
MaxRowIndex = MapedIdx(k)
5365+
If MapedIdx(k + 1) <> -3 Then '2D Array
5366+
MaxColIndex = MapedIdx(k + 1)
5367+
Else 'Vector
5368+
MaxColIndex = 0
5369+
End If
5370+
tmpArray = vbNullString
5371+
For i = 0 To MaxRowIndex
5372+
If MapedIdx(k + 1) <> -3 And MaxColIndex > 0 Then
5373+
For j = 0 To MaxColIndex
5374+
If j = 0 Then
5375+
tmpArray = tmpArray & d_lCurly & _
5376+
DecompArray(j + (i * (MaxColIndex + 1)) + wIdx)
5377+
Else
5378+
tmpArray = tmpArray & P_SEPARATORCHAR & DecompArray(j + (i * (MaxColIndex + 1)) + wIdx)
5379+
End If
5380+
If j = MaxColIndex Then
5381+
tmpArray = tmpArray & d_rCurly
5382+
End If
5383+
Next j
53425384
Else
5343-
tmpResult = tmpResult & P_SEPARATORCHAR & DecompArray(j + (i * (MaxColIndex + 1)))
5385+
If i = 0 Then
5386+
tmpArray = tmpArray & d_lCurly & DecompArray((i * (MaxColIndex + 1)) + wIdx)
5387+
Else
5388+
tmpArray = tmpArray & DecompArray((i * (MaxColIndex + 1)) + wIdx)
5389+
End If
5390+
If i = MaxRowIndex Then
5391+
tmpArray = tmpArray & d_rCurly
5392+
End If
53445393
End If
5345-
If j = MaxColIndex Then
5346-
tmpResult = tmpResult & d_rCurly
5394+
If i < MaxRowIndex Then
5395+
tmpArray = tmpArray & P_SEPARATORCHAR
53475396
End If
5348-
Next j
5349-
If i < MaxRowIndex Then
5350-
tmpResult = tmpResult & P_SEPARATORCHAR
5397+
Next i
5398+
If MapedIdx(k + 1) <> -3 Then
5399+
tmpArray = d_lCurly & tmpArray & d_rCurly
5400+
If MaxColIndex > 0 Then
5401+
wIdx = wIdx + i * j
5402+
Else
5403+
wIdx = wIdx + i
5404+
End If
5405+
Else
5406+
wIdx = wIdx + i
53515407
End If
5352-
Next i
5353-
Else
5354-
tmpResult = d_lCurly & Join$(DecompArray, P_SEPARATORCHAR) & d_rCurly
5355-
End If
5356-
JoinArrFunctArg = d_lCurly & tmpResult & d_rCurly
5408+
tmpResult = tmpResult & tmpArray
5409+
k = k + 1
5410+
Else
5411+
If tmpResult <> vbNullString Then
5412+
tmpResult = tmpResult & DecompArray(wIdx)
5413+
Else
5414+
tmpResult = DecompArray(wIdx)
5415+
End If
5416+
wIdx = wIdx + 1
5417+
End If
5418+
If k < UB Then
5419+
tmpResult = tmpResult & P_SEPARATORCHAR
5420+
End If
5421+
Next k
5422+
JoinArrFunctArg = tmpResult
53575423
End Function
53585424

53595425
Private Function LCase_(ByRef expression As String, ByRef fName As String) As String
@@ -8188,24 +8254,75 @@ End Function
81888254
''' <param name="outArr">Array to be scanned and overwritten.</param>
81898255
Private Function SplitArrBranch(ByRef Argument As String, ByRef outArr() As String) As Variant
81908256
Dim tmpArr() As String
8191-
Dim tmpResult(0 To 1) As Long
8192-
8193-
tmpArr() = ArrayFromString(Argument)
8194-
If IsArrayAllocated(tmpArr) Then 'Transform success
8195-
If Is2Darray(tmpArr) Then
8196-
outArr = ArraySTR1DFrom2DArr(tmpArr)
8197-
tmpResult(0) = UBound(tmpArr) 'Rows in the array
8198-
tmpResult(1) = UBound(tmpArr, 2) 'Columns in each row
8257+
Dim tmpArgs() As String
8258+
Dim tmpResult() As Long
8259+
Dim tmpOutArr() As String
8260+
Dim i As Long
8261+
Dim j As Long
8262+
Dim k As Long
8263+
Dim m As Long
8264+
Dim n As Long
8265+
Dim UB As Long
8266+
Dim usedIdx As Long
8267+
8268+
tmpArgs() = SplitArgs(Argument)
8269+
UB = UBound(tmpArgs)
8270+
ReDim tmpResult(0 To 2 * (UB + 1))
8271+
ReDim outArr(0 To 0)
8272+
For i = 0 To UB
8273+
If (tmpArgs(i) Like "{{*}}") Then ' Array
8274+
tmpArr() = ArrayFromString(tmpArgs(i))
8275+
If IsArrayAllocated(tmpArr) Then 'Transform success
8276+
If Is2Darray(tmpArr) Then
8277+
tmpOutArr = ArraySTR1DFrom2DArr(tmpArr)
8278+
tmpResult(j) = UBound(tmpArr) 'Rows in the array
8279+
tmpResult(j + 1) = UBound(tmpArr, 2) 'Columns in each row
8280+
Else
8281+
tmpOutArr = tmpArr
8282+
tmpResult(j) = UBound(tmpArr)
8283+
tmpResult(j + 1) = 0
8284+
End If
8285+
j = j + 2 'Worked array elements
8286+
Else
8287+
GoTo Err_return
8288+
End If
81998289
Else
8200-
outArr = tmpArr
8201-
tmpResult(0) = UBound(tmpArr)
8202-
tmpResult(1) = -1
8290+
If (tmpArgs(i) Like "{*}") Then ' Vector
8291+
tmpArr() = Split(strVBA.MidB(tmpArgs(i), 3, strVBA.LenB2(tmpArgs(i)) - 4), P_SEPARATORCHAR)
8292+
If IsArrayAllocated(tmpArr) Then
8293+
tmpOutArr = tmpArr
8294+
tmpResult(j) = UBound(tmpArr)
8295+
tmpResult(j + 1) = -3
8296+
j = j + 2
8297+
Else
8298+
GoTo Err_return
8299+
End If
8300+
Else ' Single data
8301+
ReDim tmpArr(0 To 0)
8302+
tmpArr(0) = tmpArgs(i)
8303+
tmpOutArr = tmpArr
8304+
tmpResult(j) = -2 'Single data type
8305+
j = j + 1
8306+
End If
82038307
End If
8204-
Else
8205-
tmpResult(0) = -1 'Return error values
8206-
tmpResult(1) = -1
8207-
End If
8308+
m = UBound(outArr)
8309+
n = UBound(tmpOutArr) + 1
8310+
ReDim Preserve outArr(0 To m + n)
8311+
For k = 0 To n - 1
8312+
outArr(usedIdx) = tmpOutArr(k)
8313+
usedIdx = usedIdx + 1
8314+
Next k
8315+
Next i
8316+
ReDim Preserve tmpResult(0 To j - 1)
8317+
ReDim Preserve outArr(0 To usedIdx - 1)
8318+
nReturn:
82088319
SplitArrBranch = tmpResult
8320+
Exit Function
8321+
Err_return:
8322+
ReDim tmpResult(0 To 1)
8323+
tmpResult(0) = -1 'Return error values
8324+
tmpResult(1) = -1
8325+
Resume nReturn
82098326
End Function
82108327

82118328
Private Sub SplitToken(ByRef expression As String, ByRef oArray() As String, ByRef OPtoken As OperatorToken)
@@ -8784,31 +8901,25 @@ Private Sub TokenizeSubExpr(ByRef expression As String, ByRef SubExpressionsData
87848901
ExpCopy = expression
87858902
tmpReplacement = GetSubstStr(OperationIndex)
87868903
If Not (ExpCopy Like "*{{*}}*") Then
8787-
Select Case strVBA.InStrB(1, ExpCopy, P_SEPARATORCHAR)
8904+
Select Case strVBA.InstrB(1, ExpCopy, P_SEPARATORCHAR)
87888905
Case 0 'Regular sub-expression
87898906
GetRootedTree ExpCopy, tmpReplacement, OperationIndex, outBuffer
87908907
outBuffer.CompCluster = False
87918908
Case Else 'Composite function argument
8792-
tmpArgs() = SplitArgs(ExpCopy)
8793-
For taIcounter = LBound(tmpArgs) To UBound(tmpArgs)
8794-
GetRootedTree tmpArgs(taIcounter), tmpReplacement, OperationIndex, outBuffer
8795-
AddToMap outBuffer.aindex, outBuffer
8796-
Next taIcounter
8797-
outBuffer.CompCluster = True
8798-
outBuffer.CompArrCluster = False
8909+
If Not (ExpCopy Like "*{*}*") Then
8910+
tmpArgs() = SplitArgs(ExpCopy)
8911+
For taIcounter = LBound(tmpArgs) To UBound(tmpArgs)
8912+
GetRootedTree tmpArgs(taIcounter), tmpReplacement, OperationIndex, outBuffer
8913+
AddToMap outBuffer.aindex, outBuffer
8914+
Next taIcounter
8915+
outBuffer.CompCluster = True
8916+
outBuffer.CompArrCluster = False
8917+
Else
8918+
ExpandCompositeArg outBuffer, tmpReplacement, ExpCopy, tmpArgs, taIcounter, OperationIndex
8919+
End If
87998920
End Select
88008921
Else 'Composite array function argument
8801-
outBuffer.ClusterArrBounds = SplitArrBranch(ExpCopy, tmpArgs)
8802-
If outBuffer.ClusterArrBounds(0) <> -1 Then 'Splitting argument success
8803-
For taIcounter = LBound(tmpArgs) To UBound(tmpArgs)
8804-
GetRootedTree tmpArgs(taIcounter), tmpReplacement, OperationIndex, outBuffer
8805-
AddToMap outBuffer.aindex, outBuffer
8806-
Next taIcounter
8807-
outBuffer.CompCluster = True
8808-
outBuffer.CompArrCluster = True
8809-
Else
8810-
'Todo: Code here for trap error of missing () in a composite array and standard input
8811-
End If
8922+
ExpandCompositeArg outBuffer, tmpReplacement, ExpCopy, tmpArgs, taIcounter, OperationIndex
88128923
End If
88138924
End Sub
88148925

0 commit comments

Comments
 (0)