tok

package
Version: v0.0.0-...-ce94876 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 1, 2019 License: MIT, MIT Imports: 2 Imported by: 0

Documentation

Overview

Package containing Token struct and TokenType info. Tokens are the lingua-franca used between all the refmt packages. Users typically do not refer to these types.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsTokenEqual

func IsTokenEqual(t1, t2 Token) bool

Checks if the content of two tokens is the same. Tokens are considered the same if their type one of the special consts (map/array open/close) and that type and the optional length field are equal; or, if type indicates a value, then they are the same if those values are equal. In either path, values that are *not* specified as relevant by the Token's Type are disregarded in the comparison.

If the Token.Type is not valid, the result will be false.

This method is primarily useful for testing.

Types

type Token

type Token struct {
	// The type of token.  Indicates which of the value fields has meaning,
	// or has a special value to indicate beginnings and endings of maps and arrays.
	Type   TokenType
	Length int // If this is a TMapOpen or TArrOpen, a length may be specified.  Use -1 for unknown.

	Str     string  // Value union.  Only one of these has meaning, depending on the value of 'Type'.
	Bytes   []byte  // Value union.  Only one of these has meaning, depending on the value of 'Type'.
	Bool    bool    // Value union.  Only one of these has meaning, depending on the value of 'Type'.
	Int     int64   // Value union.  Only one of these has meaning, depending on the value of 'Type'.
	Uint    uint64  // Value union.  Only one of these has meaning, depending on the value of 'Type'.
	Float64 float64 // Value union.  Only one of these has meaning, depending on the value of 'Type'.

	Tagged bool // Extension slot for cbor.
	Tag    int  // Extension slot for cbor.  Only applicable if tagged=true.
}

func TokInt

func TokInt(x int64) Token

func TokStr

func TokStr(x string) Token

func (Token) String

func (t Token) String() string

func (Token) StringSansTag

func (t Token) StringSansTag() string

func (Token) Value

func (t Token) Value() interface{}

Returns the value attached to this token, or nil. This boxes the value into an `interface{}`, which almost certainly incurs a memory allocation via `runtime.convT2E` in the process, so this this method should not be used when performance is a concern.

type TokenType

type TokenType byte
const (
	TMapOpen  TokenType = '{'
	TMapClose TokenType = '}'
	TArrOpen  TokenType = '['
	TArrClose TokenType = ']'
	TNull     TokenType = '0'

	TString  TokenType = 's'
	TBytes   TokenType = 'x'
	TBool    TokenType = 'b'
	TInt     TokenType = 'i'
	TUint    TokenType = 'u'
	TFloat64 TokenType = 'f'
)

func (TokenType) IsSpecial

func (tt TokenType) IsSpecial() bool

func (TokenType) IsValid

func (tt TokenType) IsValid() bool

func (TokenType) IsValue

func (tt TokenType) IsValue() bool

func (TokenType) String

func (tt TokenType) String() string

Source Files

Directories

Path Synopsis
Token stream test fixtures.
Token stream test fixtures.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL