Skip to content

Latest commit

 

History

History
48 lines (36 loc) · 1.23 KB

README.md

File metadata and controls

48 lines (36 loc) · 1.23 KB

strparse

build-img pkg-img reportcard-img version-img

Package strparse provides convenience wrappers around go/parser for simple expression, statement and declaretion parsing from string.

Installation

Go version 1.16+

go get github.com/go-toolsmith/strparse

Example

package main

import (
	"github.com/go-toolsmith/astequal"
	"github.com/go-toolsmith/strparse"
)

func main() {
	// Comparing AST strings for equallity (note different spacing):
	x := strparse.Expr(`1 + f(v[0].X)`)
	y := strparse.Expr(` 1+f( v[0].X ) `)
	fmt.Println(astequal.Expr(x, y)) // => true
}

License

MIT License.