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) Value

Parameters & Attributes

NameTypeDescription
litstringGo literal source text, including quotes for strings and characters.
toktoken.TokenToken identifying the literal category.
zerouintReserved 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)) }
Go Reference