ast

package
v0.16.2 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2022 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Overview

Package ast provides TTCN-3 syntax tree nodes and functions for tree traversal.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Inspect

func Inspect(node Node, f func(Node) bool)

Inspect traverses an AST in depth-first order: It starts by calling f(node); node must not be nil. If f returns true, Inspect invokes f recursively for each of the non-nil children of node, followed by a call of f(nil).

func IsNil added in v0.16.2

func IsNil(n Node) bool

IsNil returns true if the node is nil.

func Name

func Name(n Node) string

Name returns the name of a Node. If the node has no name (like statements) Name will return an empty string.

func Walk

func Walk(v Visitor, node Node)

Walk traverses an AST in depth-first order: It starts by calling v.Visit(node); node must not be nil. If the visitor w returned by v.Visit(node) is not nil, Walk is invoked recursively with visitor w for each of the non-nil children of node, followed by a call of w.Visit(nil).

func WalkModuleDefs

func WalkModuleDefs(fun func(def *ModuleDef) bool, nodes ...Node)

WalkModuleDefs calls fun for every module definition.

Types

type AltStmt

type AltStmt struct {
	Tok  Token      // ALT or INTERLEAVE
	Body *BlockStmt // Block statement with alternations
}

A AltStmt represents an alternative statement.

func (*AltStmt) End

func (x *AltStmt) End() loc.Pos

func (*AltStmt) LastTok

func (x *AltStmt) LastTok() *Token

func (*AltStmt) Pos

func (x *AltStmt) Pos() loc.Pos

type ApplyFunc

type ApplyFunc func(*Cursor) bool

An ApplyFunc is invoked by Apply for each node n, even if n is nil, before and/or after the node's children, using a Cursor describing the current node and providing operations on it.

The return value of ApplyFunc controls the syntax tree traversal. See Apply for details.

type BehaviourSpec

type BehaviourSpec struct {
	Kind   Token       // TESTCASE, FUNCTION, ALTSTEP
	Params *FormalPars // Parameter list or nil
	RunsOn *RunsOnSpec // runs on spec or nil
	System *SystemSpec // system spec or nil
	Return *ReturnSpec // return value spec or nil
}

A BehaviourSpec represents a behaviour type specification.

func (*BehaviourSpec) End

func (x *BehaviourSpec) End() loc.Pos

func (*BehaviourSpec) LastTok

func (x *BehaviourSpec) LastTok() *Token

func (*BehaviourSpec) Pos

func (x *BehaviourSpec) Pos() loc.Pos

type BehaviourTypeDecl

type BehaviourTypeDecl struct {
	TypeTok  Token // Position of "type"
	Kind     Token // TESTCASE, ALTSTEP, FUNCTION
	Name     *Ident
	TypePars *FormalPars
	Params   *FormalPars // Formal parameter list
	RunsOn   *RunsOnSpec // Optional runs-on spec
	System   *SystemSpec // Optional system spec
	Return   *ReturnSpec // Optional return spec
	With     *WithSpec
}

A BehaviourTypeDecl represents a named behaviour type.

func (*BehaviourTypeDecl) End

func (x *BehaviourTypeDecl) End() loc.Pos

func (*BehaviourTypeDecl) LastTok

func (x *BehaviourTypeDecl) LastTok() *Token

func (*BehaviourTypeDecl) Pos

func (x *BehaviourTypeDecl) Pos() loc.Pos

type BinaryExpr

type BinaryExpr struct {
	X  Expr  // First operand
	Op Token // Operator token
	Y  Expr  // Second operand
}

A BinaryExpr represents a binary expression. Possible operands are all tokens with a precedence value, TO and FROM.

func (*BinaryExpr) End

func (x *BinaryExpr) End() loc.Pos

func (*BinaryExpr) LastTok

func (x *BinaryExpr) LastTok() *Token

func (*BinaryExpr) Pos

func (x *BinaryExpr) Pos() loc.Pos

type BlockStmt

type BlockStmt struct {
	LBrace Token  // Position of "{"
	Stmts  []Stmt // List of statements
	RBrace Token  // Position of "}"
}

A BlockStmt represents a curly braces enclosed list of statements.

func (*BlockStmt) End

func (x *BlockStmt) End() loc.Pos

func (*BlockStmt) LastTok

func (x *BlockStmt) LastTok() *Token

func (*BlockStmt) Pos

func (x *BlockStmt) Pos() loc.Pos

type BranchStmt

type BranchStmt struct {
	Tok   Token  // REPEAT, BREAK, CONTINUE, LABEL, GOTO
	Label *Ident // Label literal or nil
}

A BranchStmt represents a branch statement.

func (*BranchStmt) End

func (x *BranchStmt) End() loc.Pos

func (*BranchStmt) LastTok

func (x *BranchStmt) LastTok() *Token

func (*BranchStmt) Pos

func (x *BranchStmt) Pos() loc.Pos

type CallExpr

type CallExpr struct {
	Fun  Expr       // Function expression
	Args *ParenExpr // Function arguments
}

A CallExpr represents a regular function call.

func (*CallExpr) End

func (x *CallExpr) End() loc.Pos

func (*CallExpr) LastTok

func (x *CallExpr) LastTok() *Token

func (*CallExpr) Pos

func (x *CallExpr) Pos() loc.Pos

type CallStmt

type CallStmt struct {
	Stmt Stmt       // "call" statement
	Body *BlockStmt // Block statement with alternations
}

A CallStmt represents a "call" statement with communication-block.

func (*CallStmt) End

func (x *CallStmt) End() loc.Pos

