Documentation ¶
Overview ¶
Package strparse provides convenience wrappers around `go/parser` for simple expression, statement and declaration parsing from string.
Can be used to construct AST nodes using source syntax.
Example ¶
package main import ( "fmt" "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 }
Output: true
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // BadExpr is returned as a parse result for malformed expressions. // Should be treated as constant or readonly variable. BadExpr = &ast.BadExpr{} // BadStmt is returned as a parse result for malformed statmenents. // Should be treated as constant or readonly variable. BadStmt = &ast.BadStmt{} // BadDecl is returned as a parse result for malformed declarations. // Should be treated as constant or readonly variable. BadDecl = &ast.BadDecl{} )
Functions ¶
func Decl ¶
Decl parses single declaration node from s. In case of parse error, BadDecl is returned.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.