Skip to content

Commit

Permalink
chore: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasjarosch committed Apr 28, 2024
1 parent 21dcb1f commit 54a588d
Showing 1 changed file with 7 additions and 20 deletions.
27 changes: 7 additions & 20 deletions expression.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,6 @@ func (m *ExpressionManager) ExecuteInput(input string) (data.Value, error) {
return data.NilValue, err
}

subGraph.Visualize("/tmp/sub", "sub")

vertexOrder, err := subGraph.TopologicalSort()
if err != nil {
return data.NilValue, err
Expand Down Expand Up @@ -220,29 +218,18 @@ func (m *ExpressionManager) ExecuteInput(input string) (data.Value, error) {
pathResults[i] = result
}

// figure out the byte offsets for every expression within the source value
// the order is the same as pathResults, so the pathResults map directly to the offsets which need to be replaced.
exprPositions := make([][]int, len(pathResults))
sourceValue, _ := valueProvider.GetPathValue(data.NewPath(pathVertex))
idx := expressionRegex.FindAllStringSubmatchIndex(sourceValue.String(), -1)
for n, match := range idx {
for i := 0; i < len(match); i += 2 {
start := match[i]
end := match[i+1]
exprPositions[n] = []int{start, end}
}
}

for i, result := range pathResults {
if len(exprPositions[i]) == 0 {
continue
for _, result := range pathResults {
sourceValue, err := valueProvider.GetPathValue(data.NewPath(pathVertex))
if err != nil {
return data.NilValue, err
}

sourceValue, _ = valueProvider.GetPathValue(data.NewPath(pathVertex))

// fetch the start and end offset of this expression
// and replace the old value with the result of the expression evaluation
exprOffsets := expressionRegex.FindStringSubmatchIndex(sourceValue.String())
if len(exprOffsets) == 0 {
continue
}
oldValue := sourceValue.String()[exprOffsets[0]:exprOffsets[1]]
newValue := strings.Replace(sourceValue.String(), oldValue, data.NewValue(result).String(), 1)

Expand Down

0 comments on commit 54a588d

Please sign in to comment.