func (*CallStmt) LastTok

func (x *CallStmt) LastTok() *Token

func (*CallStmt) Pos

func (x *CallStmt) Pos() loc.Pos

type CaseClause

type CaseClause struct {
	Tok  Token      // Position of "case"
	Case *ParenExpr // nil means else-case
	Body *BlockStmt // Case body
}

A CaseClause represents a case clause.

func (*CaseClause) End

func (x *CaseClause) End() loc.Pos

func (*CaseClause) LastTok

func (x *CaseClause) LastTok() *Token

func (*CaseClause) Pos

func (x *CaseClause) Pos() loc.Pos

type CommClause

type CommClause struct {
	LBrack Token      // Position of '['
	X      Expr       // Conditional guard expression or nil
	Else   Token      // Else-clause of nil
	RBrack Token      // Position of ']'
	Comm   Stmt       // Communication statement
	Body   *BlockStmt // Body of nil
}

A CommClause represents communication clauses used by alt, interleave or check.

func (*CommClause) End

func (x *CommClause) End() loc.Pos

func (*CommClause) LastTok

func (x *CommClause) LastTok() *Token

func (*CommClause) Pos

func (x *CommClause) Pos() loc.Pos

type ComponentTypeDecl

type ComponentTypeDecl struct {
	TypeTok    Token
	CompTok    Token
	Name       *Ident
	TypePars   *FormalPars
	ExtendsTok Token
	Extends    []Expr
	Body       *BlockStmt
	With       *WithSpec
}

func (*ComponentTypeDecl) End

func (x *ComponentTypeDecl) End() loc.Pos

func (*ComponentTypeDecl) LastTok

func (x *ComponentTypeDecl) LastTok() *Token

func (*ComponentTypeDecl) Pos

func (x *ComponentTypeDecl) Pos() loc.Pos

type CompositeLiteral

type CompositeLiteral struct {
	LBrace Token  // Position of "{"
	List   []Expr // Expression list
	RBrace Token  // Position of "{"
}

A CompositeLiteral represents composite literals, e.g. "{x:=23, y:=5}".

func (*CompositeLiteral) End

func (x *CompositeLiteral) End() loc.Pos

func (*CompositeLiteral) LastTok

func (x *CompositeLiteral) LastTok() *Token

func (*CompositeLiteral) Pos

func (x *CompositeLiteral) Pos() loc.Pos

type ControlPart

type ControlPart struct {
	Name *Ident
	Body *BlockStmt
	With *WithSpec
}

func (*ControlPart) End

func (x *ControlPart) End() loc.Pos

func (*ControlPart) LastTok

func (x *ControlPart) LastTok() *Token

func (*ControlPart) Pos

func (x *ControlPart) Pos() loc.Pos

type Cursor

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

A Cursor describes a node encountered during Apply. Information about the node and its parent is available from the Node, Parent, Name, and Index methods.

If p is a variable of type and value of the current parent node c.Parent(), and f is the field identifier with name c.Name(), the following invariants hold:

p.f            == c.Node()  if c.Index() <  0 p.f[c.Index()] == c.Node()
if c.Index() >= 0

The methods Replace, Delete, InsertBefore, and InsertAfter can be used to change the AST without disrupting Apply.

func (*Cursor) Delete

func (c *Cursor) Delete()

Delete deletes the current Node from its containing slice. If the current Node is not part of a slice, Delete panics. As a special case, if the current node is a package file, Delete removes it from the package's Files map.

func (*Cursor) Index

func (c *Cursor) Index() int

Index reports the index >= 0 of the current Node in the slice of Nodes that contains it, or a value < 0 if the current Node is not part of a slice. The index of the current node changes if InsertBefore is called while processing the current node.

func (*Cursor) InsertAfter

func (c *Cursor) InsertAfter(n Node)

InsertAfter inserts n after the current Node in its containing slice. If the current Node is not part of a slice, InsertAfter panics. Apply does not walk n.

func (*Cursor) InsertBefore

func (c *Cursor) InsertBefore(n Node)

InsertBefore inserts n before the current Node in its containing slice. If the current Node is not part of a slice, InsertBefore panics. Apply will not walk n.

func (*Cursor) Name

func (c *Cursor) Name() string

Name returns the name of the parent Node field that contains the current Node. If the parent is a *Package and the current Node is a *File, Name returns the filename for the current Node.

func (*Cursor) Node

func (c *Cursor) Node() Node

Node returns the current Node.

func (*Cursor) Parent

func (c *Cursor) Parent() Node

Parent returns the parent of the current Node.

func (*Cursor) Replace

func (c *Cursor) Replace(n Node)

Replace replaces the current Node with n. The replacement node is not walked by Apply.

type Decl

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

All declaration nodes implement the Decl interface.

type DeclStmt

type DeclStmt struct {
	Decl Decl
}

A DeclStmt represents a value declaration used as statement, lika a local variable declaration.

func (*DeclStmt) End

func (x *DeclStmt) End() loc.Pos

func (*DeclStmt) LastTok

func (x *DeclStmt) LastTok() *Token

func (*DeclStmt) Pos

func (x *DeclStmt) Pos() loc.Pos

type Declarator

type Declarator struct {
	Name      *Ident
	ArrayDef  []*ParenExpr
	AssignTok Token
	Value     Expr
}

A Declarator represents a single varable declaration

func (*Declarator) End

func (x *Declarator) End() loc.Pos

func (*Declarator) LastTok

func (x *Declarator) LastTok() *Token

func (*Declarator) Pos

func (x *Declarator) Pos() loc.Pos

type DecmatchExpr

