parser

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: May 12, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func StripCR

func StripCR(b []byte, comment bool) []byte

StripCR removes carriage return characters.

Types

type ArrayLit

type ArrayLit struct {
	Elements []Expr
	LBrack   core.Pos
	RBrack   core.Pos
}

ArrayLit represents an array literal.

func (*ArrayLit) End

func (e *ArrayLit) End() core.Pos

End returns the position of first character immediately after the node.

func (*ArrayLit) Pos

func (e *ArrayLit) Pos() core.Pos

Pos returns the position of first character belonging to the node.

func (*ArrayLit) String

func (e *ArrayLit) String() string

type AssignStmt

type AssignStmt struct {
	LHS      []Expr
	RHS      []Expr
	Token    token.Token
	TokenPos core.Pos
}

AssignStmt represents an assignment statement.

func (*AssignStmt) End

func (s *AssignStmt) End() core.Pos

End returns the position of first character immediately after the node.

func (*AssignStmt) Pos

func (s *AssignStmt) Pos() core.Pos

Pos returns the position of first character belonging to the node.

func (*AssignStmt) String

func (s *AssignStmt) String() string

type BadExpr

type BadExpr struct {
	From core.Pos
	To   core.Pos
}

BadExpr represents a bad expression.

func (*BadExpr) End

func (e *BadExpr) End() core.Pos

End returns the position of first character immediately after the node.

func (*BadExpr) Pos

func (e *BadExpr) Pos() core.Pos

Pos returns the position of first character belonging to the node.

func (*BadExpr) String

func (e *BadExpr) String() string

type BadStmt

type BadStmt struct {
	From core.Pos
	To   core.Pos
}

BadStmt represents a bad statement.

func (*BadStmt) End

func (s *BadStmt) End() core.Pos

End returns the position of first character immediately after the node.

func (*BadStmt) Pos

func (s *BadStmt) Pos() core.Pos

Pos returns the position of first character belonging to the node.

func (*BadStmt) String

func (s *BadStmt) String() string

type BinaryExpr

type BinaryExpr struct {
	LHS      Expr
	RHS      Expr
	Token    token.Token
	TokenPos core.Pos
}

BinaryExpr represents a binary operator expression.

func (*BinaryExpr) End

func (e *BinaryExpr) End() core.Pos

End returns the position of first character immediately after the node.

func (*BinaryExpr) Pos

func (e *BinaryExpr) Pos() core.Pos

Pos returns the position of first character belonging to the node.

func (*BinaryExpr) String

func (e *BinaryExpr) String() string

type BlockStmt

type BlockStmt struct {
	Stmts  []Stmt
	LBrace core.Pos
	RBrace core.Pos
}

BlockStmt represents a block statement.

func (*BlockStmt) End

func (s *BlockStmt) End() core.Pos

End returns the position of first character immediately after the node.

func (*BlockStmt) Pos

func (s *BlockStmt) Pos() core.Pos

Pos returns the position of first character belonging to the node.

func (*BlockStmt) String

func (s *BlockStmt) String() string

type BoolLit

type BoolLit struct {
	Value    bool
	ValuePos core.Pos
	Literal  string
}

BoolLit represents a boolean literal.

func (*BoolLit) End

func (e *BoolLit) End() core.Pos

End returns the position of first character immediately after the node.

func (*BoolLit) Pos

func (e *BoolLit) Pos() core.Pos

Pos returns the position of first character belonging to the node.

func (*BoolLit) String

func (e *BoolLit) String() string

type BranchStmt

type BranchStmt struct {
	Token    token.Token
	TokenPos core.Pos
	Label    *Ident
}

BranchStmt represents a branch statement.

func (*BranchStmt) End

func (s *BranchStmt) End() core.Pos

End returns the position of first character immediately after the node.

func (*BranchStmt) Pos

func (s *BranchStmt) Pos() core.Pos

Pos returns the position of first character belonging to the node.

func (*BranchStmt) String

func (s *BranchStmt) String() string

type CallExpr

