Documentation
¶
Index ¶
- func StripCR(b []byte, comment bool) []byte
- type ArrayLit
- type AssignStmt
- type BadExpr
- type BadStmt
- type BinaryExpr
- type BlockStmt
- type BoolLit
- type BranchStmt
- type CallExpr
- type CondExpr
- type DecimalLit
- type DeferStmt
- type EmptyStmt
- type Error
- type ErrorList
- type ExportStmt
- type Expr
- type ExprStmt
- type FStringLit
- type FStringPart
- type File
- type FloatLit
- type ForInStmt
- type ForStmt
- type FuncLit
- type FuncType
- type Ident
- type IdentList
- type IfStmt
- type ImmutableExpr
- type ImportExpr
- type IncDecStmt
- type IndexExpr
- type IntLit
- type MethodCallExpr
- type Node
- type ParenExpr
- type Parser
- type RecordElementLit
- type RecordLit
- type ReturnStmt
- type RuneLit
- type RunesLit
- type ScanMode
- type Scanner
- type ScannerBackup
- type ScannerErrorHandler
- type SelectorExpr
- type SliceExpr
- type SourceFile
- func (f *SourceFile) AddLine(offset int)
- func (f *SourceFile) FileSetPos(offset int) core.Pos
- func (f *SourceFile) LineCount() int
- func (f *SourceFile) LineStart(line int) core.Pos
- func (f *SourceFile) Offset(p core.Pos) int
- func (f *SourceFile) Position(p core.Pos) (pos SourceFilePos)
- func (f *SourceFile) Set() *SourceFileSet
- type SourceFilePos
- type SourceFileSet
- type Stmt
- type StringLit
- type UnaryExpr
- type UndefinedLit
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ArrayLit ¶
ArrayLit represents an array literal.
type AssignStmt ¶
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 ¶
BadExpr represents a bad expression.
type BadStmt ¶
BadStmt represents a bad statement.
type BinaryExpr ¶
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 ¶
BlockStmt represents a block statement.
type BoolLit ¶
BoolLit represents a boolean literal.
type BranchStmt ¶
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 ¶
CallExpr represents a function call expression.
type CondExpr ¶
CondExpr represents a ternary conditional expression.
type DecimalLit ¶
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 EmptyStmt ¶
EmptyStmt represents an empty statement.
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.
type ExportStmt ¶
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.
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.
type FloatLit ¶
FloatLit represents a floating point literal.
type ForInStmt ¶
ForInStmt represents a for-in statement.
type ForStmt ¶
ForStmt represents a for statement.
type FuncLit ¶
FuncLit represents a function literal.
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.
type Ident ¶
Ident represents an identifier.
type IdentList ¶
IdentList represents a list of identifiers.
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.
type ImmutableExpr ¶
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 ¶
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 ¶
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 ¶
IndexExpr represents an index expression.
type IntLit ¶
IntLit represents an integer literal.
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 ¶
ParenExpr represents a parenthesis wrapped expression.
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser parses the Kavun source files.
type RecordElementLit ¶
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.
type ReturnStmt ¶
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
RuneLit represents a character literal.
func (*RuneLit) End ¶ added in v0.0.6
End returns the position of first character immediately after the node.
type RunesLit ¶ added in v0.0.6
RunesLit represents a unicode string literal (u"...").
func (*RunesLit) End ¶ added in v0.0.6
End returns the position of first character immediately after the node.
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 ¶
ErrorCount returns the number of errors.
func (*Scanner) Restore ¶
func (s *Scanner) Restore(b ScannerBackup)
Restore restores the scanner state from a backup.
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 ¶
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 ¶
SliceExpr represents a slice expression.
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) 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.
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 (*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 ¶
StringLit represents a string literal.
type UnaryExpr ¶
UnaryExpr represents an unary operator expression.
type UndefinedLit ¶
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