type DecmatchExpr struct {
	Tok    Token // Position of "decmatch"
	Params Expr  // Parameter list or nil
	X      Expr  // Template expression
}

A DecmatchExpr represents a "decmatch" expression.

func (*DecmatchExpr) End

func (x *DecmatchExpr) End() loc.Pos

func (*DecmatchExpr) LastTok

func (x *DecmatchExpr) LastTok() *Token

func (*DecmatchExpr) Pos

func (x *DecmatchExpr) Pos() loc.Pos

type DecodedExpr

type DecodedExpr struct {
	Tok    Token // Position of "decoded"
	Params Expr  // Parameter list or nil
	X      Expr  // Template expression
}

A DecodedExpr represents a "@decoded" expression.

func (*DecodedExpr) End

func (x *DecodedExpr) End() loc.Pos

func (*DecodedExpr) LastTok

func (x *DecodedExpr) LastTok() *Token

func (*DecodedExpr) Pos

func (x *DecodedExpr) Pos() loc.Pos

type DefKindExpr

type DefKindExpr struct {
	Kind Token  // Definition kind, "type", "group", ...
	List []Expr // List of identifiers or except-expressions
}

A DefKindExpr represents a definition kind expression, used by imports and with-attributes.

func (*DefKindExpr) End

func (x *DefKindExpr) End() loc.Pos

func (*DefKindExpr) LastTok

func (x *DefKindExpr) LastTok() *Token

func (*DefKindExpr) Pos

func (x *DefKindExpr) Pos() loc.Pos

type DoWhileStmt

type DoWhileStmt struct {
	DoTok    Token      // Position of "do"
	Body     *BlockStmt // Loop-Body
	WhileTok Token      // Position of "while"
	Cond     *ParenExpr // Conditional expression
}

A DoWhileStmt represents a do-while statement.

func (*DoWhileStmt) End

func (x *DoWhileStmt) End() loc.Pos

func (*DoWhileStmt) LastTok

func (x *DoWhileStmt) LastTok() *Token

func (*DoWhileStmt) Pos

func (x *DoWhileStmt) Pos() loc.Pos

type EnumSpec

type EnumSpec struct {
	Tok    Token  // Position of "enumerated"
	LBrace Token  // Position of "{"
	Enums  []Expr // Enum list
	RBrace Token  // Position of "}"
}

A EnumSpec represents a enumeration type specification.

func (*EnumSpec) End

func (x *EnumSpec) End() loc.Pos

func (*EnumSpec) LastTok

func (x *EnumSpec) LastTok() *Token

func (*EnumSpec) Pos

func (x *EnumSpec) Pos() loc.Pos

type EnumTypeDecl

type EnumTypeDecl struct {
	TypeTok  Token // Position of "type"
	EnumTok  Token // Position of "ENUMERATED"
	Name     *Ident
	TypePars *FormalPars
	LBrace   Token  // Position of "{"
	Enums    []Expr // Enum list
	RBrace   Token  // Position of "}"
	With     *WithSpec
}

A EnumTypeDecl represents a named enum type.

func (*EnumTypeDecl) End

func (x *EnumTypeDecl) End() loc.Pos

func (*EnumTypeDecl) LastTok

func (x *EnumTypeDecl) LastTok() *Token

func (*EnumTypeDecl) Pos

func (x *EnumTypeDecl) Pos() loc.Pos

type ErrorNode

type ErrorNode struct {
	From, To Token
}

func (ErrorNode) End

func (x ErrorNode) End() loc.Pos

func (ErrorNode) LastTok

func (x ErrorNode) LastTok() *Token

func (ErrorNode) Pos

func (x ErrorNode) Pos() loc.Pos

type ExceptExpr

type ExceptExpr struct {
	X         Expr   // (Qualified) identifier or "all"
	ExceptTok Token  // Position of "except"
	LBrace    Token  // Position of "{" or nil
	List      []Expr // List of identifiers or DefKindExprs to exclude
	RBrace    Token  // Position of "}" or nil
}

A ExceptExpr is used by DefKindExpr to express exlusion of specific defintions.

func (*ExceptExpr) End

func (x *ExceptExpr) End() loc.Pos

func (*ExceptExpr) LastTok

func (x *ExceptExpr) LastTok() *Token

func (*ExceptExpr) Pos

func (x *ExceptExpr) Pos() loc.Pos

type Expr

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

All expression nodes implement the Expr interface.

type ExprStmt

type ExprStmt struct {
	Expr Expr
}

An ExprStmt represents a expression used as statement, like an assignment or function call.

func (*ExprStmt) End

func (x *ExprStmt) End() loc.Pos

func (*ExprStmt) LastTok

func (x *ExprStmt) LastTok() *Token

func (*ExprStmt) Pos

func (x *ExprStmt) Pos() loc.Pos

type Field

type Field struct {
	DefaultTok       Token        // Position of "@default" or nil
	Type             TypeSpec     // Type
	Name             *Ident       // Name
	ArrayDef         []*ParenExpr // Array definitions
	TypePars         *FormalPars
	ValueConstraint  *ParenExpr  // Value constraint or nil
	LengthConstraint *LengthExpr // Length constraint or nil
	Optional         Token       // Position of "optional" or nil
}

A Field represents a named struct member or sub type definition

func (*Field) End

func (x *Field) End() loc.Pos

func (*Field) LastTok

func (x *Field) LastTok() *Token

func (*Field) Pos

func (x *Field) Pos() loc.Pos

type ForStmt