type CallExpr struct {
	Func     Expr
	LParen   core.Pos
	Args     []Expr
	Ellipsis core.Pos
	RParen   core.Pos
}

CallExpr represents a function call expression.

func (*CallExpr) End

func (e *CallExpr) End() core.Pos

End returns the position of first character immediately after the node.

func (*CallExpr) Pos

func (e *CallExpr) Pos() core.Pos

Pos returns the position of first character belonging to the node.

func (*CallExpr) String

func (e *CallExpr) String() string

type CondExpr

type CondExpr struct {
	Cond        Expr
	True        Expr
	False       Expr
	QuestionPos core.Pos
	ColonPos    core.Pos
}

CondExpr represents a ternary conditional expression.

func (*CondExpr) End

func (e *CondExpr) End() core.Pos

End returns the position of first character immediately after the node.

func (*CondExpr) Pos

func (e *CondExpr) Pos() core.Pos

Pos returns the position of first character belonging to the node.

func (*CondExpr) String

func (e *CondExpr) String() string

type DecimalLit

type DecimalLit struct {
	Value    dec128.Dec128
	ValuePos core.Pos
	Literal  string
}

DecimalLit represents a decimal literal.

func (*DecimalLit) End

func (e *DecimalLit) End() core.Pos

End returns the position of first character immediately after the node.

func (*DecimalLit) Pos

func (e *DecimalLit) Pos() core.Pos

Pos returns the position of first character belonging to the node.

func (*DecimalLit) String

func (e *DecimalLit) String() string

type DeferStmt added in v0.2.1

type DeferStmt struct {
	DeferPos core.Pos
	Call     Expr // *CallExpr or *MethodCallExpr
}

DeferStmt represents a defer statement:

defer fn(arg1, arg2)

func (*DeferStmt) End added in v0.2.1

func (s *DeferStmt) End() core.Pos

func (*DeferStmt) Pos added in v0.2.1

func (s *DeferStmt) Pos() core.Pos

func (*DeferStmt) String added in v0.2.1

func (s *DeferStmt) String() string

type EmptyStmt

type EmptyStmt struct {
	Semicolon core.Pos
	Implicit  bool
}

EmptyStmt represents an empty statement.

func (*EmptyStmt) End

func (s *EmptyStmt) End() core.Pos

End returns the position of first character immediately after the node.

func (*EmptyStmt) Pos

func (s *EmptyStmt) Pos() core.Pos

Pos returns the position of first character belonging to the node.

func (*EmptyStmt) String

func (s *EmptyStmt) String() string

type Error

type Error struct {
	Pos SourceFilePos
	Msg string
}

Error represents a parser error.

func (Error) Error

func (e Error) Error() string

type ErrorList

type ErrorList []*Error

ErrorList is a collection of parser errors.

func (*ErrorList) Add

func (p *ErrorList) Add(pos SourceFilePos, msg string)

Add adds a new parser error to the collection.

func (ErrorList) Err

func (p ErrorList) Err() error

Err returns an error.

func (ErrorList) Error

func (p ErrorList) Error() string

func (ErrorList) Len

func (p ErrorList) Len() int

Len returns the number of elements in the collection.

func (ErrorList) Less

func (p ErrorList) Less(i, j int) bool

func (ErrorList) Sort

func (p ErrorList) Sort()

Sort sorts the collection.

func (ErrorList) Swap

func (p ErrorList) Swap(i, j int)

type ExportStmt

type ExportStmt struct {
	ExportPos core.Pos
	Result    Expr
}

ExportStmt represents an export statement.

func (*ExportStmt) End

func (s *ExportStmt) End() core.Pos

End returns the position of first character immediately after the node.

func (*ExportStmt) Pos

func (s *ExportStmt) Pos() core.Pos

Pos returns the position of first character belonging to the node.

func (*ExportStmt) String

func (s *ExportStmt) String() string

type Expr

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

Expr represents an expression node in the AST.

type ExprStmt

type ExprStmt struct {
	Expr Expr
}

ExprStmt represents an expression statement.

func (*ExprStmt) End

func (s *ExprStmt) End() core.Pos

End returns the position of first character immediately after the node.

