Standard library / go/parser

go/parser.ParseExpr()

Parses a standalone expression. Position information is undefined; syntax errors may return a partial AST. Expected stdout: '+\n'.

Formal Syntax & Structure

go syntaxgo
func ParseExpr(x string) (ast.Expr, error)

Parameters & Attributes

NameTypeDescription
xstringGo expression source text.

Return Value

(ast.Expr, error)

Parses a standalone expression.

Working Example

Example Snippetgo
package main
import (  "fmt"  "go/ast"  "go/parser")
func check(e error) {  if e != nil {    panic(e)  }}
func main() { x, e := parser.ParseExpr("1+2*3"); check(e); fmt.Println(x.(*ast.BinaryExpr).Op) }
Go Reference