type ForStmt struct {
	Tok      Token      // Position of "for"
	LParen   Token      // Position of "("
	Init     Stmt       // Initialization statement
	InitSemi Token      // Position of ";"
	Cond     Expr       // Conditional expression
	CondSemi Token      // Position of ";"
	Post     Stmt       // Post iteration statement
	RParen   Token      // Position of ")"
	Body     *BlockStmt // Loop-Body
}

A ForStmt represents a "for" statement.

func (*ForStmt) End

func (x *ForStmt) End() loc.Pos

func (*ForStmt) LastTok

func (x *ForStmt) LastTok() *Token

func (*ForStmt) Pos

func (x *ForStmt) Pos() loc.Pos

type FormalPar

type FormalPar struct {
	Direction           Token
	TemplateRestriction *RestrictionSpec
	Modif               Token
	Type                Expr
	Name                *Ident
	ArrayDef            []*ParenExpr
	AssignTok           Token
	Value               Expr
}

func (*FormalPar) End

func (x *FormalPar) End() loc.Pos

func (*FormalPar) LastTok

func (x *FormalPar) LastTok() *Token

func (*FormalPar) Pos

func (x *FormalPar) Pos() loc.Pos

type FormalPars

type FormalPars struct {
	LParen Token
	List   []*FormalPar
	RParen Token
}

func (*FormalPars) End

func (x *FormalPars) End() loc.Pos

func (*FormalPars) LastTok

func (x *FormalPars) LastTok() *Token

func (*FormalPars) Pos

func (x *FormalPars) Pos() loc.Pos

type FriendDecl

type FriendDecl struct {
	FriendTok Token
	ModuleTok Token
	Module    *Ident
	With      *WithSpec
}

func (*FriendDecl) End

func (x *FriendDecl) End() loc.Pos

func (*FriendDecl) LastTok

func (x *FriendDecl) LastTok() *Token

func (*FriendDecl) Pos

func (x *FriendDecl) Pos() loc.Pos

type FromExpr

type FromExpr struct {
	Kind    Token // ANY or ALL
	FromTok Token // Position of "from"
	X       Expr  // Expression
}

A FromExpr represents a "from" expression, like "any from a".

func (*FromExpr) End

func (x *FromExpr) End() loc.Pos

func (*FromExpr) LastTok

func (x *FromExpr) LastTok() *Token

func (*FromExpr) Pos

func (x *FromExpr) Pos() loc.Pos

type FuncDecl

type FuncDecl struct {
	External Token // Position of "external" or nil
	Kind     Token // TESTCASE, ALTSTEP, FUNCTION
	Name     *Ident
	Modif    Token // Position of "@deterministic" or nil
	TypePars *FormalPars
	Params   *FormalPars // Formal parameter list or nil
	RunsOn   *RunsOnSpec // Optional runs-on-spec
	Mtc      *MtcSpec    // Optional mtc-spec
	System   *SystemSpec // Optional system-spec
	Return   *ReturnSpec // Optional return-spec
	Body     *BlockStmt  // Body or nil
	With     *WithSpec
}

A FuncDecl represents a behaviour definition.

func (*FuncDecl) End

func (x *FuncDecl) End() loc.Pos

func (*FuncDecl) IsTest

func (x *FuncDecl) IsTest() bool

func (*FuncDecl) LastTok

func (x *FuncDecl) LastTok() *Token

func (*FuncDecl) Pos

func (x *FuncDecl) Pos() loc.Pos

type GroupDecl

type GroupDecl struct {
	Tok    Token
	Name   *Ident
	LBrace Token
	Defs   []*ModuleDef
	RBrace Token
	With   *WithSpec
}

func (*GroupDecl) End

func (x *GroupDecl) End() loc.Pos

func (*GroupDecl) LastTok

func (x *GroupDecl) LastTok() *Token

func (*GroupDecl) Pos

func (x *GroupDecl) Pos() loc.Pos

type Ident

type Ident struct {
	IsName bool  // true if this is a name, false if it is a reference
	Tok    Token // first identifier token
	Tok2   Token `json:",omitempty"` // optional second identifier token, e.g. for "any port"
}

Ident represents an identifier.

func (*Ident) End

func (x *Ident) End() loc.Pos

func (*Ident) LastTok

func (x *Ident) LastTok() *Token

func (*Ident) Pos

func (x *Ident) Pos() loc.Pos

func (*Ident) String

func (x *Ident) String() string

type IfStmt

type IfStmt struct {
	Tok     Token      // Position of "if"
	Cond    Expr       // Conditional expression
	Then    *BlockStmt // True branch
	ElseTok Token      // Position of "else" or nil
	Else    Stmt       // Else branch
}

A IfStmt represents a conditional statement.

func (*IfStmt) End

func (x *IfStmt) End() loc.Pos

func (*IfStmt) LastTok

func (x *IfStmt) LastTok() *Token

func (*IfStmt) Pos

func (x *IfStmt) Pos() loc.Pos

type ImportDecl

type ImportDecl struct {
	ImportTok Token
	FromTok   Token
	Module    *Ident
	Language  *LanguageSpec
	LBrace    Token
	List      []*DefKindExpr
	RBrace    Token
	With      *WithSpec
}

func (*ImportDecl) End

func (x *ImportDecl) End() loc.Pos

func (*ImportDecl) LastTok

func (x *ImportDecl) LastTok() *Token

func (*ImportDecl) Pos

func (x *ImportDecl) Pos() loc.Pos

type IndexExpr

type IndexExpr struct {
	X      Expr  // Preceding expression (might be nil)
	LBrack Token // Position of "["
	Index  Expr  // Actuall index expression (might be "-")
	RBrack Token // Position of "]"
}

