Documentation
¶
Overview ¶
Package text defines a text input reader and basic terminal parsers.
Index ¶
- type Position
- type Reader
- func (r *Reader) Clone() reader.Reader
- func (r *Reader) Cursor() reader.Position
- func (r *Reader) IsEOF() bool
- func (r *Reader) PeekMatch(expr string) ([]string, bool)
- func (r *Reader) PeekRune() (ch rune, size int, err error)
- func (r *Reader) ReadMatch(expr string, includeWhitespaces bool) ([]string, reader.Position, bool)
- func (r *Reader) ReadRune() (ch rune, size int, err error)
- func (r *Reader) Readf(f func(b []byte) (string, int, bool), includeWhitespaces bool) (string, reader.Position, bool)
- func (r *Reader) Remaining() int
- func (r *Reader) String() string
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Position ¶
type Position struct {
// contains filtered or unexported fields
}
Position represents a token position. It also contains the line and column indexes.
func NewFilePosition ¶
NewFilePosition creates a new position instance with a filename
func NewPosition ¶
NewPosition creates a new position instance
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
Reader defines a text input reader For more efficient reading it provides methods for regexp matching.
Example ¶
Let's read from a byte array with a regular expression
package main
import (
"fmt"
"github.com/opsidian/parsley/text"
)
func main() {
r := text.NewReader([]byte("abcd"), "", true)
matches, _, _ := r.ReadMatch("ab|cd", false)
fmt.Println(matches[0])
}
Output: ab
func NewFileReader ¶
NewFileReader creates a new reader instance which reads from a file The Windows-style line endings (\r\n) are automatically replaced with Unix-style line endings (\n).
func NewReader ¶
NewReader creates a new reader instance The Windows-style line endings (\r\n) are automatically replaced with Unix-style line endings (\n).
func (*Reader) PeekMatch ¶
PeekMatch reads a set of characters matching the given regular expression but doesn't move the cursor Also it never ignores whitespaces
func (*Reader) ReadMatch ¶
ReadMatch reads a set of characters matching the given regular expression
func (*Reader) Readf ¶
func (r *Reader) Readf(f func(b []byte) (string, int, bool), includeWhitespaces bool) (string, reader.Position, bool)
Readf uses the given function to match the next token