Goast (pronounced Ghost) is a Go implementation of an AST and parser. This allows for strings to be converted to and from mathematical structures.
In your project run:
go get github.com/mtresnik/goast@main
Your go.mod
file should look like this:
module mymodule
go 1.22.3
require github.com/mtresnik/goast v1.0.1
Then in your go files you should be able to access the parser:
package main
import (
"fmt"
"github.com/mtresnik/goast/pkg/operations/parser"
)
func main() {
operation, err := parser.ParseOperation("a * bc + 123 / sin(3.1415 * n) ^ log_(2, 8) - e")
if err != nil {
fmt.Println((*err).Error())
return
}
fmt.Println(operation.ToString())
}