A IndexExpr represents an expression followed by an index.

func (*IndexExpr) End

func (x *IndexExpr) End() loc.Pos

func (*IndexExpr) LastTok

func (x *IndexExpr) LastTok() *Token

func (*IndexExpr) Pos

func (x *IndexExpr) Pos() loc.Pos

type LanguageSpec

type LanguageSpec struct {
	Tok  Token
	List []Token
}

func (*LanguageSpec) End

func (x *LanguageSpec) End() loc.Pos

func (*LanguageSpec) LastTok

func (x *LanguageSpec) LastTok() *Token

func (*LanguageSpec) Pos

func (x *LanguageSpec) Pos() loc.Pos

type LengthExpr

type LengthExpr struct {
	X    Expr       // Preceding expression
	Len  Token      // Position of "length" keyword
	Size *ParenExpr // Size expression
}

A LengthExpr represents a length expression.

func (*LengthExpr) End

func (x *LengthExpr) End() loc.Pos

func (*LengthExpr) LastTok

func (x *LengthExpr) LastTok() *Token

func (*LengthExpr) Pos

func (x *LengthExpr) Pos() loc.Pos

type ListSpec

type ListSpec struct {
	Kind     Token       // RECORD, SET
	Length   *LengthExpr // Length constraint or nil
	OfTok    Token       // Position of "of"
	ElemType TypeSpec    // Element type specification
}

A ListSpec represents a list type specification.

func (*ListSpec) End

func (x *ListSpec) End() loc.Pos

func (*ListSpec) LastTok

func (x *ListSpec) LastTok() *Token

func (*ListSpec) Pos

func (x *ListSpec) Pos() loc.Pos

type ModifiesExpr

type ModifiesExpr struct {
	Tok    Token // Position of "modifies"
	X      Expr  // Base template expression
	Assign Token // Position of ":="
	Y      Expr  // Modifying expression
}

A ModifiesExpr represents a "modifies" expression.

func (*ModifiesExpr) End

func (x *ModifiesExpr) End() loc.Pos

func (*ModifiesExpr) LastTok

func (x *ModifiesExpr) LastTok() *Token

func (*ModifiesExpr) Pos

func (x *ModifiesExpr) Pos() loc.Pos

type Module

type Module struct {
	Tok      Token
	Name     *Ident
	Language *LanguageSpec
	LBrace   Token
	Defs     []*ModuleDef
	RBrace   Token
	With     *WithSpec
}

func (*Module) End

func (x *Module) End() loc.Pos

func (*Module) LastTok

func (x *Module) LastTok() *Token

func (*Module) Pos

func (x *Module) Pos() loc.Pos

type ModuleDef

type ModuleDef struct {
	Visibility Token
	Def        Node
}

func (*ModuleDef) End

func (x *ModuleDef) End() loc.Pos

func (*ModuleDef) LastTok

func (x *ModuleDef) LastTok() *Token

func (*ModuleDef) Pos

func (x *ModuleDef) Pos() loc.Pos

type ModuleParameterGroup

type ModuleParameterGroup struct {
	Tok    Token        // Position of "modulepar"
	LBrace Token        // Position of "{"
	Decls  []*ValueDecl // Module parameter list
	RBrace Token        // Position of "}"
	With   *WithSpec
}

A ModuleParameterGroup represents a deprecated module parameter list

func (*ModuleParameterGroup) End

func (x *ModuleParameterGroup) End() loc.Pos

func (*ModuleParameterGroup) LastTok

func (x *ModuleParameterGroup) LastTok() *Token

func (*ModuleParameterGroup) Pos

func (x *ModuleParameterGroup) Pos() loc.Pos

type MtcSpec

type MtcSpec struct {
	Tok  Token
	Comp Expr
}

func (*MtcSpec) End

func (x *MtcSpec) End() loc.Pos

func (*MtcSpec) LastTok

func (x *MtcSpec) LastTok() *Token

func (*MtcSpec) Pos

func (x *MtcSpec) Pos() loc.Pos

type Node

type Node interface {
	Pos() loc.Pos
	End() loc.Pos
	LastTok() *Token
}

All node types implement the Node interface.

func Apply

func Apply(root Node, pre, post ApplyFunc) (result Node)

Apply traverses a syntax tree recursively, starting with root, and calling pre and post for each node as described below. Apply returns the syntax tree, possibly modified.

If pre is not nil, it is called for each node before the node's children are traversed (pre-order). If pre returns false, no children are traversed, and post is not called for that node.

If post is not nil, and a prior call of pre didn't return false, post is called for each node after its children are traversed (post-order). If post returns false, traversal is terminated and Apply returns immediately.

Only fields that refer to AST nodes are considered children; i.e., token.Pos, Scopes, Objects, and fields of basic types (strings, etc.) are ignored.

Children are traversed in the order in which they appear in the respective node's struct definition. A package's files are traversed in the filenames' alphabetical order.

func Children added in v0.13.0

func Children(n Node) []Node

func FindChildOf added in v0.16.2

func FindChildOf(n Node, pos loc.Pos) Node

FindChildOfType returns the first direct child of the give node, enclosing given position.

func Parents added in v0.14.0

func Parents(tgt, root Node) []Node

type NodeList

type NodeList struct {
	Nodes []Node
}

func (*NodeList) End

func (n *NodeList) End() loc.Pos

func (*NodeList) LastTok

func (n *NodeList) LastTok() *Token

func (*NodeList) Pos

func (n *NodeList) Pos() loc.Pos

type ParamExpr

