syntax

package
v0.18.0 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2023 License: BSD-3-Clause Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AddToken eventType = iota
	OpenNode
	CloseNode
)

Variables

View Source
var (
	// Nil is the zero value of a Node.
	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 Kind

type Kind int32

Kind describes the kind of a syntax node.

const (
	EOF Kind = iota
	Unknown
	Malformed
	Unterminated

	Comment
	Preproc
	Name
	Bitstring
	Float
	Identifier
	Integer
	Modifier
	String

	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
	ErrorLiteral
	Exclude
	FailLiteral
	FalseLiteral
	Greater
	GreaterEqual
	InconcLiteral
	LeftBrace
	LeftBracket
	LeftParen
	Less
	LessEqual
	Mul
	NoneLiteral
	NotANumber
	NotEqual
	PassLiteral
	RightBrace
	RightBracket
	RightParen
	RotateLeft
	RotateRight
	Semicolon
	ShiftLeft
	ShiftRight
	Sub
	TrueLiteral

	Root
	SyntaxError
	Module
	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
	DotExpr
	IndexExpr
	CallExpr
	Literal
	UnaryExpr
	BinaryExpr
	Ref
	TypePars
	TypePar
	With
	WithStmt
	WithQualifier
	WithKind
	Refs
	Extends
	Language
	Return
	ConfigSpec
	Exception
	Visibility

	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. Errors without a position are attached to the root node.

func (Node) FindDescendant

func (n Node) FindDescendant(pos int) Node

FindDescendant finds the last descendant of this node whose span includes the given position. If no such node exists, it returns Nil.

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/terminal of a syntax node or Nil if there is none.

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. If n is a non-terminal the call is followed by a call of f(Nil).

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) IsToken

func (n Node) IsToken() bool

IsToken returns true if the node is a token node.

func (Node) IsValid

func (n Node) IsValid() bool

IsValid returns true if the node is valid non-nil 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/terminal of a syntax node or Nil 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 Nil if there is none.

func (Node) Parent

func (n Node) Parent() Node

Parent returns the parent of the node or Nil 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) Span

func (n Node) Span() Span

Span returns the text span of the node in the source code.

func (Node) Text

func (n Node) Text() string

Text returns the source code text of the node.

type NodeError

type NodeError struct {
	Node
	Err  error
	Hint string
}

func (*NodeError) Error

func (e *NodeError) Error() string

func (*NodeError) Unwrap

func (e *NodeError) Unwrap() error

type Position

type Position struct {
	Line, Column int
}

Position is a cursor position in a source file. Lines and columns are 1-based.

func (*Position) After

func (pos *Position) After(other Position) bool

After returns true if the position is after other given position.

func (*Position) Before

func (pos *Position) Before(other Position) bool

Before returns true if the position is before the other given position.

func (*Position) IsValid

func (pos *Position) IsValid() bool

IsValid returns true if the position is valid.

func (*Position) String

func (pos *Position) String() string

String returns the position's string representation.

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) Lines

func (s *Scanner) Lines() []int

Lines returns the line offsets of the source.

func (*Scanner) Scan

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

Scan returns the next token and its range.

type Span

type Span struct {
	Filename   string
	Begin, End Position
}

Span is the text span in the source code.

func (Span) String

func (s Span) String() string

String returns the string representation of the text span.

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