func (*ExprStmt) Pos

func (s *ExprStmt) Pos() core.Pos

Pos returns the position of first character belonging to the node.

func (*ExprStmt) String

func (s *ExprStmt) String() string

type FStringLit added in v0.1.3

type FStringLit struct {
	Parts    []FStringPart
	ValuePos core.Pos
	EndPos   core.Pos
	Literal  string // original source text, including surrounding quotes
}

FStringLit represents f-string literal: f"text {expr:fspec} ...". All format specs and literal text segments are resolved at parse time so the runtime cost of an f-string is the cost of its expression evaluations plus per-interpolation Format calls and string concatenation.

func (*FStringLit) End added in v0.1.3

func (e *FStringLit) End() core.Pos

End returns the position of first character immediately after the node.

func (*FStringLit) Pos added in v0.1.3

func (e *FStringLit) Pos() core.Pos

Pos returns the position of first character belonging to the node.

func (*FStringLit) String added in v0.1.3

func (e *FStringLit) String() string

type FStringPart added in v0.1.3

type FStringPart struct {
	// Literal text segment. Used when Expr == nil. Already unescaped from the f-string body (with `{{` / `}}` collapsed
	// to single braces and the usual `\n`, `\"`, ... escapes processed).
	Literal string

	// Interpolated expression (parsed Kavun expression). Nil for literal segments.
	Expr Expr

	// Pre-parsed format spec for the interpolation. Always valid for static interpolation parts; for literal parts and
	// dynamic-spec interpolation parts it is the zero FormatSpec.
	Spec fspec.FormatSpec

	// Original spec text (the substring after the `:` inside `{...}`), without leading colon. Empty when no `:` was
	// present or when the fspec was empty. For dynamic specs this is the raw template (including `{...}` placeholders);
	// it is only used for de-duplication and disassembly.
	SpecText string

	// Dynamic format-spec template. Set only when the spec contains nested `{expr}` placeholders. The runtime spec
	// string is built by interleaving SpecLiterals[i] with str(SpecExprs[i]) and ending with
	// SpecLiterals[len(SpecExprs)]. When SpecExprs is non-empty, Spec is unused and the spec is parsed at run time.
	SpecLiterals []string
	SpecExprs    []Expr
}

FStringPart is a single segment of an f-string. Exactly one of Literal or Expr is set: when Expr == nil the part is a verbatim literal text; when Expr != nil the part is an interpolation that must be Format()-ed with the pre-parsed Spec at run time.

type File

type File struct {
	InputFile *SourceFile
	Stmts     []Stmt
}

File represents a file unit.

func (*File) End

func (n *File) End() core.Pos

End returns the position of first character immediately after the node.

func (*File) Pos

func (n *File) Pos() core.Pos

Pos returns the position of first character belonging to the node.

func (*File) String

func (n *File) String() string

type FloatLit

type FloatLit struct {
	Value    float64
	ValuePos core.Pos
	Literal  string
}

FloatLit represents a floating point literal.

func (*FloatLit) End

func (e *FloatLit) End() core.Pos

End returns the position of first character immediately after the node.

func (*FloatLit) Pos

func (e *FloatLit) Pos() core.Pos

Pos returns the position of first character belonging to the node.

func (*FloatLit) String

func (e *FloatLit) String() string

type ForInStmt

type ForInStmt struct {
	ForPos   core.Pos
	Key      *Ident
	Value    *Ident
	Iterable Expr
	Body     *BlockStmt
}

ForInStmt represents a for-in statement.

func (*ForInStmt) End

func (s *ForInStmt) End() core.Pos

End returns the position of first character immediately after the node.

func (*ForInStmt) Pos

func (s *ForInStmt) Pos() core.Pos

Pos returns the position of first character belonging to the node.

func (*ForInStmt) String

func (s *ForInStmt) String() string

type ForStmt

type ForStmt struct {
	ForPos core.Pos
	Init   Stmt
	Cond   Expr
	Post   Stmt
	Body   *BlockStmt
}

ForStmt represents a for statement.

func (*ForStmt) End

