ast

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: May 31, 2023 License: MIT Imports: 2 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DecoratorNameToString = map[DecoratorName]string{
		Public: "public", Read: "read", Call: "call", Delegate: "delegate",
	}
	StringToDecoratorName = map[string]DecoratorName{
		"public": Public, "read": Read, "call": Call, "delegate": Delegate,
	}
)
View Source
var (
	OperatorToString = map[Operator]string{
		Not: "!", BitNot: "~", Exponent: "**", Multiply: "*", Divide: "/", Modulo: "%",
		Add: "+", Subtract: "-", ShiftLeft: "<<", ShiftRight: ">>", BitAnd: "&", BitXor: "^",
		BitOr: "|", LessThan: "<", GreaterThan: ">", LessThanOrEqual: "<=", GreaterThanOrEqual: ">=",
		Equal: "==", NotEqual: "!=", And: "&&", Or: "||", AssignSub: "-=", AssignAdd: "+=", Assign: "=",
	}
	StringToOperator = map[string]Operator{
		"!": Not, "~": BitNot, "**": Exponent, "*": Multiply, "/": Divide, "%": Modulo,
		"+": Add, "-": Subtract, "<<": ShiftLeft, ">>": ShiftRight, "&": BitAnd, "^": BitXor,
		"|": BitOr, "<": LessThan, ">": GreaterThan, "<=": LessThanOrEqual, ">=": GreaterThanOrEqual,
		"==": Equal, "!=": NotEqual, "&&": And, "||": Or, "-=": AssignSub, "+=": AssignAdd, "=": Assign,
	}
)
View Source
var (
	OrderToString = map[Order]string{Asc: "asc", Desc: "desc"}
	StringToOrder = map[string]Order{"asc": Asc, "desc": Desc}
)
View Source
var (
	TypeToString = map[BasicType]string{
		String: "string", Number: "number", Boolean: "boolean", Bytes: "bytes",
		PublicKey: "PublicKey", Record: "record",
	}
	StringToType = map[string]BasicType{
		"string": String, "number": Number, "boolean": Boolean, "bytes": Bytes,
		"PublicKey": PublicKey, "record": Record,
	}
)

Functions

This section is empty.

Types

type BasicType

type BasicType int
const (
	String BasicType = iota + 1
	Number
	Boolean
	Bytes
	PublicKey
	Record
)

func (*BasicType) Parse

func (t *BasicType) Parse(lex *lexer.PeekingLexer) error

func (BasicType) String

func (t BasicType) String() string

type Collection

type Collection struct {
	Decorators []*Decorator `parser:"( @@* )?"`
	Name       string       `parser:"'collection' @Ident"`
	Items      []*Item      `parser:"'{' @@* '}'"`
}

type CompoundStatement

type CompoundStatement struct {
	If    *If    `parser:"@@"`
	While *While `parser:"| @@"`
	For   *For   `parser:"| @@"`
}

type Decorator added in v0.0.2

type Decorator struct {
	Name      DecoratorName `parser:"'@' @@"`
	Arguments []string      `parser:"( '(' @Ident ')' )?"`
}

type DecoratorName added in v0.0.2

type DecoratorName int
const (
	Public DecoratorName = iota + 1
	Read
	Call
	Delegate
)

func (*DecoratorName) Parse added in v0.0.2

func (d *DecoratorName) Parse(lex *lexer.PeekingLexer) error

func (DecoratorName) String added in v0.0.2

func (d DecoratorName) String() string

type Expression

type Expression struct {
	Left     *Value   `parser:"@@"`
	Operator Operator `parser:"( @@ )?"`
	Right    *Value   `parser:"( @@ )?"`
}

type Field

type Field struct {
	Name     string `parser:"@Ident"`
	Optional bool   `parser:"@'?'?"`
	Type     Type   `parser:"':' @@"`
}

type For

type For struct {
	Initial    *ForInitial  `parser:"'for' '(' @@ ';'"`
	Condition  *Expression  `parser:"@@ ';'"`
	Post       *Expression  `parser:"@@ ')'"`
	Statements []*Statement `parser:"'{' @@* '}'"`
}

type ForInitial

type ForInitial struct {
	Let        *Let        `parser:"@@"`
	Expression *Expression `parser:"| @@"`
}

type Function

