parser

package
v1.22.2-preview2 Latest Latest
Warning

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

Go to latest
Published: May 7, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateBitsTypes added in v1.0.1

func GenerateBitsTypes(sizes []int) string

func GenerateConstantBigInts added in v1.0.1

func GenerateConstantBigInts(sizes []int) string

func GenerateConstantBigUints added in v1.16.4

func GenerateConstantBigUints(sizes []int) string

func GenerateConstantInts added in v1.0.1

func GenerateConstantInts(max int) string

func GenerateUintBitsConversions added in v1.22.5

func GenerateUintBitsConversions(uintSizes, bitsSizes []int) string

func GenerateVarUintTypes added in v1.0.1

func GenerateVarUintTypes(max int) string

Types

type Anon

type Anon struct {
	Values []FieldDefinition `"[" @@* "]"`
}

type CellRef

type CellRef struct {
	TypeExpression TypeExpression `"^" @@`
}

type Combinator

type Combinator struct {
	Name            string           `@Ident`
	TypeExpressions []TypeExpression `@@*`
}

type CombinatorDeclaration

type CombinatorDeclaration struct {
	Constructor      Constructor       `@@`
	FieldDefinitions []FieldDefinition `@@*`
	Equal            string            `"="`
	Combinator       Combinator        `@@`
	End              string            `";"`
}

type CompareOperatorExpr added in v1.4.0

type CompareOperatorExpr struct {
	Left      *RefInner `@@`
	Operation string    `@Comparison`
	Right     *RefInner `@@`
}

type Constructor

type Constructor struct {
	Name   string `@Ident`
	Prefix string `@(HexTag|BinTag)?`
}

type CurlyExpression added in v1.4.0

type CurlyExpression struct {
	CompareExpr    *CompareOperatorExpr `@@`
	TypeDefinition *TypeDefinition      `| @@`
}

type DefaultType added in v1.0.1

type DefaultType struct {
	Name          string
	IsPointerType bool
}

type FieldDefinition

type FieldDefinition struct {
	Implicit   *CurlyExpression `"{" @@ "}"`
	NamedField *NamedField      `| @@`
	Anon       *ParenExpression `| @@`
	CellRef    *CellRef         `| @@`
	TypeRef    *TypeRef         `| @@`
}

func (FieldDefinition) IsEmpty added in v1.0.1

func (fd FieldDefinition) IsEmpty() bool

type File added in v1.4.0

type File struct {
	Name    string
	Package string
	Imports []string
	Code    string
}

func (*File) Save added in v1.4.0

func (f *File) Save() error

type Generator added in v1.0.1

type Generator struct {
	// contains filtered or unexported fields
}

func NewGenerator added in v1.0.1

func NewGenerator(options ...Option) *Generator

func (*Generator) GenerateGolangTypes added in v1.0.1

func (g *Generator) GenerateGolangTypes(declarations []CombinatorDeclaration, typePrefix string, skipMagic bool) (string, error)

func (*Generator) GetTlbTypes added in v1.0.1

func (g *Generator) GetTlbTypes() []TlbType

type ImplicitField

type ImplicitField struct {
	Name string `@Ident`
	Sep  string `":"`
	Type string `@("#"|"Type")`
}

type NamedField

type NamedField struct {
	Name       string         `@(Ident|"_")`
	Sep        string         `":"`
	Expression TypeExpression `@@`
}

type Option added in v1.5.0

type Option func(*Generator)

func WithDefaultTypes added in v1.5.0

func WithDefaultTypes(types map[string]DefaultType, replace bool) Option

func WithSkipTypes added in v1.21.0

func WithSkipTypes(types ...string) Option

WithSkipTypes causes fields whose resolved Go type matches any of the given names to be omitted from the generated output. Use this for TLB types that cannot be expressed as a plain Go type (e.g. parameterized type applications whose parameter is a runtime variable rather than a constant).

func WithTlbPackage added in v1.21.0

func WithTlbPackage(pkg string) Option

type Optional added in v1.0.1

type Optional struct {
	Modificator string `@Ident`
	Dot         string `"."`
	Int         int    `@NUMBER`
	QMark       string `"?"`
	Ident       string `@Ident`
}

type ParenExpression

type ParenExpression struct {
	Name      TypeExpression   `"(" @@ `
	Parameter []TypeExpression `@@* ")"`
}

type RefInner added in v1.4.0

type RefInner struct {
	Ident  *string `@Ident`
	Number *int    `| @NUMBER`
}

type TLB

type TLB struct {
	Declarations []CombinatorDeclaration `@@*`
}

func Parse

func Parse(tlb string) (*TLB, error)

type TlbType added in v1.0.1

type TlbType struct {
	Name       string
	Definition string
}

type TypeDefinition added in v1.4.0

type TypeDefinition struct {
	Implicit   *ImplicitField  `(@@`
	Expression *TypeExpression `| @@)`
}

type TypeExpression

type TypeExpression struct {
	Tilda                string           `@"~"?`
	ParenExpression      *ParenExpression `(@@`
	AnonymousConstructor *Anon            `| @@`
	CellRef              *CellRef         `| @@`
	Optional             *Optional        `| @@`
	BuiltIn              *string          `| @BuiltIn`
	Number               *int             `| @NUMBER`
	NamedRef             *string          `| @Ident)`
}

type TypeRef added in v1.4.0

type TypeRef struct {
	Name string `@Ident`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL