Documentation
¶
Overview ¶
Package scan provide a language independent scanner.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrBlock = errors.New("block not terminated") ErrIllegal = errors.New("illegal token") )
Error definitions.
Functions ¶
This section is empty.
Types ¶
type Scanner ¶
type Scanner struct {
*lang.Spec
Sources Sources // source position registry (multi-file / REPL)
PosBase int // base offset for current source
// contains filtered or unexported fields
}
Scanner contains the scanner rules for a language.
func NewScanner ¶
NewScanner returns a new scanner for a given language specification.
type Source ¶
type Source struct {
Name string
Base int // base byte offset in the unified position space
Len int // length in bytes
// contains filtered or unexported fields
}
Source describes a source text.
type Sources ¶
type Sources []Source
Sources is an ordered list of Source entries.
func (Sources) ByName ¶ added in v0.2.0
ByName returns the source with the given name, or nil if not found. When multiple sources share a name (e.g. the REPL's anonymous chunks), the first registered match is returned.
func (Sources) LineText ¶ added in v0.2.0
LineText returns the source line containing pos, without the trailing newline. Returns "" if pos is out of range.
func (Sources) Resolve ¶
Resolve converts a global byte offset to (source name, line, col). Returns ("", 0, 0) if pos is out of range.
type Token ¶
type Token struct {
Tok lang.Token // token identificator
Pos int // position in source
Str string // string in source
Beg int // length of begin delimiter (block, string)
End int // length of end delimiter (block, string)
}
Token defines a scanner token.
func (*Token) Describe ¶ added in v0.3.0
Describe returns a short human-readable form of t for diagnostics: the token kind plus a quoted, whitespace-collapsed, truncated snippet of its source.