syntax

package
v0.17.0 Latest Latest
Warning

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

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

Documentation

Overview

Package syntax provides a fast high fidelity parser for TTCN-3.

Index

Constants

View Source
const (
	AddToken treeEventType = iota
	OpenNode
	CloseNode
)

Variables

View Source
var (
	Nil = Node{}
)

Functions

This section is empty.

Types

type Builder

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

A Builder is used to build a syntax tree. The zero value is ready to use.

func (*Builder) Pop

func (b *Builder) Pop()

Pop finishes a non-terminal. Invalid pop calls will panic.

func (*Builder) Push

func (b *Builder) Push(k Kind) Node

Push pushes appends a new non-terminal of given kind to the syntax tree.

func (*Builder) PushToken

func (b *Builder) PushToken(k Kind, begin int, end int) Node

PushToken appends a new token to the syntax tree.

func (*Builder) SetName

func (b *Builder) SetName(name string)

SetName sets a name for the syntax tree.

type Error

type Error struct {
	Errors []error
}

func (*Error) Error

func (e *Error) Error() string

type Kind

type Kind int32

Kind describes the kind of a syntax node.

const (
	EOF Kind = iota

	Unknown
	Malformed
	Unterminated

	Identifier
	Comment
	Preproc
	Modifier
	Integer
	Float
	String
	Bitstring

	Unused
	ErrorLiteral
	FailLiteral
	FalseLiteral
	InconcLiteral
	NoneLiteral
	PassLiteral
	TrueLiteral

	AddressKeyword
	AllKeyword
	AltKeyword
	AltstepKeyword
	And4bKeyword
	AndKeyword
	AnyKeyword
	CaseKeyword
	CatchKeyword
	CharstringKeyword
	ClassKeyword
	ComponentKeyword
	ConfigurationKeyword
	ConnectKeyword
	ConstKeyword
	ControlKeyword
	CreateKeyword
	DisplayKeyword
	DoKeyword
	ElseKeyword
	EncodeKeyword
	EnumeratedKeyword
	ExceptKeyword
	ExceptionKeyword
	ExecuteKeyword
	ExtendsKeyword
	ExtensionKeyword
	ExternalKeyword
	FinallyKeyword
	ForKeyword
	FriendKeyword
	FromKeyword
	FunctionKeyword
	GotoKeyword
	GroupKeyword
	IfKeyword
	ImportKeyword
	InKeyword
	InoutKeyword
	InterleaveKeyword
	LabelKeyword
	LanguageKeyword
	LengthKeyword
	MapKeyword
	MessageKeyword
	ModKeyword
	ModifiesKeyword
	ModuleKeyword
	ModuleparKeyword
	MtcKeyword
	NoblockKeyword
	Not4bKeyword
	NotKeyword
	NullKeyword
	OfKeyword
	OmitKeyword
	OnKeyword
	OptionalKeyword
	Or4bKeyword
	OrKeyword
	OutKeyword
	OverrideKeyword
	ParamKeyword
	PortKeyword
	PresentKeyword
	PrivateKeyword
	ProcedureKeyword
	PublicKeyword
	RealtimeKeyword
	RecordKeyword
	RemKeyword
	ReturnKeyword
	RunsKeyword
	SelectKeyword
	SelfKeyword
	SetKeyword
	SignatureKeyword
	StreamKeyword
	SystemKeyword
	TemplateKeyword
	TestcaseKeyword
	ThisKeyword
	TimerKeyword
	ToKeyword
	TypeKeyword
	UnionKeyword
	UniversalKeyword
	UnmapKeyword
	ValueKeyword
	VarKeyword
	VariantKeyword
	WhileKeyword
	WithKeyword
	Xor4bKeyword
	XorKeyword

	Add
	Any
	Arrow
	Assign
	AtDefault
	AtLocal
	Colon
	ColonColon
	Comma
	Concat
	Div
	Dot
	DotDot
	DoubleArrow
	Equal
	Exclude
	Greater
	GreaterEqual
	LeftBrace
	LeftBracket
	LeftParen
	Less
	LessEqual
	Mul
	NotANumber
	NotEqual
	RightBrace
	RightBracket
	RightParen
	RotateLeft
	RotateRight
	Semicolon
	ShiftLeft
	ShiftRight
	Sub

	Root
	Module
	Decls
	Decl
	Group
	Friend
	Import
	ExceptSpec
	ExceptStmt
	ImportSpec
	ImportStmt
	ImportKind
	Signature
	Component
	Port
	PortKind
	PortSpec
	PortAttribute
	PortElement
	PortTranslation
	SubType
	Struct
	StructKind
	StructMember
	List
	ListKind
	Enum
	EnumLabel
	Map
	Class
	Constructor
	Control
	Destructor
	TestcaseType
	FunctionType
	AltstepType
	VarDecl
	TimerDecl
	PortDecl
	Template
	Testcase
	Function
	Configuration
	Altstep
	Stmt
	IfStmt
	SelectStmt
	ForStmt
	WhileStmt
	DoStmt
	GotoStmt
	LabelStmt
	ReturnStmt
	AltStmt
	AssignStmt
	GuardStmt
	Block
	BasicBlock
	Exprs
	Expr
	PrimaryExpr
	Literal
	UnaryExpr
	BinaryExpr
	Ref
	TypePars
	TypePar
	With
	WithStmt
	WithQualifier
	WithKind
	Refs
	Extends
	Language
	Return
	ValueConstraints
	ConfigSpec
	Exception
	Visibility
	Name
	FormalTypePars
	FormalTypePar
	FormalPars
	FormalPar
	Declarator
	ArrayDef
	TemplateRestriction
	NestedTemplate
	NestedType
	NestedStruct
	NestedList
	NestedEnum
)