type ParamExpr struct {
	X   Expr  // map or unmap statement
	Tok Token // Position "param"
	Y   Expr  // Additional arguments for map/unmap
}

A ParamExpr represents parametrized map and unmap statements.

func (*ParamExpr) End

func (x *ParamExpr) End() loc.Pos

func (*ParamExpr) LastTok

func (x *ParamExpr) LastTok() *Token

func (*ParamExpr) Pos

func (x *ParamExpr) Pos() loc.Pos

type ParametrizedIdent

type ParametrizedIdent struct {
	Ident  *Ident     // Identifier
	Params *ParenExpr // Parameter list
}

ParametrizedIdent represents a paremetrized identifier, e.g. "f<charstring>".

func (*ParametrizedIdent) End

func (x *ParametrizedIdent) End() loc.Pos

func (*ParametrizedIdent) LastTok

func (x *ParametrizedIdent) LastTok() *Token

func (*ParametrizedIdent) Pos

func (x *ParametrizedIdent) Pos() loc.Pos

type ParenExpr

type ParenExpr struct {
	LParen Token  // Position of "(", "<", "["
	List   []Expr // Expression list
	RParen Token  // Position of ")", ">", "]"
}

A ParenExpr represents parenthized expression lists.

func (*ParenExpr) End

func (x *ParenExpr) End() loc.Pos

func (*ParenExpr) LastTok

func (x *ParenExpr) LastTok() *Token

func (*ParenExpr) Pos

func (x *ParenExpr) Pos() loc.Pos

type PatternExpr

type PatternExpr struct {
	Tok    Token // Position of "pattern"
	NoCase Token // Position of "@nocase" of nil
	X      Expr  // Pattern expression
}

A PatternExpr represents a "pattern" expression.

func (*PatternExpr) End

func (x *PatternExpr) End() loc.Pos

func (*PatternExpr) LastTok

func (x *PatternExpr) LastTok() *Token

func (*PatternExpr) Pos

func (x *PatternExpr) Pos() loc.Pos

type PortAttribute

type PortAttribute struct {
	Kind  Token // IN, OUT, INOUT, ADDRESS
	Types []Expr
}

func (*PortAttribute) End

func (x *PortAttribute) End() loc.Pos

func (*PortAttribute) LastTok

func (x *PortAttribute) LastTok() *Token

func (*PortAttribute) Pos

func (x *PortAttribute) Pos() loc.Pos

type PortMapAttribute

type PortMapAttribute struct {
	MapTok   Token // MAP, UNMAP
	ParamTok Token
	Params   *FormalPars
}

func (*PortMapAttribute) End

func (x *PortMapAttribute) End() loc.Pos

func (*PortMapAttribute) LastTok

func (x *PortMapAttribute) LastTok() *Token

func (*PortMapAttribute) Pos

func (x *PortMapAttribute) Pos() loc.Pos

type PortTypeDecl

type PortTypeDecl struct {
	TypeTok  Token
	PortTok  Token
	Name     *Ident
	TypePars *FormalPars
	Kind     Token // MIXED, MESSAGE, PROCEDURE
	Realtime Token
	LBrace   Token
	Attrs    []Node
	RBrace   Token
	With     *WithSpec
}

func (*PortTypeDecl) End

func (x *PortTypeDecl) End() loc.Pos

func (*PortTypeDecl) LastTok

func (x *PortTypeDecl) LastTok() *Token

func (*PortTypeDecl) Pos

func (x *PortTypeDecl) Pos() loc.Pos

type RedirectExpr

type RedirectExpr struct {
	X             Expr   // Preceding redirected expression
	Tok           Token  // Position of "->"
	ValueTok      Token  // Position of "value" or nil
	Value         []Expr // Value expression
	ParamTok      Token  // Position of "param" or nil
	Param         []Expr // Param expression
	SenderTok     Token  // Position of "sender" or nil
	Sender        Expr   // Sender expression
	IndexTok      Token  // Position of "@index" or nil
	IndexValueTok Token  // Position of "value" or nil
	Index         Expr   // Index expression
	TimestampTok  Token  // Position of "timestamp" or nil
	Timestamp     Expr   // Timestamp expression
}

A RedirectExpr represents various redirect expressions

func (*RedirectExpr) End

func (x *RedirectExpr) End() loc.Pos

func (*RedirectExpr) LastTok

func (x *RedirectExpr) LastTok() *Token

func (*RedirectExpr) Pos

func (x *RedirectExpr) Pos() loc.Pos

type RefSpec

type RefSpec struct {
	X Expr
}

A RefSpec represents a type reference.

func (*RefSpec) End

func (x *RefSpec) End() loc.Pos

func (*RefSpec) LastTok

func (x *RefSpec) LastTok() *Token

func (*RefSpec) Pos

func (x *RefSpec) Pos() loc.Pos

type RegexpExpr

type RegexpExpr struct {
	Tok    Token // Position of "regexp"
	NoCase Token // Position of "@nocase" or nil
	X      Expr  // Regex expression
}

A RegexExpr represents a "regexp" expression.

func (*RegexpExpr) End

func (x *RegexpExpr) End() loc.Pos

func (*RegexpExpr) LastTok

func (x *RegexpExpr) LastTok() *Token

func (*RegexpExpr) Pos

func (x *RegexpExpr) Pos() loc.Pos

type RestrictionSpec

type RestrictionSpec struct {
	TemplateTok Token
	LParen      Token
	Tok         Token
	RParen      Token
}

func (*RestrictionSpec) End

func (x *RestrictionSpec) End() loc.Pos

