Standard library / go/constant
go/constant.MakeFromLiteral()
Parse a Go literal with its token kind; the reserved final argument must be zero. Invalid syntax produces Unknown. Expected stdout: '255\n'.
Formal Syntax & Structure
go syntaxgo
func MakeFromLiteral(lit string, tok token.Token, zero uint) ValueParameters & Attributes
| Name | Type | Description |
|---|---|---|
| lit | string | Go literal source text, including quotes for strings and characters. |
| tok | token.Token | Token identifying the literal category. |
| zero | uint | Reserved argument; must be zero. |
Return Value
Value
Parse a Go literal with its token kind; the reserved final argument must be zero.
Working Example
Example Snippetgo
package main
import ( "fmt" "go/constant" "go/token")
func main() { fmt.Println(constant.MakeFromLiteral("0xff", token.INT, 0)) }