43 lines
944 B
Go
43 lines
944 B
Go
package interpreter
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"github.com/zeevdiukman/go-interpreter"
|
|
)
|
|
|
|
type Interp struct {
|
|
*interpreter.Interpreter
|
|
}
|
|
|
|
func New() *Interp {
|
|
interp := &Interp{interpreter.New()}
|
|
|
|
return interp
|
|
}
|
|
func (interp *Interp) PathAction(rules string, fn func(fn interpreter.Function)) {
|
|
name := "router_rules"
|
|
|
|
regx := interp.Regex(name, "\\(`(.*?)`\\)")
|
|
interp.Func(name, func(args ...any) string {
|
|
// argsStmntName := args[0].(string)
|
|
argsPathAction := args[0].(func(string))
|
|
interp.AddStatment(name, rules).SplitStatementByRegex(regx)
|
|
interp.Statments.ForEach(func(stmnt *interpreter.Statment) {
|
|
if stmnt.Name == name {
|
|
for idx, splitVal := range stmnt.RegexSplit {
|
|
splitVal, _ = strings.CutPrefix(splitVal, ".")
|
|
switch splitVal {
|
|
case "Path":
|
|
{
|
|
path := stmnt.RegexSplit[idx+1]
|
|
argsPathAction(path)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
})
|
|
return ""
|
|
})
|
|
interp.Funcs[name].Function()
|
|
}
|