parser

package module
v1.4.1 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2026 License: MIT Imports: 14 Imported by: 0

README

pawn-parser

Reusable Go lexer and concrete-syntax-tree parser for the Pawn language used by SA-MP and open.mp projects.

The parser preserves source byte ranges, tokens, comments, whitespace trivia, preprocessor directives, and conditional compilation regions.

Install

go get github.com/pawnkit/pawn-parser

Parse source

package main

import (
	"fmt"

	parser "github.com/pawnkit/pawn-parser"
)

func main() {
	source := []byte("stock AddOne(value) { return value + 1; }")
	file := parser.Parse(source)
	if file.HasParseErrors() {
		panic("invalid Pawn source")
	}

	fmt.Println(file.Root.Kind)
	fmt.Println(file.Root.Text(source))
}

Packages

  • github.com/pawnkit/pawn-parser: Pawn CST parser and node kinds
  • github.com/pawnkit/pawn-parser/lexer: standalone tokenizer
  • github.com/pawnkit/pawn-parser/token: token kinds, positions, and trivia

Parse profiles

Use ParseWithProfile for new compact consumers:

  • ProfileLossless retains syntax, tokens, trivia, and origins for formatting.
  • ProfileAnalysis retains compact syntax and diagnostics for linting.
  • ProfileTokensOnly tokenizes without building a syntax tree.

Parse remains the pointer-tree compatibility API. ParseForLinter remains an alias for the analysis profile.

Analysis consumers can use typed, allocation-free traversal:

file := parser.ParseWithProfile(source, parser.ProfileAnalysis)
declarations := file.Syntax().Declarations()
for declarations.Next() {
	function, ok := parser.AsFunction(declarations.Declaration())
	if !ok {
		continue
	}
	name, _ := function.Name()
	fmt.Println(name.Text())
}

Formatters should use ProfileLossless. Syntax token handles then expose retained leading trivia, trailing trivia, and origin chains without expanding the pointer CST.

The v1.0 pointer-tree API remains supported. See compatibility before choosing an API for a new integration.

Contributing

Grammar fixes and small compatibility cases are welcome. See CONTRIBUTING.md for the test and review expectations.

Documentation

Overview

Package parser is a reusable concrete-syntax-tree parser for the Pawn language used by SA-MP and open.mp projects.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsTopLevelDeclaration

func IsTopLevelDeclaration(k Kind) bool

IsTopLevelDeclaration reports whether k is a top-level declaration kind.

Types

type BinarySyntax

type BinarySyntax struct{ SyntaxNode }

BinarySyntax is a typed binary or assignment expression handle.

func AsBinary

func AsBinary(n SyntaxNode) (BinarySyntax, bool)

AsBinary converts binary and assignment nodes.

func (BinarySyntax) Left

func (b BinarySyntax) Left() (ExpressionSyntax, bool)

Left returns the left operand.

func (BinarySyntax) Right

func (b BinarySyntax) Right() (ExpressionSyntax, bool)

Right returns the right operand.

type BlockSyntax

type BlockSyntax struct{ SyntaxNode }

BlockSyntax is a typed block statement handle.

func (BlockSyntax) Statements

func (b BlockSyntax) Statements() SyntaxIterator

Statements iterates statements in the block.

type ByteRange

type ByteRange struct {
	Start int
	End   int
}

ByteRange is a half-open source byte range.

func ByteRangeFromSpan

func ByteRangeFromSpan(s source.Span) ByteRange

ByteRangeFromSpan drops s.File, keeping only the byte offsets.

func (ByteRange) Span

func (r ByteRange) Span(file source.FileID) source.Span

Span converts r into a pawnkit-core source.Span for file.

type CallSyntax

type CallSyntax struct{ SyntaxNode }

CallSyntax is a typed call expression handle.

func AsCall

func AsCall(n SyntaxNode) (CallSyntax, bool)

AsCall converts n when it is a call expression.

func (CallSyntax) Arguments

func (c CallSyntax) Arguments() SyntaxIterator

Arguments returns the argument nodes.

func (CallSyntax) Function

func (c CallSyntax) Function() (ExpressionSyntax, bool)

Function returns the called expression.

type CompactError

type CompactError struct {
	Message       string
	Node          uint32
	Offset        uint32
	Found         token.Kind
	ExpectedStart uint32
	ExpectedCount uint32
}

CompactError stores sparse recovery data.

type CompactField

type CompactField struct {
	ID   FieldID
	Node uint32
}

CompactField maps a field name to a node.

type CompactFile

type CompactFile struct {
	Source      []byte
	Tokens      []CompactToken
	Trivia      []CompactTrivia
	Origins     []CompactOrigin
	MacroNames  []string
	Lines       token.LineMap
	Tree        CompactTree
	Broken      bool
	Diagnostics []Diagnostic
	Profile     Profile
}

CompactFile is an index-based CST.

func ParseCompact

func ParseCompact(source []byte, options ParseOptions) *CompactFile

ParseCompact parses source into a compact CST.

func ParseForLinter

func ParseForLinter(source []byte) *CompactFile

ParseForLinter parses source without retaining tokens or trivia.

func ParseTokensCompact

func ParseTokensCompact(source []byte, toks []token.Token, options ParseOptions) *CompactFile

ParseTokensCompact parses tokens into a compact CST.

func ParseTokensCompactContext added in v1.3.0

func ParseTokensCompactContext(
	ctx context.Context,
	source []byte,
	toks []token.Token,
	options ParseOptions,
) (*CompactFile, error)

ParseTokensCompactContext parses tokens with cancellation.

func ParseTokensForLinter

func ParseTokensForLinter(source []byte, toks []token.Token) *CompactFile

ParseTokensForLinter parses an existing token stream for linting.

func ParseWithProfile

func ParseWithProfile(source []byte, profile Profile) *CompactFile

ParseWithProfile parses source using a consumer-oriented retention profile.

func (*CompactFile) Expand

func (f *CompactFile) Expand() *File

Expand builds the pointer CST represented by f.

func (*CompactFile) HasParseErrors

func (f *CompactFile) HasParseErrors() bool

HasParseErrors reports whether compact parsing produced a syntax error.

func (*CompactFile) Syntax

func (f *CompactFile) Syntax() SyntaxNode

Syntax returns the root syntax node.

type CompactNode

type CompactNode struct {
	Kind Kind

	Start uint32
	End   uint32

	TokenKind  token.Kind
	TokenStart uint32
	TokenEnd   uint32

	ChildStart uint32
	ChildCount uint32
	FieldStart uint32
	FieldCount uint32

	HasError    bool
	MissingSemi bool
	HasRaw      bool
}

CompactNode stores one tree node.

func (CompactNode) Bytes

func (n CompactNode) Bytes(source []byte) []byte

Bytes returns the node's exact source bytes without allocating.

func (CompactNode) Range

func (n CompactNode) Range() ByteRange

Range returns the node's half-open source byte range.

func (CompactNode) Text

func (n CompactNode) Text(source []byte) string

Text returns the node's exact source text.

type CompactOrigin

type CompactOrigin = token.CompactOrigin

CompactOrigin stores one origin link.

type CompactPosition

type CompactPosition = token.CompactPosition

CompactPosition stores a compact source position.

type CompactToken

type CompactToken = token.CompactToken

CompactToken stores one token with indexed metadata.

type CompactTree

type CompactTree struct {
	Nodes    []CompactNode
	Children []uint32
	Fields   []CompactField
	Errors   []CompactError
	Expected []token.Kind
	Root     uint32
}

CompactTree stores nodes and edges in arrays.

func (*CompactTree) ChildIndices

func (t *CompactTree) ChildIndices(node uint32) []uint32

ChildIndices returns the child indices for node.

func (*CompactTree) Field

func (t *CompactTree) Field(node uint32, name string) (uint32, bool)

Field returns the node index associated with name.

type CompactTrivia

type CompactTrivia = token.CompactTrivia

CompactTrivia stores one trivia span.

type ConditionalSyntax

type ConditionalSyntax struct{ SyntaxNode }

ConditionalSyntax is a typed conditional region handle.

func AsConditional

func AsConditional(n SyntaxNode) (ConditionalSyntax, bool)

AsConditional converts conditional region nodes.

