tlast

package
v1.4.1 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2026 License: MPL-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const ContactAuthorsString = "please check/create issue with example https://github.com/VKCOM/tl/issues" // TODO move to better place
View Source
const OneLineConstructorSize = 120
View Source
const UnionConstructorSize = 80

Variables

This section is empty.

Functions

func NewCanonicalFormatOptions

func NewCanonicalFormatOptions() formatOptions

func NewDefaultFormatOptions

func NewDefaultFormatOptions() formatOptions

func SplitMultilineComment

func SplitMultilineComment(comment string) []string

we support windows-style line separators

Types

type Arithmetic

type Arithmetic struct {
	Nums []uint32
	Res  uint32
}

func (Arithmetic) IsEmpty

func (a Arithmetic) IsEmpty() bool

func (Arithmetic) StreamString

func (a Arithmetic) StreamString(qw422016 *qt422016.Writer)

func (Arithmetic) String

func (a Arithmetic) String() string

func (Arithmetic) WriteString

func (a Arithmetic) WriteString(qq422016 qtio422016.Writer)

type ArithmeticOrType

type ArithmeticOrType struct {
	IsArith bool
	Arith   Arithmetic
	T       TypeRef // PR of T can also be used for Arith
}

func (ArithmeticOrType) StreamString

func (aot ArithmeticOrType) StreamString(qw422016 *qt422016.Writer)

func (ArithmeticOrType) String

func (aot ArithmeticOrType) String() string

func (ArithmeticOrType) WriteString

func (aot ArithmeticOrType) WriteString(qq422016 qtio422016.Writer)

type Combinator

type Combinator struct {
	Builtin           bool
	IsFunction        bool
	Modifiers         []Modifier // TODO - rename to annotations
	Construct         Constructor
	TemplateArguments []TemplateArgument
	Fields            []Field
	TypeDecl          TypeDeclaration
	FuncDecl          TypeRef

	OriginalDescriptor *Combinator // hack - if some replacements were made, original descriptor is saved here
	OriginalOrderIndex int         // declaration order index (needed in TLO generation)

	TemplateArgumentsPR PositionRange // especially useful when 0 arguments
	PR                  PositionRange
	SectionPR           PositionRange // section headers
	AllPR               PositionRange // with all whitespace in file (except sections and last section) accounted for

	CommentBefore string // comment before combinator
	CommentRight  string // comment to the right of combinator
}

func (*Combinator) Crc32

func (descriptor *Combinator) Crc32() uint32

func (*Combinator) GenCrc32

func (descriptor *Combinator) GenCrc32() uint32

func (Combinator) MostOriginalVersion

func (c Combinator) MostOriginalVersion() *Combinator

func (Combinator) StreamString

func (descriptor Combinator) StreamString(qw422016 *qt422016.Writer)

func (Combinator) String

func (descriptor Combinator) String() string

func (Combinator) WriteString

func (descriptor Combinator) WriteString(qq422016 qtio422016.Writer)

type CombinatorField

type CombinatorField struct {
	Comb       *Combinator
	FieldIndex int
}

type Constructor

type Constructor struct {
	Name       Name
	ID         uint32
	IDExplicit bool // if false, ID is calculated immediately after parsing

	NamePR PositionRange
	IDPR   PositionRange
}

func (Constructor) StreamString

func (c Constructor) StreamString(qw422016 *qt422016.Writer)

func (Constructor) String

func (c Constructor) String() string

func (Constructor) WriteString

func (c Constructor) WriteString(qq422016 qtio422016.Writer)

type Field

type Field struct {
	FieldName string
	Mask      *FieldMask
	Excl      bool

	IsRepeated  bool
	ScaleRepeat RepeatWithScale
	FieldType   TypeRef

	PR     PositionRange
	PRName PositionRange
	AllPR  PositionRange // with all whitespace in file (except sections and last section) accounted for

	CommentBefore string // comment before field
	CommentRight  string // comment to the right of field
	NewlineRight  bool

	// this is set during type resolution, so the information
	// about argument references not erased from the type
	UsedAsMask     bool
	UsedAsMaskPR   PositionRange
	UsedAsSize     bool
	UsedAsSizePR   PositionRange
	AffectedFields []CombinatorField
}