func (*RestrictionSpec) LastTok

func (x *RestrictionSpec) LastTok() *Token

func (*RestrictionSpec) Pos

func (x *RestrictionSpec) Pos() loc.Pos

type ReturnSpec

type ReturnSpec struct {
	Tok         Token
	Restriction *RestrictionSpec
	Modif       Token
	Type        Expr
}

func (*ReturnSpec) End

func (x *ReturnSpec) End() loc.Pos

func (*ReturnSpec) LastTok

func (x *ReturnSpec) LastTok() *Token

func (*ReturnSpec) Pos

func (x *ReturnSpec) Pos() loc.Pos

type ReturnStmt

type ReturnStmt struct {
	Tok    Token // Position of "return"
	Result Expr  // Resulting expression of nil
}

A ReturnStmt represents a return statement.

func (*ReturnStmt) End

func (x *ReturnStmt) End() loc.Pos

func (*ReturnStmt) LastTok

func (x *ReturnStmt) LastTok() *Token

func (*ReturnStmt) Pos

func (x *ReturnStmt) Pos() loc.Pos

type RunsOnSpec

type RunsOnSpec struct {
	RunsTok Token
	OnTok   Token
	Comp    Expr
}

func (*RunsOnSpec) End

func (x *RunsOnSpec) End() loc.Pos

func (*RunsOnSpec) LastTok

func (x *RunsOnSpec) LastTok() *Token

func (*RunsOnSpec) Pos

func (x *RunsOnSpec) Pos() loc.Pos

type SelectStmt

type SelectStmt struct {
	Tok    Token         // Position of "select"
	Union  Token         // Position of "union" or nil
	Tag    *ParenExpr    // Tag expression
	LBrace Token         // Position of "{"
	Body   []*CaseClause // List of case clauses
	RBrace Token         // Position of "}"
}

A SelectStmt represents a select statements.

func (*SelectStmt) End

func (x *SelectStmt) End() loc.Pos

func (*SelectStmt) LastTok

func (x *SelectStmt) LastTok() *Token

func (*SelectStmt) Pos

func (x *SelectStmt) Pos() loc.Pos

type SelectorExpr

type SelectorExpr struct {
	X   Expr  // Preceding expression (might be nil)
	Dot Token // Position of "."
	Sel Expr  // Literal, identifier or reference.
}

A SelectorExpr represents an expression followed by a selector.

func (*SelectorExpr) End

func (x *SelectorExpr) End() loc.Pos

func (*SelectorExpr) LastTok

func (x *SelectorExpr) LastTok() *Token

func (*SelectorExpr) Pos

func (x *SelectorExpr) Pos() loc.Pos

type SignatureDecl

type SignatureDecl struct {
	Tok          Token // Position of "signature"
	Name         *Ident
	TypePars     *FormalPars
	Params       *FormalPars
	NoBlock      Token       // Optional "noblock"
	Return       *ReturnSpec // Optional return-spec
	ExceptionTok Token       // Position of "exeception" or nil
	Exception    *ParenExpr  // Exception list
	With         *WithSpec
}

A SignatureDecl represents a signature type for procedure based communication.

func (*SignatureDecl) End

func (x *SignatureDecl) End() loc.Pos

func (*SignatureDecl) LastTok

func (x *SignatureDecl) LastTok() *Token

func (*SignatureDecl) Pos

func (x *SignatureDecl) Pos() loc.Pos

type Stmt

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

All statement nodes implement the Stmt interface.

type StructSpec

type StructSpec struct {
	Kind   Token    // RECORD, SET, UNION
	LBrace Token    // Position of "{"
	Fields []*Field // Member list
	RBrace Token    // Position of "}"
}

A StructSpec represents a struct type specification.

func (*StructSpec) End

func (x *StructSpec) End() loc.Pos

func (*StructSpec) LastTok

func (x *StructSpec) LastTok() *Token

func (*StructSpec) Pos

func (x *StructSpec) Pos() loc.Pos

type StructTypeDecl

type StructTypeDecl struct {
	TypeTok  Token  // Position of "type"
	Kind     Token  // RECORD, SET, UNION
	Name     *Ident // Name
	TypePars *FormalPars
	LBrace   Token    // Position of "{"
	Fields   []*Field // Member list
	RBrace   Token    // Position of }"
	With     *WithSpec
}

A StructTypeDecl represents a name struct type.

func (*StructTypeDecl) End

func (x *StructTypeDecl) End() loc.Pos

func (*StructTypeDecl) LastTok

func (x *StructTypeDecl) LastTok() *Token

func (*StructTypeDecl) Pos

func (x *StructTypeDecl) Pos() loc.Pos

type SubTypeDecl

type SubTypeDecl struct {
	TypeTok Token  // Position of "type"
	Field   *Field // Field spec
	With    *WithSpec
}

A SubTypeDecl represents a named sub type declaration

func (*SubTypeDecl) End

func (x *SubTypeDecl) End() loc.Pos

func (*SubTypeDecl) LastTok

func (x *SubTypeDecl) LastTok() *Token

func (*SubTypeDecl) Pos

func (x *SubTypeDecl) Pos() loc.Pos

type SystemSpec

type SystemSpec struct {
	Tok  Token
	Comp Expr
}

func (*SystemSpec) End

func (x *SystemSpec) End() loc.Pos

func (*SystemSpec) LastTok

func (x *SystemSpec) LastTok() *Token

func (*SystemSpec) Pos

func (x *SystemSpec) Pos() loc.Pos

type TemplateDecl