func (Kind) IsKeyword

func (k Kind) IsKeyword() bool

IsKeyword returns true if the kind is a keyword.

func (Kind) IsLiteral

func (k Kind) IsLiteral() bool

IsLiteral returns true if the kind is a literal token. Literal tokens are tokens which have a value, such as identifier, integer, ...

func (Kind) IsNonTerminal

func (k Kind) IsNonTerminal() bool

IsNonTerminal returns true if the kind is a non terminal. Non terminals are produced by the parser and usually have other non terminals or tokens as children.

func (Kind) IsTerminal

func (k Kind) IsTerminal() bool

IsTerminal returns true if the kind is a terminal. Terminals are also known as leave nodes, lexemes, tokens, ...

func (Kind) IsToken

func (k Kind) IsToken() bool

IsToken returns true if the kind is a token. This function is the same as IsTerminal.

func (Kind) IsTrivia

func (k Kind) IsTrivia() bool

IsTrivia returns true if the kind is either a comment or a preprocessor directive

func (Kind) String

func (k Kind) String() string

String returns a human readable name for the kind.

type Node

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

Node is a syntax node.

func Parse

func Parse(src []byte) Node

Parse parses the TTCN-3 source code in src and returns a syntax tree.

func Tokenize

func Tokenize(src []byte) Node

Tokenize given source code and return a root node with all the tokens.

func (Node) End

func (n Node) End() int

End returns the end position of the node in the source code. Or -1 if none was available.

func (Node) Err

func (n Node) Err() error

Err returns the error of the subtree.

func (Node) FirstChild

func (n Node) FirstChild() Node

FirstChild returns the first child of the node or nil if there is none.

func (Node) FirstToken

func (n Node) FirstToken() Node

FirstToken returns the first token of a syntax node which is not a trivia or Invalid if there is none.

Trivia tokens are tokens that are comments or preproccessor directives.

func (Node) Inspect

func (n Node) Inspect(f func(n Node) bool)

Inspect traverses the syntax tree in depth-first order. It calls f for each node recursively followed by a call of f(Invalid).

func (Node) IsNonTerminal

func (n Node) IsNonTerminal() bool

IsNonTerminal returns true if the node is a non-terminal node.

func (Node) IsTerminal

func (n Node) IsTerminal() bool

IsTerminal returns true if the node is a terminal node.

func (Node) Kind

func (n Node) Kind() Kind

Kind returns the syntax node kind of the node, such as Comment, Identifier, VarDecl, etc.

func (Node) LastToken

func (n Node) LastToken() Node

LastToken returns the last token of a syntax node which is not a trivia or Invalid if none is available.

func (Node) Len

func (n Node) Len() int

Len returns the length of the node or 0 if no length is available.

func (Node) Next

func (n Node) Next() Node

Next returns the next sibling node or Invalid if there is none.

func (Node) Parent

func (n Node) Parent() Node

Parent returns the parent of the node or Invalid if the node is the root node.

func (Node) Pos

func (n Node) Pos() int

Pos returns the position (offset) of the node in the source code. Or -1 if no position was available.

func (Node) Text

func (n Node) Text() string

Text returns the source code text of the node.

type Scanner

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

Scanner scans a TTCN-3 source.

func NewScanner

func NewScanner(src []byte) *Scanner

NewScanner returns a new TTCN-3 scanner for src.

func (*Scanner) Scan

func (s *Scanner) Scan() (Kind, int, int)

Scan returns the next token and its range.

Directories

Path Synopsis
internal
gen
This program reads the TTCN-3 grammar file and generates a parser for it.
This program reads the TTCN-3 grammar file and generates a parser for it.

Jump to

Keyboard shortcuts

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