strparse: github.com/go-toolsmith/strparse Index | Examples | Files

package strparse

import "github.com/go-toolsmith/strparse"

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.

Code:

// 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

Package Files

strparse.go

Variables

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{}
)

func Decl Uses

func Decl(s string) ast.Decl

Decl parses single declaration node from s. In case of parse error, BadDecl is returned.

func Expr Uses

func Expr(s string) ast.Expr

Expr parses single expression node from s. In case of parse error, BadExpr is returned.

func Stmt Uses

func Stmt(s string) ast.Stmt

Stmt parses single statement node from s. In case of parse error, BadStmt is returned.

Package strparse imports 3 packages (graph) and is imported by 1 packages. Updated 2018-09-24. Refresh now. Tools for package owners.