type TemplateDecl struct {
	RestrictionSpec
	Modif       Token // "@lazy", "@fuzzy" or nil
	Type        Expr
	Name        *Ident
	TypePars    *FormalPars
	Params      *FormalPars
	ModifiesTok Token
	Base        Expr
	AssignTok   Token
	Value       Expr
	With        *WithSpec
}

func (*TemplateDecl) End

func (x *TemplateDecl) End() loc.Pos

func (*TemplateDecl) LastTok

func (x *TemplateDecl) LastTok() *Token

type Terminal

type Terminal struct {
	Kind token.Kind // Token kind like TESTCASE, SEMICOLON, COMMENT, ...
	Lit  string     // Token values for non-operator tokens
	// contains filtered or unexported fields
}

token functionality shared by Token and Trivia

func (Terminal) End

func (x Terminal) End() loc.Pos

func (*Terminal) IsValid

func (t *Terminal) IsValid() bool

func (Terminal) Pos

func (x Terminal) Pos() loc.Pos

func (*Terminal) String

func (x *Terminal) String() string

type Token

type Token struct {
	Terminal
	LeadingTriv  []Trivia
	TrailingTriv []Trivia
}

A Token represents a TTCN-3 token and implements the Node interface. Tokens are leave-nodes.

func FirstToken

func FirstToken(n Node) *Token

First returns the first valid token of a syntax tree

func NewToken

func NewToken(pos loc.Pos, kind token.Kind, val string) Token

func (*Token) Comments

func (t *Token) Comments() string

Comments concatenates all leading comments into one single string.

func (Token) LastTok

func (t Token) LastTok() *Token

func (Token) MarshalJSON

func (x Token) MarshalJSON() ([]byte, error)

type Trivia

type Trivia struct {
	Terminal
}

Trivia represent the parts of the source text that are largely insignificant for normal understanding of the code, such as whitespace, comments, and preprocessor directives.

func NewTrivia

func NewTrivia(pos loc.Pos, kind token.Kind, val string) Trivia

type TypeSpec

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

All nested types implement TypeSpec interface.

type UnaryExpr

type UnaryExpr struct {
	Op Token // Operator token, like "+", "-", "!", ...
	X  Expr
}

A UnaryExpr represents a unary expresions.

func (*UnaryExpr) End

func (x *UnaryExpr) End() loc.Pos

func (*UnaryExpr) LastTok

func (x *UnaryExpr) LastTok() *Token

func (*UnaryExpr) Pos

func (x *UnaryExpr) Pos() loc.Pos

type ValueDecl

type ValueDecl struct {
	Kind                Token // VAR, CONST, TIMER, PORT, TEMPLATE, MODULEPAR
	TemplateRestriction *RestrictionSpec
	Modif               Token // "@lazy", "@fuzzy" or nil
	Type                Expr
	Decls               []*Declarator
	With                *WithSpec
}

A ValueDecl represents a value declaration.

func (*ValueDecl) End

func (x *ValueDecl) End() loc.Pos

func (*ValueDecl) LastTok

func (x *ValueDecl) LastTok() *Token

func (*ValueDecl) Pos

func (x *ValueDecl) Pos() loc.Pos

type ValueExpr

type ValueExpr struct {
	X   Expr  // Preceding template expression
	Tok Token // Position of "value"
	Y   Expr  // Value expression
}

A ValueExpr represents the return value used by signature based communication.

func (*ValueExpr) End

func (x *ValueExpr) End() loc.Pos

func (*ValueExpr) LastTok

func (x *ValueExpr) LastTok() *Token

func (*ValueExpr) Pos

func (x *ValueExpr) Pos() loc.Pos

type ValueLiteral

type ValueLiteral struct {
	Tok Token
}

A ValueLiteral represents simple literals, like integers, charstrings, ...

func (*ValueLiteral) End

func (x *ValueLiteral) End() loc.Pos

func (*ValueLiteral) LastTok

func (x *ValueLiteral) LastTok() *Token

func (*ValueLiteral) Pos

func (x *ValueLiteral) Pos() loc.Pos

type Visitor

type Visitor interface {
	Visit(node Node) (w Visitor)
}

A Visitor's Visit method is invoked for each node encountered by Walk. If the result visitor w is not nil, Walk visits each of the children of node with the visitor w, followed by a call of w.Visit(nil).

type WhileStmt

type WhileStmt struct {
	Tok  Token      // Position of "while"
	Cond *ParenExpr // Conditional expression
	Body *BlockStmt // Loop-body
}

A WhilStmt represents a "while" statement.

func (*WhileStmt) End

func (x *WhileStmt) End() loc.Pos

func (*WhileStmt) LastTok

func (x *WhileStmt) LastTok() *Token

func (*WhileStmt) Pos

func (x *WhileStmt) Pos() loc.Pos

type WithSpec

type WithSpec struct {
	Tok    Token
	LBrace Token
	List   []*WithStmt
	RBrace Token
}

func (*WithSpec) End

func (x *WithSpec) End() loc.Pos

func (*WithSpec) LastTok

func (x *WithSpec) LastTok() *Token

func (*WithSpec) Pos

func (x *WithSpec) Pos() loc.Pos

type WithStmt

type WithStmt struct {
	Kind     Token
	Override Token
	LParen   Token
	List     []Expr
	RParen   Token
	Value    Expr
}

func (*WithStmt) End

func (x *WithStmt) End() loc.Pos

func (*WithStmt) LastTok

func (x *WithStmt) LastTok() *Token

func (*WithStmt) Pos

func (x *WithStmt) Pos() loc.Pos

Jump to

Keyboard shortcuts

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