func (Field) StreamString

func (f Field) StreamString(qw422016 *qt422016.Writer)

func (Field) StreamToCrc32

func (f Field) StreamToCrc32(qw422016 *qt422016.Writer)

func (Field) String

func (f Field) String() string

func (Field) ToCrc32

func (f Field) ToCrc32() string

func (Field) WriteString

func (f Field) WriteString(qq422016 qtio422016.Writer)

func (Field) WriteToCrc32

func (f Field) WriteToCrc32(qq422016 qtio422016.Writer)

type FieldMask

type FieldMask struct {
	MaskName  string
	BitNumber uint32

	PRName PositionRange
	PRBits PositionRange
}

func (FieldMask) StreamString

func (fm FieldMask) StreamString(qw422016 *qt422016.Writer)

func (FieldMask) String

func (fm FieldMask) String() string

func (FieldMask) WriteString

func (fm FieldMask) WriteString(qq422016 qtio422016.Writer)

type LexerLanguage

type LexerLanguage int
const (
	TL1 LexerLanguage = iota
	TL2
)

type LexerOptions

type LexerOptions struct {
	AllowBuiltin bool // allows constructor to start from '_' (underscore), used only internally by tlgen
	AllowDirty   bool // allows to use '_' (underscore) as constructor name, will be removed after combined.tl is cleaned up

	LexerLanguage // default value is TL1
}

type Modifier

type Modifier struct {
	Name string
	PR   PositionRange
}

type Name

type Name struct {
	Namespace string
	Name      string
}

func (Name) IsEmpty

func (n Name) IsEmpty() bool

func (Name) StreamString

func (n Name) StreamString(qw422016 *qt422016.Writer)

func (Name) String

func (n Name) String() string

func (Name) WriteString

func (n Name) WriteString(qq422016 qtio422016.Writer)

type OptionalParse

type OptionalParse[T any] func(tokens tokenIterator, position Position) (state OptionalState, restTokens tokenIterator, result T)

type OptionalState

type OptionalState struct {
	StartProcessing bool
	Error           *ParseError
}

func (*OptionalState) ExpectProgress

func (state *OptionalState) ExpectProgress(orError *ParseError) bool

func (*OptionalState) FailWithError

func (state *OptionalState) FailWithError(error *ParseError)

func (*OptionalState) HasProgress

func (state *OptionalState) HasProgress() bool

func (*OptionalState) Inherit

func (state *OptionalState) Inherit(otherState OptionalState)

func (*OptionalState) IsFailed

func (state *OptionalState) IsFailed() bool

func (*OptionalState) IsOmitted

func (state *OptionalState) IsOmitted() bool

type ParseError

type ParseError struct {
	Err error

	Pos PositionRange
	// contains filtered or unexported fields
}

func BeautifulError2

func BeautifulError2(original *ParseError, compare *ParseError) *ParseError

func (*ParseError) ConsolePrint

func (e *ParseError) ConsolePrint(out io.Writer, outmostError error, isWarning bool)

func (ParseError) Error

func (e ParseError) Error() string

func (*ParseError) PrintWarning

func (e *ParseError) PrintWarning(out io.Writer, outmostError error)

func (ParseError) Unwrap

func (e ParseError) Unwrap() error

type Position

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

func (*Position) FileContent

func (p *Position) FileContent() string

func (*Position) FileName

func (p *Position) FileName() string

func (*Position) Offset

func (p *Position) Offset() int

func (Position) String

func (p Position) String() string

type PositionRange

type PositionRange struct {
	Outer Position // in lexer, it is empty, in parser set to start of combinator
	Begin Position
	End   Position
}

func (PositionRange) BeautifulError

func (pr PositionRange) BeautifulError(err error) *ParseError

func (PositionRange) CheckValidity

func (pr PositionRange) CheckValidity()

func (PositionRange) CollapseToBegin

func (pr PositionRange) CollapseToBegin() PositionRange

func (PositionRange) CollapseToEnd

func (pr PositionRange) CollapseToEnd() PositionRange

type RepeatWithScale

type RepeatWithScale struct {
	ExplicitScale bool
	Scale         ScaleFactor
	Rep           []Field

	PR PositionRange
}

func (RepeatWithScale) StreamString

