Standard library / go/types
go/types.ExprString()
Formats a parsed expression for diagnostics; not a replacement for a source formatter. Expected stdout: '1 + 2\n'.
Formal Syntax & Structure
go syntaxgo
func ExprString(x ast.Expr) stringParameters & Attributes
| Name | Type | Description |
|---|---|---|
| x | ast.Expr | First type or expression to inspect. |
Return Value
string
Formats a parsed expression for diagnostics; not a replacement for a source formatter.
Working Example
Example Snippetgo
package main
import ( "fmt" "go/parser" "go/types")
func check(e error) { if e != nil { panic(e) }}
func main() { e, err := parser.ParseExpr("1+2"); check(err); fmt.Println(types.ExprString(e)) }