func (ConditionalSyntax) Branches

func (c ConditionalSyntax) Branches() SyntaxIterator

Branches iterates conditional branches.

type DeclarationBoundary added in v1.2.0

type DeclarationBoundary struct {
	Kind        Kind
	Range       ByteRange
	Name        string
	Identity    [sha256.Size]byte
	Fingerprint [sha256.Size]byte
	HasError    bool
}

DeclarationBoundary identifies one top-level declaration.

type DeclarationIndex added in v1.2.0

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

DeclarationIndex is an immutable declaration boundary table.

func BuildDeclarationIndex added in v1.2.0

func BuildDeclarationIndex(file *CompactFile) DeclarationIndex

BuildDeclarationIndex indexes the top-level declarations in file.

func (DeclarationIndex) At added in v1.2.0

At returns the declaration at position n.

func (DeclarationIndex) Len added in v1.2.0

func (i DeclarationIndex) Len() int

Len returns the number of declarations.

func (DeclarationIndex) Reliable added in v1.2.0

func (i DeclarationIndex) Reliable() bool

Reliable reports whether every boundary was recovered cleanly.

type DeclarationIterator

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

DeclarationIterator iterates top-level declarations without allocating.

func (*DeclarationIterator) Declaration

func (i *DeclarationIterator) Declaration() SyntaxNode

Declaration returns the current declaration.

func (*DeclarationIterator) Next

func (i *DeclarationIterator) Next() bool

Next advances to the next declaration.

type Diagnostic

type Diagnostic struct {
	Code     DiagnosticCode
	Message  string
	Range    ByteRange
	Found    token.Token
	Expected []token.Kind
	Recovery Recovery
}

Diagnostic is a structured syntax error produced while building the CST.

func (Diagnostic) ToCore

func (d Diagnostic) ToCore(file source.FileID) diagnostic.Diagnostic

ToCore converts d to the shared diagnostic format. Parser diagnostics currently use error severity.

type DiagnosticCode

type DiagnosticCode string

DiagnosticCode is a stable, machine-readable syntax diagnostic identifier.

const (
	// DiagnosticUnexpectedToken reports a token consumed by generic recovery.
	DiagnosticUnexpectedToken DiagnosticCode = "unexpected_token"
	// DiagnosticUnexpectedDelimiter reports an unmatched closing delimiter.
	DiagnosticUnexpectedDelimiter DiagnosticCode = "unexpected_closing_delimiter"
	// DiagnosticMissingToken reports required punctuation that was absent.
	DiagnosticMissingToken DiagnosticCode = "missing_token"
	// DiagnosticMissingExpression reports an absent expression operand.
	DiagnosticMissingExpression DiagnosticCode = "missing_expression"
	// DiagnosticMissingIdentifier reports an absent required identifier.
	DiagnosticMissingIdentifier DiagnosticCode = "missing_identifier"
	// DiagnosticMissingDeclaration reports an absent declaration component.
	DiagnosticMissingDeclaration DiagnosticCode = "missing_declaration_component"
	// DiagnosticMaximumDepth reports that the parser nesting limit was reached.
	DiagnosticMaximumDepth DiagnosticCode = "maximum_parse_depth"
	// DiagnosticUnrecoverable reports that parsing could not make progress.
	DiagnosticUnrecoverable DiagnosticCode = "unrecoverable_parse_failure"
	// DiagnosticSyntaxError reports an error node without a more specific code.
	DiagnosticSyntaxError DiagnosticCode = "syntax_error"
)

type DirectiveSyntax

type DirectiveSyntax struct{ SyntaxNode }

DirectiveSyntax is a typed preprocessor directive handle.

func AsDirective

func AsDirective(n SyntaxNode) (DirectiveSyntax, bool)

AsDirective converts n when it is a directive.

type EnumSyntax

type EnumSyntax struct{ SyntaxNode }

EnumSyntax is a typed enum declaration handle.

func AsEnum

func AsEnum(n SyntaxNode) (EnumSyntax, bool)

AsEnum converts n when it is an enum declaration.

func (EnumSyntax) Entries

func (e EnumSyntax) Entries() SyntaxIterator

Entries iterates enum entries.

func (EnumSyntax) Name