func (rws RepeatWithScale) StreamString(qw422016 *qt422016.Writer)

func (RepeatWithScale) String

func (rws RepeatWithScale) String() string

func (RepeatWithScale) WriteString

func (rws RepeatWithScale) WriteString(qq422016 qtio422016.Writer)

type ScaleFactor

type ScaleFactor struct {
	IsArith bool
	Arith   Arithmetic
	Scale   string

	PR PositionRange
}

func (ScaleFactor) IsEmpty

func (sf ScaleFactor) IsEmpty() bool

func (ScaleFactor) StreamString

func (sf ScaleFactor) StreamString(qw422016 *qt422016.Writer)

func (ScaleFactor) String

func (sf ScaleFactor) String() string

func (ScaleFactor) WriteString

func (sf ScaleFactor) WriteString(qq422016 qtio422016.Writer)

type TL

type TL []*Combinator

func ParseTL

func ParseTL(str string) (TL, error)

func ParseTLFile

func ParseTLFile(str, file string, opts LexerOptions) (TL, error)

ParseTLFile TL := TypesSection [ type ... ] FunctionSection [ function ... ]

func (TL) Generate2TL

func (tl TL) Generate2TL() string

func (TL) GenerateTLO

func (tl TL) GenerateTLO(version uint32) (tls.SchemaV4, error)

func (TL) StreamGenerate2TL

func (tl TL) StreamGenerate2TL(qw422016 *qt422016.Writer)

func (TL) StreamString

func (tl TL) StreamString(qw422016 *qt422016.Writer)

func (TL) String

func (tl TL) String() string

func (TL) ToDot

func (tl TL) ToDot() string

func (TL) WriteGenerate2TL

func (tl TL) WriteGenerate2TL(qq422016 qtio422016.Writer)

func (TL) WriteString

func (tl TL) WriteString(qq422016 qtio422016.Writer)

type TL2Annotation

type TL2Annotation struct {
	Name string
	PR   PositionRange
}

TL2Annotation := at name;

type TL2BracketType

type TL2BracketType struct {
	IndexType TL2TypeArgument
	ArrayType TL2TypeRef

	HasIndex bool

	PR PositionRange
}

TL2BracketType := lsb TL2TypeArgument? rsb TL2TypeRef;

func (*TL2BracketType) Print

func (t *TL2BracketType) Print(sb *strings.Builder)

type TL2Combinator

type TL2Combinator struct {
	Annotations []TL2Annotation

	TypeDecl TL2TypeDeclaration
	FuncDecl TL2FuncDeclaration

	IsFunction bool

	PR PositionRange

	CommentBefore string
}

TL2Combinator := TL2Annotation* (TL2TypeDeclaration | TL2FuncDeclaration) scl;

func (TL2Combinator) HasAnnotation

func (c TL2Combinator) HasAnnotation(value string) bool

func (*TL2Combinator) Print

func (t *TL2Combinator) Print(sb *strings.Builder, options formatOptions)

func (TL2Combinator) ReferenceName

func (c TL2Combinator) ReferenceName() TL2TypeName

func (TL2Combinator) ReferenceNamePR

func (c TL2Combinator) ReferenceNamePR() PositionRange

func (TL2Combinator) String

func (t TL2Combinator) String() string

type TL2Field

type TL2Field struct {
	Name       string
	IsOptional bool
	IsIgnored  bool
	Type       TL2TypeRef

	PR     PositionRange
	PRName PositionRange

	CommentBefore string
	CommentRight  string
}

TL2Field := ((name qm?) | ucs) cl TL2TypeRef;

func (TL2Field) IsOmitted

func (f TL2Field) IsOmitted() bool

func (*TL2Field) Print

func (t *TL2Field) Print(sb *strings.Builder)

type TL2File

type TL2File struct {
	Combinators []TL2Combinator
}

TL2File := TL2Combinator*;

func ParseTL2

func ParseTL2(str string) (TL2File, error)

func ParseTL2File

func ParseTL2File(str, file string, opts LexerOptions) (tl2File TL2File, err error)

TL2File := TL2Combinator* EOF;

func (TL2File) Print

func (t TL2File) Print(sb *strings.Builder, options formatOptions)

func (TL2File) String

func (t TL2File) String() string