type Function struct {
	Name       string       `parser:"( 'function' )? @Ident '('"`
	Parameters []*Field     `parser:"( @@ ( ',' @@ )* )? ')'"`
	ReturnType Type         `parser:"( ':' @@ )?"`
	Statements []*Statement `parser:"'{' ( @@* )? '}'"`
}

type If

type If struct {
	Condition *Expression         `parser:"'if' '(' @@ ')'"`
	Statement *StatementsOrSimple `parser:"( @@ )?"`
	Else      *StatementsOrSimple `parser:"( 'else' @@ )?"`
}

type Index

type Index struct {
	Fields []*IndexField `parser:"'@' 'index' '(' ( @@ ( ',' @@ )* )? ')'"`
}

type IndexField

type IndexField struct {
	Name  string `parser:"( '[' )? ( @Ident )"`
	Order Order  `parser:"( ',' @@ ']' )?"`
}

type Item

type Item struct {
	Decorators []*Decorator `parser:"( @@* )?"`
	Function   *Function    `parser:"@@"`
	Field      *Field       `parser:"| @@ ';'"`
	Index      *Index       `parser:"| @@ ';'"`
}

type Let

type Let struct {
	Ident      string      `parser:"'let' @Ident '='"`
	Expression *Expression `parser:"@@"`
}

type Map

type Map struct {
	Key   BasicType `parser:"'map' '<' @@ ','"`
	Value Type      `parser:"@@ '>'"`
}

type Node added in v0.0.3

type Node struct {
	Collection *Collection `parser:"@@"   json:"collection,omitempty"`
	Function   *Function   `parser:"| @@" json:"function,omitempty"`
}

type Operator

type Operator int
const (
	Not Operator = iota + 1
	BitNot
	Exponent
	Multiply
	Divide
	Modulo
	Add
	Subtract
	ShiftLeft
	ShiftRight
	BitAnd
	BitXor
	BitOr
	LessThan
	GreaterThan
	LessThanOrEqual
	GreaterThanOrEqual
	Equal
	NotEqual
	And
	Or
	AssignSub
	AssignAdd
	Assign
)

func (*Operator) Parse

func (o *Operator) Parse(lex *lexer.PeekingLexer) error

func (Operator) String

func (o Operator) String() string

type Order

type Order int
const (
	Asc Order = iota
	Desc
)

func (*Order) Parse

func (o *Order) Parse(lex *lexer.PeekingLexer) error

func (Order) String

func (o Order) String() string

type Program

type Program struct {
	Nodes []*Node `parser:"@@*" json:"nodes,omitempty"`
}

type SimpleStatement

type SimpleStatement struct {
	Small *SmallStatement `parser:"@@ ';'"`
}

type SmallStatement

type SmallStatement struct {
	Break      bool        `parser:"( @'break'? )!"`
	Return     *Expression `parser:"| 'return' @@"`
	Throw      *Expression `parser:"| 'throw' @@"`
	Let        *Let        `parser:"| @@"`
	Expression *Expression `parser:"| @@"`
}

type Statement

type Statement struct {
	Compound *CompoundStatement `parser:"@@"`
	Simple   *SimpleStatement   `parser:"| @@"`
}

type StatementsOrSimple added in v0.0.2

type StatementsOrSimple struct {
	Statements []*Statement     `parser:"'{' @@* '}'"`
	Simple     *SimpleStatement `parser:"| @@"`
}

type Type

type Type struct {
	Basic   BasicType `parser:"@@"`
	Array   bool      `parser:"@( '[' ']' )?"`
	Map     *Map      `parser:"| @@"`
	Object  []*Field  `parser:"| '{' ( ( @@ ';' )* )? '}'"`
	Foreign string    `parser:"| @Ident"`
}

type Value added in v0.0.2

type Value struct {
	Number  *int        `parser:"@Number"`
	String  *string     `parser:"| @String"`
	Boolean bool        `parser:"| ( @'true' | 'false' )"`
	Ident   *string     `parser:"| @Ident"`
	Sub     *Expression `parser:"| '(' ( @@ )? ')'"`
}

type While

type While struct {
	Condition  *Expression  `parser:"'while' '(' @@ ')'"`
	Statements []*Statement `parser:"'{' @@* '}'"`
}

Jump to

Keyboard shortcuts

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