func (e EnumSyntax) Name() (SyntaxNode, bool)

Name returns the enum name when present.

type ExpressionSyntax

type ExpressionSyntax struct{ SyntaxNode }

ExpressionSyntax is a lightweight expression handle.

type FieldID

type FieldID uint8

FieldID identifies a named syntax field.

func (FieldID) String

func (id FieldID) String() string

String returns the field name.

type File

type File struct {
	Source []byte
	Tokens []token.Token
	Root   *Node

	Broken bool

	Diagnostics []Diagnostic
}

File is the result of parsing one Pawn source file/buffer.

func Parse

func Parse(source []byte) *File

Parse parses source into a File. Parse errors are reported via File.Broken and Node.HasError.

func ParseTokens

func ParseTokens(source []byte, toks []token.Token) *File

ParseTokens parses a caller-provided token stream. It is useful for parsing preprocessed tokens whose Origin fields retain expansion history.

func ParseTokensWithOptions

func ParseTokensWithOptions(source []byte, toks []token.Token, options ParseOptions) *File

ParseTokensWithOptions parses tokens with retention options.

func ParseWithOptions

func ParseWithOptions(source []byte, options ParseOptions) *File

ParseWithOptions parses source with retention options.

func (*File) HasParseErrors

func (f *File) HasParseErrors() bool

HasParseErrors reports whether parsing produced a syntax diagnostic or an unrecoverable/broken result.

type FileID

type FileID = source.FileID

FileID is the shared PawnKit source identifier.

type FileSet

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

FileSet owns logical source files and assigns deterministic IDs in insertion order. Logical names can be used instead of host paths in generated output.

func (*FileSet) Add

func (s *FileSet) Add(name string, data []byte) SourceFile

Add copies data into the set and returns the newly added source file.

func (*FileSet) File

func (s *FileSet) File(id FileID) (SourceFile, bool)

File returns the source file with id, if it exists.

func (*FileSet) Files

func (s *FileSet) Files() []SourceFile

Files returns a copy of the set's source-file list.

func (*FileSet) Require

func (s *FileSet) Require(id FileID) (SourceFile, error)

Require returns the source file with id or an error if it does not exist.

type FunctionSyntax

type FunctionSyntax struct{ SyntaxNode }

FunctionSyntax is a typed function declaration or definition handle.

func AsFunction

func AsFunction(n SyntaxNode) (FunctionSyntax, bool)

AsFunction converts n when it is a function node.

func (FunctionSyntax) Body

func (f FunctionSyntax) Body() (BlockSyntax, bool)

Body returns the function body when present.

func (FunctionSyntax) Name

func (f FunctionSyntax) Name() (SyntaxNode, bool)

Name returns the function name.

func (FunctionSyntax) Parameters

func (f FunctionSyntax) Parameters() ParameterIterator

Parameters returns the function parameter list.

type IfSyntax

type IfSyntax struct{ SyntaxNode }

IfSyntax is a typed if statement handle.

func AsIf

func AsIf(n SyntaxNode) (IfSyntax, bool)

AsIf converts n when it is an if statement.

func (IfSyntax) Alternative

func (s IfSyntax) Alternative() (StatementSyntax, bool)

Alternative returns the else branch when present.

func (IfSyntax) Condition

func (s IfSyntax) Condition() (ExpressionSyntax, bool)

Condition returns the if condition.

func (IfSyntax) Consequence

func (s IfSyntax) Consequence() (StatementSyntax, bool)

Consequence returns the if consequence.

type Kind

type Kind uint16

Kind identifies the syntactic category of a Node in the parsed CST.

