tl

package module
v0.0.0-...-5e76058 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2015 License: MIT Imports: 9 Imported by: 0

README

tl

This Go package provides lexer and a recursive descent LL parser for Telegram's TL (Type Language).

Installation

go get github.com/igungor/tl

Status

It is a work in progress and a hobby project. Not much works yet.

Documentation

Overview

Package tl implements Telegram's TL(Type Language) lexer and parser. It takes a []byte as source which can be tokenized through the scanner and then they fed to the parser. The output is an abstract syntax tree (AST) representing the TL program.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Arg

type Arg struct{}

type BareType

type BareType struct{}

type BoxedTypeIdent

type BoxedTypeIdent struct {
	Name string
}

type BuiltinCombDecl

type BuiltinCombDecl struct {
	Id     FullCombinatorId
	Result BoxedTypeIdent
}

A declaration is represented by one of the following declaration nodes.

type CombDecl

type CombDecl struct {
	Id      FullCombinatorId
	OptArgs []OptionalArg
	Args    []Arg
	Result  ResultType
}

A declaration is represented by one of the following declaration nodes.

func (CombDecl) Name

func (CombDecl) Name()

type Combinator

type Combinator interface {
	Node
	Name() string
}

Combinator represents a constructor, function or a built-in combinator whose combinator-name can be computed.

type CombinatorId

type CombinatorId struct {
	Id Ident
}

type ConstrDecl

type ConstrDecl struct{}

A declaration is represented by one of the following declaration nodes.

func (ConstrDecl) Name

func (ConstrDecl) Name()

combinatorNode implementations for combinator nodes.

type Declaration

type Declaration interface {
	Node
	// contains filtered or unexported methods
}

Declaration represents a constructor or function declaration. All declaration nodes implement the Declaration interface.

type Expr

type Expr struct{}

type FullCombinatorId

type FullCombinatorId struct {
	Id Ident
}

type FuncDecl

type FuncDecl struct{}

A declaration is represented by one of the following declaration nodes.

func (FuncDecl) Name

func (FuncDecl) Name()

type Ident

type Ident struct {
	Name Token
}

func NewIdent

func NewIdent(name string) Ident

func (Ident) Text

func (i Ident) Text() string

type Item

type Item int

Item represents a lexical token type.

const (
	ItemIllegal Item = iota
	ItemWhitespace
	ItemEOF

	ItemUnderscore   // _
	ItemColon        // :
	ItemSemicolon    // ;
	ItemOpenPar      // (
	ItemClosePar     // )
	ItemOpenBracket  // [
	ItemCloseBracket // ]
	ItemOpenBrace    // {
	ItemCloseBrace   // }
	ItemLeftAngle    // <
	ItemRightAngle   // >
	ItemTripleMinus  // ---
	ItemEquals       // =
	ItemHash         // #
	ItemExclMark     // !
	ItemQuestionMark // ?
	ItemPercent      // %
	ItemPlus         // +
	ItemComma        // ,
	ItemDot          // .
	ItemAsterisk     // *

	ItemNatConst // 4, 42, 421
	// LowerIdent represents lc-ident, lc-ident-ns and lc-ident-full
	ItemLowerIdent // user | user#decafbad | users.user | users.user#decafbad
	// UpperIdent represents uc-ident, uc-ident-ns
	ItemUpperIdent // User | group.User

	ItemFinal // Final
	ItemNew   // New
	ItemEmpty // Empty
)

List of tokens - https://core.telegram.org/mtproto/TL-formal#tokens

func (Item) String

func (i Item) String() string

type Node

type Node interface {
	// contains filtered or unexported methods
}

Node represents a node in abstract syntax tree.

type OptionalArg

type OptionalArg struct{}

type Parser

type Parser struct {
	Trace bool // parsing mode
	// contains filtered or unexported fields
}

Parser holds the parser's internal state while consuming a given token.

func NewParser

func NewParser(r io.Reader) *Parser

NewParser returns a Parser from the given io.Reader.

func (*Parser) Err

func (p *Parser) Err() error

func (*Parser) Parse

func (p *Parser) Parse() (program Program)

Parse is the entry-point to the parser.

TL-program ::= constr-declarations { --- functions --- fun-declarations | --- types --- constr-declarations }

type Program

type Program struct {
	Constructors []ConstrDecl

	// Optional
	Functions []FuncDecl
	Types     []ConstrDecl
}

Program represents a TL program.

https://core.telegram.org/mtproto/TL-formal

type ResultType

type ResultType struct{}

type Scanner

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

Scanner implements a TL (Type Language) lexer.

func NewScanner

func NewScanner(r io.Reader) *Scanner

NewScanner returns a Scanner which tokenizes a TL program

func (*Scanner) Err

func (s *Scanner) Err() error

Err returns the first non-EOF error that was encountered by the Scanner.

func (*Scanner) Next

func (s *Scanner) Next() rune

Next reads and returns the next rune from the underlying reader.

func (*Scanner) Scan

func (s *Scanner) Scan() Token

Scan returns the next token from the underlying reader.

type Token

type Token struct {
	// Type of token
	Token Item

	// Literal value of token
	Literal string
}

Token represents a lexical token.

func (Token) HasName

func (t Token) HasName() bool

HasName reports whether the token literal is lc-ident-full.

func (Token) HasNamespace

func (t Token) HasNamespace() bool

HasNamespace reports whether the token literal is lc-ident-ns or uc-ident-ns.

func (Token) String

func (t Token) String() string

type TypeIdent

type TypeIdent struct {
	Name string
}

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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