func (s *ForStmt) End() core.Pos

End returns the position of first character immediately after the node.

func (*ForStmt) Pos

func (s *ForStmt) Pos() core.Pos

Pos returns the position of first character belonging to the node.

func (*ForStmt) String

func (s *ForStmt) String() string

type FuncLit

type FuncLit struct {
	Type *FuncType
	Body *BlockStmt
}

FuncLit represents a function literal.

func (*FuncLit) End

func (e *FuncLit) End() core.Pos

End returns the position of first character immediately after the node.

func (*FuncLit) Pos

func (e *FuncLit) Pos() core.Pos

Pos returns the position of first character belonging to the node.

func (*FuncLit) String

func (e *FuncLit) String() string

type FuncType

type FuncType struct {
	FuncPos core.Pos
	Params  *IdentList

	// Result is the optional named return identifier:
	//   func(a, b) name { ... }
	// When non-nil, `name` is allocated as a local pre-initialized to undefined; bare `return` and exit-after-recover
	// return its current value.
	Result *Ident
}

FuncType represents a function type definition.

func (*FuncType) End

func (e *FuncType) End() core.Pos

End returns the position of first character immediately after the node.

func (*FuncType) Pos

func (e *FuncType) Pos() core.Pos

Pos returns the position of first character belonging to the node.

func (*FuncType) String

func (e *FuncType) String() string

type Ident

type Ident struct {
	Name    string
	NamePos core.Pos
}

Ident represents an identifier.

func (*Ident) End

func (e *Ident) End() core.Pos

End returns the position of first character immediately after the node.

func (*Ident) Pos

func (e *Ident) Pos() core.Pos

Pos returns the position of first character belonging to the node.

func (*Ident) String

func (e *Ident) String() string

type IdentList

type IdentList struct {
	LParen  core.Pos
	VarArgs bool
	List    []*Ident
	RParen  core.Pos
}

IdentList represents a list of identifiers.

func (*IdentList) End

func (n *IdentList) End() core.Pos

End returns the position of first character immediately after the node.

func (*IdentList) NumFields

func (n *IdentList) NumFields() int

NumFields returns the number of fields.

func (*IdentList) Pos

func (n *IdentList) Pos() core.Pos

Pos returns the position of first character belonging to the node.

func (*IdentList) String

func (n *IdentList) String() string

type IfStmt

type IfStmt struct {
	IfPos core.Pos
	Init  Stmt
	Cond  Expr
	Body  *BlockStmt
	Else  Stmt // else branch; or nil
}

IfStmt represents an if statement.

func (*IfStmt) End

func (s *IfStmt) End() core.Pos

End returns the position of first character immediately after the node.

func (*IfStmt) Pos

func (s *IfStmt) Pos() core.Pos

Pos returns the position of first character belonging to the node.

func (*IfStmt) String

func (s *IfStmt) String() string

type ImmutableExpr

type ImmutableExpr struct {
	Expr   Expr
	IPos   core.Pos
	LParen core.Pos
	RParen core.Pos
}

ImmutableExpr represents an immutable expression

func (*ImmutableExpr) End

func (e *ImmutableExpr) End() core.Pos

End returns the position of first character immediately after the node.

func (*ImmutableExpr) Pos

func (e *ImmutableExpr) Pos() core.Pos

Pos returns the position of first character belonging to the node.

func (*ImmutableExpr) String

func (e *ImmutableExpr) String() string

type ImportExpr

type ImportExpr struct {
	ModuleName string
	Token      token.Token
	TokenPos   core.Pos
}

ImportExpr represents an import expression

func (*ImportExpr) End

func (e *ImportExpr) End() core.Pos

End returns the position of first character immediately after the node.

func (*ImportExpr) Pos

func (e *ImportExpr) Pos() core.Pos

Pos returns the position of first character belonging to the node.

func (*ImportExpr) String

func (e *ImportExpr) String() string

type IncDecStmt

type IncDecStmt struct {
	Expr     Expr
	Token    token.Token
	TokenPos core.Pos
}

IncDecStmt represents increment or decrement statement.