const (
	// KindInvalid is the zero value of Kind, used for uninitialized nodes.
	KindInvalid Kind = iota

	KindSourceFile
	KindComment
	KindRaw

	// Directives
	KindDirectiveInclude
	KindDirectiveTryInclude
	KindDirectiveDefine
	KindDirectiveUndef
	KindDirectiveIf
	KindDirectiveElseif
	KindDirectiveElse
	KindDirectiveEndif
	KindDirectivePragma
	KindDirectiveError
	KindDirectiveWarning
	KindDirectiveEmit
	KindDirectiveAssert
	KindDirectiveLine
	KindDirectiveFile
	KindDirectiveEndinput
	KindDirectiveRaw
	KindConditionalRegion
	KindConditionalBranch
	KindSharedConditional
	KindSharedConditionalPrefix
	KindConditionalFunction

	// Declarations
	KindFunctionDefinition
	KindFunctionDeclaration
	KindVariableDeclaration
	KindVariableDeclarator
	KindEnumDeclaration
	KindEnumEntry
	KindParameterList
	KindParameter
	KindArgumentList
	KindDimension
	KindTaggedType

	// Statements
	KindBlock
	KindIfStatement
	KindWhileStatement
	KindDoWhileStatement
	KindForStatement
	KindSwitchStatement
	KindCaseClause
	KindDefaultClause
	KindCaseValueList
	KindCaseRange
	KindGotoStatement
	KindLabelStatement
	KindReturnStatement
	KindBreakStatement
	KindContinueStatement
	KindStateStatement
	KindExpressionStatement
	KindEmptyStatement
	KindMacroInvocationBlock

	// Expressions
	KindIdentifier
	KindLiteral
	KindCallExpression
	KindSubscriptExpression
	KindTernaryExpression
	KindBinaryExpression
	KindUnaryExpression
	KindUpdateExpression
	KindAssignmentExpression
	KindSizeofExpression
	KindTagofExpression
	KindDefinedExpression
	KindTaggedExpression
	KindParenthesizedExpression
	KindArrayLiteral
	KindExpressionList
	KindArgumentName
	KindIteratorArgument
	KindStringizeExpression
	KindStringConcat
	KindConditionalSplice
	KindDirectivePath
	KindMacroBody
	KindEnumIncrementClause
	KindStateSelector
	KindMacroInvocation
)

func (Kind) IsDirective

func (k Kind) IsDirective() bool

IsDirective reports whether k is one of the directive node kinds.

func (Kind) String

func (k Kind) String() string

type LoopSyntax

type LoopSyntax struct{ SyntaxNode }

LoopSyntax is a typed loop statement handle.

func AsLoop

func AsLoop(n SyntaxNode) (LoopSyntax, bool)

AsLoop converts while, do-while, and for nodes.

func (LoopSyntax) Body

func (s LoopSyntax) Body() (StatementSyntax, bool)

Body returns the loop body.

func (LoopSyntax) Condition

func (s LoopSyntax) Condition() (ExpressionSyntax, bool)

Condition returns the loop condition when present.

type Node

type Node struct {
	Kind     Kind
	Tok      token.Token
	Children []*Node

	Start int
	End   int

	HasError bool
	Raw      []byte

	ErrorMessage  string
	ErrorOffset   int
	ErrorFound    token.Kind
	ErrorExpected []token.Kind

	MissingSemi bool

	Leading  []token.Trivia
	Trailing []token.Trivia
	// contains filtered or unexported fields
}

Node is a single element of the concrete syntax tree produced by Parse.

func (*Node) Bytes

func (n *Node) Bytes(source []byte) []byte

Bytes returns the node's exact source bytes without allocating.

func (*Node) Field

func (n *Node) Field(name string) *Node

Field looks up a named child. Returns nil if absent.

func (*Node) LeadingTrivia

func (n *Node) LeadingTrivia() []token.Trivia

LeadingTrivia returns the trivia attached before the node's first token.

func (*Node) OperatorTokenHasComment

func (n *Node) OperatorTokenHasComment() bool

OperatorTokenHasComment reports whether n's operator token has a leading or trailing comment attached.

func (*Node) Range

func (n *Node) Range() ByteRange

Range returns the node's half-open source byte range.

func (*Node) Text

func (n *Node) Text(source []byte) string

Text returns the node's exact source text.

func (*Node) TrailingTrivia

func (n *Node) TrailingTrivia() []token.Trivia

TrailingTrivia returns the trivia attached after the node's last token.

type ParameterIterator

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

ParameterIterator iterates parameters without allocating.

func (*ParameterIterator) Next

func (i *ParameterIterator) Next() bool

Next advances to the next parameter.

func (*ParameterIterator) Parameter