type TL2FuncDeclaration

type TL2FuncDeclaration struct {
	Name       TL2TypeName
	Magic      uint32
	Arguments  []TL2Field
	ReturnType TL2TypeDefinition

	PR     PositionRange
	PRName PositionRange
	PRID   PositionRange
}

TL2FuncDeclaration := TL2TypeName CRC32 TL2Field* TL2FuncReturnTypeDefinition;

type TL2StructTypeDefinition

type TL2StructTypeDefinition struct {
	ConstructorFields []TL2Field
	UnionType         TL2UnionType

	IsUnionType bool

	PR PositionRange
}

TL2StructTypeDefinition := TL2Field* | TL2UnionType;

type TL2TypeApplication

type TL2TypeApplication struct {
	Name      TL2TypeName
	Arguments []TL2TypeArgument

	PR          PositionRange
	PRName      PositionRange
	PRArguments PositionRange

	// this is part of TL1 support. The hybrid kernel first converts all.
	// type references to the same (TL2) format for type resolution purposes.
	// this field is false for all TL2-originated type references.
	Bare bool
}

TL2TypeApplication := TL2TypeName (lts TL2TypeArgument (cm TL2TypeArgument)* gts)?;

func (*TL2TypeApplication) Print

func (t *TL2TypeApplication) Print(sb *strings.Builder)

func (TL2TypeApplication) String

func (t TL2TypeApplication) String() string

type TL2TypeArgument

type TL2TypeArgument struct {
	Type   TL2TypeRef
	Number uint32

	IsNumber bool

	PR PositionRange

	// this is set during type resolution, so the information
	// about argument references not erased from the type
	// TODO - decide on moving into TL2TypeRef when working on C++ gen
	OriginalArgumentName string
}

TL2TypeArgument := TL2TypeRef | number;

func (*TL2TypeArgument) Print

func (t *TL2TypeArgument) Print(sb *strings.Builder)

func (TL2TypeArgument) String

func (t TL2TypeArgument) String() string

type TL2TypeCategory

type TL2TypeCategory struct {
	IsNatValue bool
}

func (TL2TypeCategory) IsNat

func (c TL2TypeCategory) IsNat() bool

func (TL2TypeCategory) IsType

func (c TL2TypeCategory) IsType() bool

func (TL2TypeCategory) String

func (c TL2TypeCategory) String() string

type TL2TypeDeclaration

type TL2TypeDeclaration struct {
	Name              TL2TypeName
	Magic             uint32
	TemplateArguments []TL2TypeTemplate
	Type              TL2TypeDefinition

	// TODO -TemplateArgumentsPR
	PR     PositionRange
	PRName PositionRange
	PRID   PositionRange
}

TL2TypeDeclaration := TL2TypeName (lts TL2TypeArgumentDeclaration (cm TL2TypeArgumentDeclaration)* gts)? CRC32? eq TL2TypeDefinition?;

type TL2TypeDefinition

type TL2TypeDefinition struct {
	StructType TL2StructTypeDefinition
	TypeAlias  TL2TypeRef

	IsTypeAlias bool

	PR PositionRange
}

TL2TypeDefinition = (eq TL2StructTypeDefinition) | (alias TL2TypeRef);

func (TL2TypeDefinition) IsAlias

func (t TL2TypeDefinition) IsAlias() bool

type TL2TypeName

type TL2TypeName struct {
	Namespace string
	Name      string
}

TL2TypeName := (name dot)? name;

func (TL2TypeName) String

func (t TL2TypeName) String() string

type TL2TypeRef

type TL2TypeRef struct {
	SomeType    TL2TypeApplication
	BracketType *TL2BracketType

	PR PositionRange
}

TL2TypeRef := TL2TypeApplication | TL2BracketType;

func (TL2TypeRef) IsBracket

func (t TL2TypeRef) IsBracket() bool

func (*TL2TypeRef) Print

func (t *TL2TypeRef) Print(sb *strings.Builder)

func (TL2TypeRef) String

func (t TL2TypeRef) String() string

type TL2TypeTemplate

type TL2TypeTemplate struct {
	Name     string
	Category TL2TypeCategory

	PR         PositionRange
	PRName     PositionRange
	PRCategory PositionRange
}