func (*IncDecStmt) End

func (s *IncDecStmt) End() core.Pos

End returns the position of first character immediately after the node.

func (*IncDecStmt) Pos

func (s *IncDecStmt) Pos() core.Pos

Pos returns the position of first character belonging to the node.

func (*IncDecStmt) String

func (s *IncDecStmt) String() string

type IndexExpr

type IndexExpr struct {
	Expr   Expr
	LBrack core.Pos
	Index  Expr
	RBrack core.Pos
}

IndexExpr represents an index expression.

func (*IndexExpr) End

func (e *IndexExpr) End() core.Pos

End returns the position of first character immediately after the node.

func (*IndexExpr) Pos

func (e *IndexExpr) Pos() core.Pos

Pos returns the position of first character belonging to the node.

func (*IndexExpr) String

func (e *IndexExpr) String() string

type IntLit

type IntLit struct {
	Value    int64
	ValuePos core.Pos
	Literal  string
}

IntLit represents an integer literal.

func (*IntLit) End

func (e *IntLit) End() core.Pos

End returns the position of first character immediately after the node.

func (*IntLit) Pos

func (e *IntLit) Pos() core.Pos

Pos returns the position of first character belonging to the node.

func (*IntLit) String

func (e *IntLit) String() string

type MethodCallExpr

type MethodCallExpr struct {
	Object     Expr
	MethodName string
	MethodPos  core.Pos
	LParen     core.Pos
	Args       []Expr
	Ellipsis   core.Pos
	RParen     core.Pos
}

MethodCallExpr represents a method call expression.

func (*MethodCallExpr) End

func (e *MethodCallExpr) End() core.Pos

func (*MethodCallExpr) Pos

func (e *MethodCallExpr) Pos() core.Pos

func (*MethodCallExpr) String

func (e *MethodCallExpr) String() string

type Node

type Node interface {
	// Pos returns the position of first character belonging to the node.
	Pos() core.Pos
	// End returns the position of first character immediately after the node.
	End() core.Pos
	// String returns a string representation of the node.
	String() string
}

Node represents a node in the AST.

type ParenExpr

type ParenExpr struct {
	Expr   Expr
	LParen core.Pos
	RParen core.Pos
}

ParenExpr represents a parenthesis wrapped expression.

func (*ParenExpr) End

func (e *ParenExpr) End() core.Pos

End returns the position of first character immediately after the node.

func (*ParenExpr) Pos

func (e *ParenExpr) Pos() core.Pos

Pos returns the position of first character belonging to the node.

func (*ParenExpr) String

func (e *ParenExpr) String() string

type Parser

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

Parser parses the Kavun source files.

func NewParser

func NewParser(file *SourceFile, src []byte, trace io.Writer) *Parser

NewParser creates a Parser.

func (*Parser) ParseFile

func (p *Parser) ParseFile() (file *File, err error)

ParseFile parses the source and returns an AST file unit.

type RecordElementLit

type RecordElementLit struct {
	Key      string
	KeyPos   core.Pos
	ColonPos core.Pos
	Value    Expr
}

RecordElementLit represents a record element.

func (*RecordElementLit) End

func (e *RecordElementLit) End() core.Pos

End returns the position of first character immediately after the node.

func (*RecordElementLit) Pos

func (e *RecordElementLit) Pos() core.Pos

Pos returns the position of first character belonging to the node.

func (*RecordElementLit) String

func (e *RecordElementLit) String() string

type RecordLit

type RecordLit struct {
	LBrace   core.Pos
	Elements []*RecordElementLit
	RBrace   core.Pos
}

RecordLit represents a record literal.

func (*RecordLit) End

func (e *RecordLit) End() core.Pos

End returns the position of first character immediately after the node.

func (*RecordLit) Pos

func (e *RecordLit) Pos() core.Pos

Pos returns the position of first character belonging to the node.

func (*RecordLit) String

func (e *RecordLit) String() string

type ReturnStmt

type ReturnStmt struct {
	ReturnPos core.Pos
	Result    Expr
}

ReturnStmt represents a return statement.

func (*ReturnStmt) End