func (i *ParameterIterator) Parameter() ParameterSyntax

Parameter returns the current parameter.

type ParameterSyntax

type ParameterSyntax struct{ SyntaxNode }

ParameterSyntax is a typed parameter handle.

func (ParameterSyntax) DefaultValue

func (p ParameterSyntax) DefaultValue() (ExpressionSyntax, bool)

DefaultValue returns the default value when present.

func (ParameterSyntax) Name

func (p ParameterSyntax) Name() (SyntaxNode, bool)

Name returns the parameter name.

type ParseOptions

type ParseOptions struct {
	DiscardTokens bool
	DiscardTrivia bool
}

ParseOptions controls retained parse data.

type Profile

type Profile uint8

Profile selects retained syntax for a consumer.

const (
	// ProfileLossless retains tokens, trivia, origins, and syntax.
	ProfileLossless Profile = iota
	// ProfileAnalysis retains compact syntax and diagnostics.
	ProfileAnalysis
	// ProfileTokensOnly retains tokens and trivia without building syntax.
	ProfileTokensOnly
)

type Recovery

type Recovery struct {
	Kind        RecoveryKind
	Range       ByteRange
	Replacement string
	Confidence  RecoveryConfidence
}

Recovery describes a source edit associated with a diagnostic.

type RecoveryConfidence

type RecoveryConfidence string

RecoveryConfidence states whether a recovery is safe to apply directly.

const (
	// RecoveryExact marks an unambiguous parser-selected edit.
	RecoveryExact RecoveryConfidence = "exact"
	// RecoverySuggested marks an ambiguous, non-applicable recovery hint.
	RecoverySuggested RecoveryConfidence = "suggested"
)

type RecoveryKind

type RecoveryKind string

RecoveryKind describes the edit shape selected during recovery.

const (
	// RecoveryNone indicates that no directly applicable edit is available.
	RecoveryNone RecoveryKind = "none"
	// RecoveryInsert inserts replacement text at an empty recovery range.
	RecoveryInsert RecoveryKind = "insert"
	// RecoveryRemove removes the recovery range.
	RecoveryRemove RecoveryKind = "remove"
	// RecoveryReplace replaces the recovery range with replacement text.
	RecoveryReplace RecoveryKind = "replace"
)

type ReturnSyntax

type ReturnSyntax struct{ SyntaxNode }

ReturnSyntax is a typed return statement handle.

func AsReturn

func AsReturn(n SyntaxNode) (ReturnSyntax, bool)

AsReturn converts n when it is a return statement.

func (ReturnSyntax) Expression

func (r ReturnSyntax) Expression() (ExpressionSyntax, bool)

Expression returns the returned expression when present.

type SourceFile

type SourceFile struct {
	ID   FileID
	Name string
	Data []byte
}

SourceFile contains a logical source file and its stable ID.

type StatementSyntax

type StatementSyntax struct{ SyntaxNode }

StatementSyntax is a lightweight statement handle.

type SubscriptSyntax

type SubscriptSyntax struct{ SyntaxNode }

SubscriptSyntax is a typed array access handle.

func AsSubscript

func AsSubscript(n SyntaxNode) (SubscriptSyntax, bool)

AsSubscript converts n when it is a subscript expression.

func (SubscriptSyntax) Array

func (s SubscriptSyntax) Array() (ExpressionSyntax, bool)

Array returns the indexed expression.

func (SubscriptSyntax) Index

func (s SubscriptSyntax) Index() (ExpressionSyntax, bool)

Index returns the index expression when present.

type SyntaxIterator

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

SyntaxIterator iterates syntax nodes without allocating.

func (*SyntaxIterator) Next

func (i *SyntaxIterator) Next() bool

Next advances the iterator.

func (*SyntaxIterator) Node

func (i *SyntaxIterator) Node() SyntaxNode

Node returns the current node.

type SyntaxNode

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

SyntaxNode is a lightweight handle into an immutable compact tree.

func (SyntaxNode) Bytes

func (n SyntaxNode) Bytes() []byte

Bytes returns the node source bytes without allocating.

func (SyntaxNode) Children

func (n SyntaxNode) Children() SyntaxIterator

Children returns an allocation-free child iterator.

