Make everything a morsel less complex
This commit is contained in:
14
main.go
14
main.go
@@ -56,15 +56,11 @@ func main() {
|
||||
|
||||
// Generate the Lua script
|
||||
luaScript := buildLuaScript(luaExpr)
|
||||
log.Printf("Final expression: %s", luaExpr)
|
||||
|
||||
// Make sure the regex can match across multiple lines by adding (?s) flag
|
||||
if !strings.HasPrefix(regexPattern, "(?s)") {
|
||||
regexPattern = "(?s)" + regexPattern
|
||||
}
|
||||
log.Printf("Regex pattern: %s", regexPattern)
|
||||
log.Printf("Lua script: %s", luaScript)
|
||||
log.Printf("Processing files: %v", files)
|
||||
|
||||
// Compile the pattern for file processing
|
||||
pattern, err := regexp.Compile(regexPattern)
|
||||
@@ -89,11 +85,9 @@ func buildLuaScript(luaExpr string) string {
|
||||
strings.HasPrefix(luaExpr, "+") || strings.HasPrefix(luaExpr, "-") ||
|
||||
strings.HasPrefix(luaExpr, "^") || strings.HasPrefix(luaExpr, "%") {
|
||||
luaExpr = "v1" + luaExpr
|
||||
log.Printf("Expression modified to: %s", luaExpr)
|
||||
} else if strings.HasPrefix(luaExpr, "=") {
|
||||
// Handle direct assignment with = operator
|
||||
luaExpr = "v1 " + luaExpr
|
||||
log.Printf("Expression modified to: %s", luaExpr)
|
||||
}
|
||||
|
||||
// Replace shorthand v1, v2, etc. with their direct variable names (no need for array notation)
|
||||
@@ -137,7 +131,6 @@ end
|
||||
}
|
||||
|
||||
func processFile(filename string, pattern *regexp.Regexp, luaScript string) error {
|
||||
log.Printf("Processing file: %s", filename)
|
||||
fullPath := filepath.Join(".", filename)
|
||||
|
||||
content, err := os.ReadFile(fullPath)
|
||||
@@ -156,7 +149,6 @@ func processFile(filename string, pattern *regexp.Regexp, luaScript string) erro
|
||||
return fmt.Errorf("error writing file: %v", err)
|
||||
}
|
||||
|
||||
log.Printf("File %s updated successfully", filename)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -176,7 +168,6 @@ func process(data string, pattern *regexp.Regexp, luaScript string) (string, err
|
||||
return data, fmt.Errorf("error in Lua script: %v", err)
|
||||
}
|
||||
|
||||
modified := false
|
||||
// Process all regex matches
|
||||
result := pattern.ReplaceAllStringFunc(data, func(match string) string {
|
||||
captures := pattern.FindStringSubmatch(match)
|
||||
@@ -238,16 +229,11 @@ func process(data string, pattern *regexp.Regexp, luaScript string) (string, err
|
||||
// If we have a value, replace it
|
||||
if newVal != "" {
|
||||
result = strings.Replace(result, oldVal, newVal, 1)
|
||||
modified = true
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
})
|
||||
|
||||
if !modified {
|
||||
log.Printf("No changes made to the content")
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user