func (s *ReturnStmt) End() core.Pos

End returns the position of first character immediately after the node.

func (*ReturnStmt) Pos

func (s *ReturnStmt) Pos() core.Pos

Pos returns the position of first character belonging to the node.

func (*ReturnStmt) String

func (s *ReturnStmt) String() string

type RuneLit added in v0.0.6

type RuneLit struct {
	Value    rune
	ValuePos core.Pos
	Literal  string
}

RuneLit represents a character literal.

func (*RuneLit) End added in v0.0.6

func (e *RuneLit) End() core.Pos

End returns the position of first character immediately after the node.

func (*RuneLit) Pos added in v0.0.6

func (e *RuneLit) Pos() core.Pos

Pos returns the position of first character belonging to the node.

func (*RuneLit) String added in v0.0.6

func (e *RuneLit) String() string

type RunesLit added in v0.0.6

type RunesLit struct {
	Value    []rune
	ValuePos core.Pos
	Literal  string
}

RunesLit represents a unicode string literal (u"...").

func (*RunesLit) End added in v0.0.6

func (e *RunesLit) End() core.Pos

End returns the position of first character immediately after the node.

func (*RunesLit) Pos added in v0.0.6

func (e *RunesLit) Pos() core.Pos

Pos returns the position of first character belonging to the node.

func (*RunesLit) String added in v0.0.6

func (e *RunesLit) String() string

type ScanMode

type ScanMode int

ScanMode represents a scanner mode.

const (
	ScanComments ScanMode = 1 << iota
	DoNotInsertSemis
)

List of scanner modes.

type Scanner

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

Scanner reads the Kavun source text.

func NewScanner

func NewScanner(file *SourceFile, src []byte, errorHandler ScannerErrorHandler, mode ScanMode) *Scanner

NewScanner creates a Scanner.

func (*Scanner) Backup

func (s *Scanner) Backup() ScannerBackup

Backup returns a backup of the scanner state.

func (*Scanner) ErrorCount

func (s *Scanner) ErrorCount() int

ErrorCount returns the number of errors.

func (*Scanner) Restore

func (s *Scanner) Restore(b ScannerBackup)

Restore restores the scanner state from a backup.

func (*Scanner) Scan

func (s *Scanner) Scan() (tok token.Token, literal string, pos core.Pos)

Scan returns a token, token literal and its position.

type ScannerBackup

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

ScannerBackup represents a backup of the scanner state.

type ScannerErrorHandler

type ScannerErrorHandler func(pos SourceFilePos, msg string)

ScannerErrorHandler is an error handler for the scanner.

type SelectorExpr

type SelectorExpr struct {
	Expr Expr
	Sel  Expr
}

SelectorExpr represents a selector expression.

func (*SelectorExpr) End

func (e *SelectorExpr) End() core.Pos

End returns the position of first character immediately after the node.

func (*SelectorExpr) Pos

func (e *SelectorExpr) Pos() core.Pos

Pos returns the position of first character belonging to the node.

func (*SelectorExpr) String

func (e *SelectorExpr) String() string

type SliceExpr

type SliceExpr struct {
	Expr   Expr
	LBrack core.Pos
	Low    Expr
	High   Expr
	Step   Expr
	RBrack core.Pos
}

SliceExpr represents a slice expression.

func (*SliceExpr) End

func (e *SliceExpr) End() core.Pos

End returns the position of first character immediately after the node.

func (*SliceExpr) Pos

func (e *SliceExpr) Pos() core.Pos

Pos returns the position of first character belonging to the node.

func (*SliceExpr) String

func (e *SliceExpr) String() string

type SourceFile

type SourceFile struct {

	// SourceFile name as provided to AddFile
	Name string
	// SourcePos value range for this file is [base...base+size]
	Base int
	// SourceFile size as provided to AddFile
	Size int
	// Lines contains the offset of the first character for each line
	// (the first entry is always 0)
	Lines []int
	// contains filtered or unexported fields
}

SourceFile represents a source file.

func (*SourceFile) AddLine

func (f *SourceFile) AddLine(offset int)

