Beispiel #1
0
func main() {
	/*
	     p1 := &ast.CallExpr {
	   Fun: &ast.Ident {
	     NamePos: 385,
	     Name: "Mul",
	     Obj: nil },
	   Lparen: 388,
	   Args: []ast.Expr {
	     &ast.CallExpr {
	       Fun: &ast.Ident {
	         NamePos: 389,
	         Name: "Const",
	         Obj: nil },
	       Lparen: 394,
	       Args: []ast.Expr {
	         &ast.BasicLit {
	           ValuePos: 395,
	           Kind: token.INT,
	           Value: []uint8 {
	             49,
	             48 } } },
	       Ellipsis: 0,
	       Rparen: 397 },
	     &ast.CallExpr {
	       Fun: &ast.Ident {
	         NamePos: 399,
	         Name: "Const",
	         Obj: nil },
	       Lparen: 404,
	       Args: []ast.Expr {
	         &ast.BasicLit {
	           ValuePos: 405,
	           Kind: token.INT,
	           Value: []uint8 {
	             50,
	             48 } } },
	       Ellipsis: 0,
	       Rparen: 407 } },
	   Ellipsis: 0,
	   Rparen: 408 }
	*/

	// fmt.Printf("%s \n",
	c, _ := parser.ParseExpr(token.NewFileSet(), "temp.go", "Mul(Const(1),x)")
	p := c.(*ast.CallExpr)
	fmt.Print(callToStmt("m", "e", p))
	c2, _ := parser.ParseExpr(token.NewFileSet(), "temp.go", "Mul(x,Const(1))")
	p2 := c2.(*ast.CallExpr)
	callToStmt("m", "e", p2)
	// fmt.Printf"%s \n", p2)
}
Beispiel #2
0
func NewExpr(src string) Expr {
	fs := token.NewFileSet()
	if e, ok := parser.ParseExpr(fs, "temp.go", src); ok == nil {
		return e
	}
	return nil
}