TL2TypeTemplate := name cl name;

type TL2UnionConstructor

type TL2UnionConstructor struct {
	Name string

	Fields    []TL2Field
	TypeAlias TL2TypeRef

	IsTypeAlias bool

	PR     PositionRange
	PRName PositionRange

	CommentBefore string
}

TL2UnionConstructor := name (TL2TypeRef | TL2Field*); case of TL2TypeRef will be converted to TL2Field with empty name

func (TL2UnionConstructor) HasBeforeCommentIn

func (t TL2UnionConstructor) HasBeforeCommentIn() bool

type TL2UnionType

type TL2UnionType struct {
	Variants []TL2UnionConstructor // at least 1

	PR PositionRange
}

TL2UnionType := tl2UnionTypeMono | tl2UnionTypeMulti;

tl2UnionTypeMono := vb TL2UnionConstructor (vb TL2UnionConstructor)*; tl2UnionTypeMulti := TL2UnionConstructor (vb TL2UnionConstructor)+;

type TemplateArgument

type TemplateArgument struct {
	FieldName string
	IsNat     bool
	PR        PositionRange // TODO - split into type and name
}

func (TemplateArgument) StreamString

func (ta TemplateArgument) StreamString(qw422016 *qt422016.Writer)

func (TemplateArgument) String

func (ta TemplateArgument) String() string

func (TemplateArgument) WriteString

func (ta TemplateArgument) WriteString(qq422016 qtio422016.Writer)

type TypeDeclaration

type TypeDeclaration struct {
	Name      Name
	Arguments []string

	PR          PositionRange
	NamePR      PositionRange
	ArgumentsPR []PositionRange
}

func (TypeDeclaration) StreamString

func (d TypeDeclaration) StreamString(qw422016 *qt422016.Writer)

func (TypeDeclaration) String

func (d TypeDeclaration) String() string

func (TypeDeclaration) WriteString

func (d TypeDeclaration) WriteString(qq422016 qtio422016.Writer)

type TypeRef

type TypeRef struct {
	Type Name
	Args []ArithmeticOrType
	Bare bool

	PR     PositionRange
	PRArgs PositionRange
}

func (TypeRef) DeepCopy

func (t TypeRef) DeepCopy() TypeRef

func (TypeRef) IsEmpty

func (t TypeRef) IsEmpty() bool

func (TypeRef) StreamString

func (t TypeRef) StreamString(qw422016 *qt422016.Writer)

func (TypeRef) StreamToCrc32

func (t TypeRef) StreamToCrc32(qw422016 *qt422016.Writer)

func (TypeRef) StreamTopLevelString

func (t TypeRef) StreamTopLevelString(qw422016 *qt422016.Writer)

func (TypeRef) String

func (t TypeRef) String() string

func (TypeRef) ToCrc32

func (t TypeRef) ToCrc32() string

func (TypeRef) TopLevelString

func (t TypeRef) TopLevelString() string

func (TypeRef) WriteString

func (t TypeRef) WriteString(qq422016 qtio422016.Writer)

func (TypeRef) WriteToCrc32

func (t TypeRef) WriteToCrc32(qq422016 qtio422016.Writer)

func (TypeRef) WriteTopLevelString

func (t TypeRef) WriteTopLevelString(qq422016 qtio422016.Writer)

Directories

Path Synopsis
gentlo
basictl
Code generated by tl2gen; DO NOT EDIT.
Code generated by tl2gen; DO NOT EDIT.
constants
Code generated by tl2gen; DO NOT EDIT.
Code generated by tl2gen; DO NOT EDIT.
factory
Code generated by tl2gen; DO NOT EDIT.
Code generated by tl2gen; DO NOT EDIT.
internal
Code generated by tl2gen; DO NOT EDIT.
Code generated by tl2gen; DO NOT EDIT.
internal/metainternal
Code generated by tl2gen; DO NOT EDIT.
Code generated by tl2gen; DO NOT EDIT.
meta
Code generated by tl2gen; DO NOT EDIT.
Code generated by tl2gen; DO NOT EDIT.
tltls
Code generated by tl2gen; DO NOT EDIT.
Code generated by tl2gen; DO NOT EDIT.

Jump to

Keyboard shortcuts

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