AddLine adds a new line.

func (*SourceFile) FileSetPos

func (f *SourceFile) FileSetPos(offset int) core.Pos

FileSetPos returns the position in the file set.

func (*SourceFile) LineCount

func (f *SourceFile) LineCount() int

LineCount returns the current number of lines.

func (*SourceFile) LineStart

func (f *SourceFile) LineStart(line int) core.Pos

LineStart returns the position of the first character in the line.

func (*SourceFile) Offset

func (f *SourceFile) Offset(p core.Pos) int

Offset translates the file set position into the file offset.

func (*SourceFile) Position

func (f *SourceFile) Position(p core.Pos) (pos SourceFilePos)

Position translates the file set position into the file position.

func (*SourceFile) Set

func (f *SourceFile) Set() *SourceFileSet

Set returns SourceFileSet.

type SourceFilePos

type SourceFilePos struct {
	Filename string // filename, if any
	Offset   int    // offset, starting at 0
	Line     int    // line number, starting at 1
	Column   int    // column number, starting at 1 (byte count)
}

SourceFilePos represents a position information in the file.

func (SourceFilePos) IsValid

func (p SourceFilePos) IsValid() bool

IsValid returns true if the position is valid.

func (SourceFilePos) String

func (p SourceFilePos) String() string

String returns a string in one of several forms:

file:line:column    valid position with file name
file:line           valid position with file name but no column (column == 0)
line:column         valid position without file name
line                valid position without file name and no column (column == 0)
file                invalid position with file name
-                   invalid position without file name

type SourceFileSet

type SourceFileSet struct {
	Base     int           // base offset for the next file
	Files    []*SourceFile // list of files in the order added to the set
	LastFile *SourceFile   // cache of last file looked up
}

SourceFileSet represents a set of source files.

func NewFileSet

func NewFileSet() *SourceFileSet

NewFileSet creates a new file set.

func (*SourceFileSet) AddFile

func (s *SourceFileSet) AddFile(filename string, base, size int) *SourceFile

AddFile adds a new file in the file set.

func (*SourceFileSet) File

func (s *SourceFileSet) File(p core.Pos) (f *SourceFile)

File returns the file that contains the position p. If no such file is found (for instance for p == NoPos), the result is nil.

func (*SourceFileSet) Position

func (s *SourceFileSet) Position(p core.Pos) (pos SourceFilePos)

Position converts a SourcePos p in the file-set into a SourceFilePos value.

func (*SourceFileSet) Size

func (s *SourceFileSet) Size() (size int64)

Size of all files in this set in bytes.

type Stmt

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

Stmt represents a statement in the AST.

type StringLit

type StringLit struct {
	Value    string
	ValuePos core.Pos
	Literal  string
}

StringLit represents a string literal.

func (*StringLit) End

func (e *StringLit) End() core.Pos

End returns the position of first character immediately after the node.

func (*StringLit) Pos

func (e *StringLit) Pos() core.Pos

Pos returns the position of first character belonging to the node.

func (*StringLit) String

func (e *StringLit) String() string

type UnaryExpr

type UnaryExpr struct {
	Expr     Expr
	Token    token.Token
	TokenPos core.Pos
}

UnaryExpr represents an unary operator expression.

func (*UnaryExpr) End

func (e *UnaryExpr) End() core.Pos

End returns the position of first character immediately after the node.

func (*UnaryExpr) Pos

func (e *UnaryExpr) Pos() core.Pos

Pos returns the position of first character belonging to the node.

func (*UnaryExpr) String

func (e *UnaryExpr) String() string

type UndefinedLit

type UndefinedLit struct {
	TokenPos core.Pos
}

UndefinedLit represents an undefined literal.

func (*UndefinedLit) End

func (e *UndefinedLit) End() core.Pos

End returns the position of first character immediately after the node.

func (*UndefinedLit) Pos

func (e *UndefinedLit) Pos() core.Pos

Pos returns the position of first character belonging to the node.

func (*UndefinedLit) String

func (e *UndefinedLit) String() string

Jump to

Keyboard shortcuts

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