func (SyntaxNode) Declarations

func (n SyntaxNode) Declarations() DeclarationIterator

Declarations iterates top-level declarations.

func (SyntaxNode) Field

func (n SyntaxNode) Field(name string) (SyntaxNode, bool)

Field returns a named child.

func (SyntaxNode) HasError

func (n SyntaxNode) HasError() bool

HasError reports whether the node contains syntax errors.

func (SyntaxNode) Kind

func (n SyntaxNode) Kind() Kind

Kind returns the node kind.

func (SyntaxNode) MissingSemicolon

func (n SyntaxNode) MissingSemicolon() bool

MissingSemicolon reports whether recovery inserted a semicolon.

func (SyntaxNode) Range

func (n SyntaxNode) Range() ByteRange

Range returns the node source range.

func (SyntaxNode) Text

func (n SyntaxNode) Text() string

Text returns the node source text.

func (SyntaxNode) Token

func (n SyntaxNode) Token() SyntaxToken

Token returns the node's primary token reference.

func (SyntaxNode) Valid

func (n SyntaxNode) Valid() bool

Valid reports whether n refers to a tree node.

type SyntaxOrigin

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

SyntaxOrigin is a lightweight origin-chain handle.

func (SyntaxOrigin) Macro

func (o SyntaxOrigin) Macro() string

Macro returns the originating macro name.

func (SyntaxOrigin) Parent

func (o SyntaxOrigin) Parent() (SyntaxOrigin, bool)

Parent returns the parent origin when present.

func (SyntaxOrigin) Span

func (o SyntaxOrigin) Span() token.Span

Span returns the origin source span.

func (SyntaxOrigin) Valid

func (o SyntaxOrigin) Valid() bool

Valid reports whether the origin exists.

type SyntaxToken

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

SyntaxToken is a lightweight token reference.

func (SyntaxToken) Bytes

func (t SyntaxToken) Bytes() []byte

Bytes returns token source bytes without allocating.

func (SyntaxToken) Kind

func (t SyntaxToken) Kind() token.Kind

Kind returns the token kind.

func (SyntaxToken) LeadingTrivia

func (t SyntaxToken) LeadingTrivia() []CompactTrivia

LeadingTrivia returns retained leading trivia.

func (SyntaxToken) Origin

func (t SyntaxToken) Origin() (SyntaxOrigin, bool)

Origin returns the first retained token origin.

func (SyntaxToken) Range

func (t SyntaxToken) Range() ByteRange

Range returns the token source range.

func (SyntaxToken) Text

func (t SyntaxToken) Text() string

Text returns token source text.

func (SyntaxToken) TrailingTrivia

func (t SyntaxToken) TrailingTrivia() []CompactTrivia

TrailingTrivia returns retained trailing trivia.

func (SyntaxToken) Valid

func (t SyntaxToken) Valid() bool

Valid reports whether the token reference is present.

type UnarySyntax

type UnarySyntax struct{ SyntaxNode }

UnarySyntax is a typed unary expression handle.

func AsUnary

func AsUnary(n SyntaxNode) (UnarySyntax, bool)

AsUnary converts unary and update nodes.

func (UnarySyntax) Expression

func (u UnarySyntax) Expression() (ExpressionSyntax, bool)

Expression returns the unary operand.

type VariableSyntax

type VariableSyntax struct{ SyntaxNode }

VariableSyntax is a typed variable declarator handle.

func AsVariable

func AsVariable(n SyntaxNode) (VariableSyntax, bool)

AsVariable converts n when it is a variable declarator.

func (VariableSyntax) Initializer

func (v VariableSyntax) Initializer() (ExpressionSyntax, bool)

Initializer returns the variable initializer when present.

func (VariableSyntax) Name

func (v VariableSyntax) Name() (SyntaxNode, bool)

Name returns the variable name.

Directories

Path Synopsis
Package lexer is a standalone tokenizer for the Pawn language.
Package lexer is a standalone tokenizer for the Pawn language.
Package token defines token kinds, positions, and trivia shared by the lexer and parser packages.
Package token defines token kinds, positions, and trivia shared by the lexer and parser packages.

Jump to

Keyboard shortcuts

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