Documentation
¶
Overview ¶
Package source defines source file an source queue for parsers.
Index ¶
- func NormalizeNls(content *[]byte)
- type Pos
- type Queue
- func (q *Queue) Append(s *Source) *Queue
- func (q *Queue) ContentPos() ([]byte, int)
- func (q *Queue) Eof() bool
- func (q *Queue) IsEmpty() bool
- func (q *Queue) LineCol(pos int) (line, col int)
- func (q *Queue) NextSource() bool
- func (q *Queue) Pos() int
- func (q *Queue) Prepend(s *Source) *Queue
- func (q *Queue) Rewind(size int)
- func (q *Queue) Seek(pos int)
- func (q *Queue) Skip(size int)
- func (q *Queue) Source() *Source
- func (q *Queue) SourceName() string
- func (q *Queue) SourcePos() Pos
- type Source
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NormalizeNls ¶
func NormalizeNls(content *[]byte)
NormalizeNls replaces all occurrences of "\r" and "\r\n" with "\n".
Types ¶
type Pos ¶
type Pos struct {
// contains filtered or unexported fields
}
Pos combines captured source, position, line, and column number corresponding to that position. Zero value means no source and position information available.
func (Pos) SourceName ¶
SourceName returns captured source name or empty string.
type Queue ¶
type Queue struct {
// contains filtered or unexported fields
}
Queue represents a queue of source files to be processed.
func (*Queue) Append ¶
Append adds new source to the end of the queue. Does nothing if s is nil. Does not add empty source if the queue is not empty.
func (*Queue) ContentPos ¶
ContentPos returns content of current source and current position, or (nil, 0) if the queue is empty.
func (*Queue) Eof ¶
Eof returns true if the queue is empty or current source position is beyond the end of current source.
func (*Queue) IsEmpty ¶
IsEmpty returns true if the queue is empty (contains no sources) and false otherwise.
func (*Queue) LineCol ¶
LineCol returns line and column number for current source position. Returns (0, 0) if the queue is empty.
func (*Queue) NextSource ¶
NextSource discards current source from the queue. The next source (if there is one) becomes the current one and its saved current position is restored. Returns true if the queue is not empty.
func (*Queue) Prepend ¶
Prepend adds new source to the beginning of the queue. Current position for current source (if there is one) is saved, added source becomes the current one. Does nothing if s is nil. Does not add empty source if the queue is not empty.
func (*Queue) Rewind ¶
Rewind decreases current source position by given amount of bytes. New position will be ≥ 0. Does nothing if size is ≤ 0 or the queue is empty.
func (*Queue) Seek ¶
Seek changes current source position to given value. New position is adjusted so that 0 ≤ position ≤ content length. Does nothing if the queue is empty.
func (*Queue) Skip ¶
Skip increases current source position by given amount of bytes. New position will not exceed current source length. Does nothing if size is ≤ 0 or the queue is empty.
func (*Queue) Source ¶
Source returns current (i.e. first) source in the queue or nil if the queue is empty.
func (*Queue) SourceName ¶
SourceName returns the name of current source or empty string if the queue is empty.
type Source ¶
type Source struct {
// contains filtered or unexported fields
}
Source represents single source file.
func New ¶
New creates new source. Name may be any string identifying the source, does not have to be unique, may be empty. Content should be a valid UTF-8 encoded text, lines should be separated by "\n" rune. Content should not be modified.
func (*Source) LineCol ¶
LineCol returns line and column number (both 1-based) of rune starting at given position in the source content. Negative position is treated as 0, position equal to or higher than length of content is treated as position right after EoF.