Implement printing from lua
This commit is contained in:
@@ -107,14 +107,6 @@ func (p *RegexProcessor) ProcessContent(content string, pattern string, luaExpr
|
||||
luaExpr = BuildLuaScript(luaExpr)
|
||||
log.Printf("Changing Lua expression from: %s to: %s", previous, luaExpr)
|
||||
|
||||
L, err := NewLuaState()
|
||||
if err != nil {
|
||||
log.Printf("Error creating Lua state: %v", err)
|
||||
return "", 0, 0, fmt.Errorf("error creating Lua state: %v", err)
|
||||
}
|
||||
defer L.Close()
|
||||
log.Printf("Lua state created successfully")
|
||||
|
||||
// Initialize Lua environment
|
||||
modificationCount := 0
|
||||
|
||||
@@ -128,6 +120,17 @@ func (p *RegexProcessor) ProcessContent(content string, pattern string, luaExpr
|
||||
// By going backwards we fuck up all the indices to the end of the file that we don't care about
|
||||
// Because there either aren't any (last match) or they're already modified (subsequent matches)
|
||||
for i := len(indices) - 1; i >= 0; i-- {
|
||||
L, err := NewLuaState()
|
||||
if err != nil {
|
||||
log.Printf("Error creating Lua state: %v", err)
|
||||
return "", 0, 0, fmt.Errorf("error creating Lua state: %v", err)
|
||||
}
|
||||
// Hmm... Maybe we don't want to defer this..
|
||||
// Maybe we want to close them every iteration
|
||||
// We'll leave it as is for now
|
||||
defer L.Close()
|
||||
log.Printf("Lua state created successfully")
|
||||
|
||||
matchIndices := indices[i]
|
||||
log.Printf("Processing match indices: %v", matchIndices)
|
||||
|
||||
@@ -150,9 +153,19 @@ func (p *RegexProcessor) ProcessContent(content string, pattern string, luaExpr
|
||||
log.Println("Odd number of indices of groups, what the fuck?")
|
||||
continue
|
||||
}
|
||||
for _, index := range groups {
|
||||
if index == -1 {
|
||||
// return "", 0, 0, fmt.Errorf("negative indices encountered: %v. This indicates that there was an issue with the match indices, possibly due to an empty match or an unexpected pattern. Please check the regex pattern and input content.", matchIndices)
|
||||
log.Printf("Negative indices encountered: %v. This indicates that there was an issue with the match indices, possibly due to an empty match or an unexpected pattern. This is not an error but it's possibly not what you want.", matchIndices)
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
captures := make([]string, 0, len(groups)/2)
|
||||
for j := 0; j < len(groups); j += 2 {
|
||||
if groups[j] == -1 || groups[j+1] == -1 {
|
||||
continue
|
||||
}
|
||||
captures = append(captures, content[groups[j]:groups[j+1]])
|
||||
}
|
||||
log.Printf("Captured groups: %v", captures)
|
||||
@@ -167,6 +180,9 @@ func (p *RegexProcessor) ProcessContent(content string, pattern string, luaExpr
|
||||
if name == "" {
|
||||
continue
|
||||
}
|
||||
if groups[i*2] == -1 || groups[i*2+1] == -1 {
|
||||
continue
|
||||
}
|
||||
namedCaptures = append(namedCaptures, NamedCapture{
|
||||
Name: name,
|
||||
Value: captures[i],
|
||||
|
||||
Reference in New Issue
Block a user