Documentation
¶
Index ¶
- Constants
- Variables
- func MustFileLine(f *File, pos Pos) int
- func MustFileOffset(f *File, pos Pos) int
- type Data
- func (d *Data) Bytes() []byte
- func (d *Data) LineData(line int) (r []byte, _ error)
- func (d *Data) LineOffset(line int) (offset int, _ error)
- func (d *Data) LineSliceDataUpDown(line, upCount, downCount int) (up, down []*LineData, s []byte)
- func (d *Data) LinesData(lineStart, count int) (s []*LineData)
- func (d *Data) NumLines() int
- func (d *Data) Pack(line, column int) (offset int, err error)
- func (d *Data) Slice(startLine, numLines int) (_ []byte, err error)
- func (d *Data) SplitLines() (r [][]byte)
- func (d *Data) ToString() string
- func (d *Data) TraceLines(s io.Writer, line, column, up, down int)
- func (d *Data) Unpack(offset int) (line, column int)
- type File
- func (f *File) AddLine(offset int)
- func (f *File) DataPosition(p Pos) (pos FilePos, err error)
- func (f *File) FileSetPos(offset int) (Pos, error)
- func (f *File) LineCount() int
- func (f *File) Offset(p Pos) (int, error)
- func (f *File) Position(p Pos) (pos FilePos, err error)
- func (f *File) SafePosition(p Pos) (pos FilePos)
- func (f *File) Set() *FileSet
- func (f *File) Slice(slicedSet *FileSet, name string, startLine, numLines int) (_ *SliceFile, err error)
- func (f *File) Unpack(offset int) (filename string, line, column int)
- type FilePos
- func (p FilePos) Dump(w io.Writer, up, down int)
- func (p FilePos) FileName() string
- func (p FilePos) IsValid() bool
- func (p FilePos) Pos() Pos
- func (p FilePos) PositionString() (s string)
- func (p FilePos) SourceLineDataRange(up, down int) (line *LineData, upLines, downLines []*LineData)
- func (p FilePos) String() string
- func (p FilePos) TraceLines(w io.Writer, up, down int)
- type FilePosStackTrace
- type FileReaderOption
- type FileSet
- type LineData
- type NextHandlers
- type NumberType
- type Pos
- type PosStackTrace
- type Reader
- func (s *Reader) CallEOFHandlers()
- func (s *Reader) Error(offset int, msg string)
- func (s *Reader) ErrorCount() int
- func (s *Reader) ErrorHandler(h ...ScannerErrorHandler)
- func (s *Reader) Expect(ch rune, msg string) bool
- func (s *Reader) ExpectError(msg string)
- func (s *Reader) FindLineEnd() bool
- func (s *Reader) HasError() bool
- func (s *Reader) IndexOfInlineNoSpace() int
- func (s *Reader) IsSpace() bool
- func (s *Reader) Next()
- func (s *Reader) NextC(count int)
- func (s *Reader) NextNoSpace()
- func (s *Reader) NextPosOf(b byte) (end int)
- func (s *Reader) NextTo(v string)
- func (s *Reader) Peek() byte
- func (s *Reader) PeekAtEndLine() (start, end int)
- func (s *Reader) PeekEq(str string) bool
- func (s *Reader) PeekIdentEq(to string, skip int) bool
- func (s *Reader) PeekInlineNoSpace() byte
- func (s *Reader) PeekN(n int) []byte
- func (s *Reader) PeekNoSingleSpaceEq(to string, skip int) (length int)
- func (s *Reader) PeekNoSpace() byte
- func (s *Reader) PeekNoSpaceEq(to string, skip int) bool
- func (s *Reader) PeekNoSpaceN(n int) []byte
- func (s *Reader) Read(b []byte) (n int, err error)
- func (s *Reader) ReadAt(b rune) []byte
- func (s *Reader) ReadAtMany(quote []byte) []byte
- func (s *Reader) ReadCount(q int) []byte
- func (s Reader) ReadEscape(quote rune) bool
- func (s *Reader) ReadWhen(b rune) []byte
- func (s *Reader) ScanMantissa(base int)
- func (s *Reader) ScanNumber(seenDecimalPoint bool) (tok NumberType, lit string)
- func (s *Reader) ScanRawString() (string, bool)
- func (s *Reader) ScanRune() string
- func (s *Reader) ScanString() string
- func (s *Reader) ScanStringDelimiter(delimiter rune) string
- func (s *Reader) Skip(str string)
- func (s *Reader) SkipWhitespace()
- func (s *Reader) Source() []byte
- func (s *Reader) SourceFile() *File
- func (s *Reader) Start()
- type ScannerErrorHandler
- type SliceFile
- type StartEndDelimiter
- func (m *StartEndDelimiter) Ends(b []byte) bool
- func (m *StartEndDelimiter) EndsR(r rune, b []byte) bool
- func (m *StartEndDelimiter) IsZero() bool
- func (m *StartEndDelimiter) Starts(r rune, b []byte) bool
- func (m *StartEndDelimiter) String() string
- func (m *StartEndDelimiter) Strings() (start, end string)
- func (m *StartEndDelimiter) WrapString(s string) string
Constants ¶
const BOM = 0xFEFF
BOM byte order mark
Variables ¶
Functions ¶
func MustFileLine ¶
func MustFileOffset ¶
Types ¶
type Data ¶
type Data struct {
// contains filtered or unexported fields
}
Data represents a File data
func (*Data) LineOffset ¶
LineOffset returns the offset of the first character in the line or error if line number isn't valid.
func (*Data) LineSliceDataUpDown ¶
LineSliceDataUpDown returns data of line and slices of up and down lines
func (*Data) SplitLines ¶
SplitLines return a splited data into lines
type File ¶
type File struct {
// File name as provided to AddFile
Name string
// SourcePos value range for this file is [base...base+size]
Base int
// File 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
// Index is a index of `set`
Index int
// Data is data
Data *Data
// contains filtered or unexported fields
}
File represents a source file.
func (*File) DataPosition ¶
DataPosition translates the file set position into the file data position.
func (*File) FileSetPos ¶
FileSetPos returns the position in the file set.
func (*File) SafePosition ¶
SafePosition return a position without validations
type FilePos ¶
type FilePos struct {
File *File // 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)
}
FilePos represents a position information in the file.
func MustFilePosition ¶
func (FilePos) PositionString ¶
func (FilePos) SourceLineDataRange ¶
func (FilePos) String ¶
String returns a string in one of several forms:
[empty] no valid pos 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 FilePosStackTrace ¶
type FilePosStackTrace []FilePos
FilePosStackTrace is the stack of source file positions.
type FileReaderOption ¶
type FileReaderOption func(r *Reader)
func FileReaderWithData ¶
func FileReaderWithData(data any) FileReaderOption
func FileReaderWithSkipWhitespaceFunc ¶
func FileReaderWithSkipWhitespaceFunc(f func(fr *Reader)) FileReaderOption
type FileSet ¶
type FileSet struct {
Base int // base offset for the next file
Files []*File // list of files in the order added to the set
LastFile *File // cache of last file looked up
}
FileSet represents a set of source files.
func (*FileSet) AddFileData ¶
AddFileData adds a new file in the file set with data.
func (*FileSet) AppendFileData ¶
AppendFileData appends a new file in the file set with data.
type NextHandlers ¶
type NextHandlers struct {
LineEndHandlers []func()
PostLineEndHandlers []func()
EOFHandlers []func(r *Reader)
}
func (*NextHandlers) CallLineEndHandlers ¶
func (h *NextHandlers) CallLineEndHandlers()
func (*NextHandlers) CallPostLineEndHandlers ¶
func (h *NextHandlers) CallPostLineEndHandlers()
func (*NextHandlers) EOFHandler ¶
func (h *NextHandlers) EOFHandler(f func(r *Reader))
func (*NextHandlers) LineEndHandler ¶
func (h *NextHandlers) LineEndHandler(f func())
func (*NextHandlers) PostLineEndHandler ¶
func (h *NextHandlers) PostLineEndHandler(f func())
type Pos ¶
type Pos int
Pos represents a position in the file set.
const NoPos Pos = 0
NoPos represents an invalid position.
func MustFileLineStartPos ¶
func MustFileSetPos ¶
type Reader ¶
type Reader struct {
Data any
File *File
Ch rune // current character
Offset int // character offset
ReadOffset int // reading offset (position after current character)
NewLineEscaped bool
Src []byte
NewLineEscape func() bool
SkipWhitespaceFunc func(r *Reader)
NextHandlers
// contains filtered or unexported fields
}
func NewFileReader ¶
func NewFileReader(file *File, option ...FileReaderOption) (fr *Reader)
func (*Reader) CallEOFHandlers ¶
func (s *Reader) CallEOFHandlers()
func (*Reader) ErrorCount ¶
ErrorCount returns the number of errors.
func (*Reader) ErrorHandler ¶
func (s *Reader) ErrorHandler(h ...ScannerErrorHandler)
func (*Reader) ExpectError ¶
func (*Reader) FindLineEnd ¶
func (*Reader) IndexOfInlineNoSpace ¶
func (*Reader) NextNoSpace ¶
func (s *Reader) NextNoSpace()
func (*Reader) PeekAtEndLine ¶
func (*Reader) PeekInlineNoSpace ¶
func (*Reader) PeekNoSingleSpaceEq ¶
func (*Reader) PeekNoSpace ¶
func (*Reader) PeekNoSpaceN ¶
func (*Reader) ReadAtMany ¶
func (Reader) ReadEscape ¶
func (*Reader) ScanMantissa ¶
func (*Reader) ScanNumber ¶
func (s *Reader) ScanNumber(seenDecimalPoint bool) (tok NumberType, lit string)
func (*Reader) ScanRawString ¶
func (*Reader) ScanString ¶
func (*Reader) ScanStringDelimiter ¶
func (*Reader) SkipWhitespace ¶
func (s *Reader) SkipWhitespace()
func (*Reader) SourceFile ¶
type ScannerErrorHandler ¶
ScannerErrorHandler is an error handler for the scanner.
type SliceFile ¶
type SliceFile struct {
*File
// contains filtered or unexported fields
}
SliceFile represets a slice source File
type StartEndDelimiter ¶
func (*StartEndDelimiter) Ends ¶
func (m *StartEndDelimiter) Ends(b []byte) bool
func (*StartEndDelimiter) IsZero ¶
func (m *StartEndDelimiter) IsZero() bool
func (*StartEndDelimiter) String ¶
func (m *StartEndDelimiter) String() string
func (*StartEndDelimiter) Strings ¶
func (m *StartEndDelimiter) Strings() (start, end string)
func (*StartEndDelimiter) WrapString ¶
func (m *StartEndDelimiter) WrapString(s string) string