text

package
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 19, 2018 License: MPL-2.0 Imports: 7 Imported by: 5

Documentation

Overview

Package text defines a text input reader and basic terminal parsers.

Index

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

func NewFilePosition(filename string, pos int, line int, col int) Position

NewFilePosition creates a new position instance with a filename

func NewPosition

func NewPosition(pos int, line int, col int) Position

NewPosition creates a new position instance

func (Position) Col

func (p Position) Col() int

Col returns with the column position

func (Position) Filename

func (p Position) Filename() string

Filename returns with the file name if any

func (Position) Line

func (p Position) Line() int

Line returns with the line position

func (Position) Pos

func (p Position) Pos() int

Pos returns with the byte position

func (Position) String

func (p Position) String() string

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

func NewFileReader(filename string, ignoreWhitespaces bool) (*Reader, error)

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

func NewReader(b []byte, filename string, ignoreWhitespaces bool) *Reader

NewReader creates a new reader instance The Windows-style line endings (\r\n) are automatically replaced with Unix-style line endings (\n).

func (*Reader) Clone

func (r *Reader) Clone() reader.Reader

Clone creates a new reader with the same position

func (*Reader) Cursor

func (r *Reader) Cursor() reader.Position

Cursor returns with the cursor's position

func (*Reader) IsEOF

func (r *Reader) IsEOF() bool

IsEOF returns true if we reached the end of the buffer

func (*Reader) PeekMatch

func (r *Reader) PeekMatch(expr string) ([]string, bool)

PeekMatch reads a set of characters matching the given regular expression but doesn't move the cursor Also it never ignores whitespaces

func (*Reader) PeekRune

func (r *Reader) PeekRune() (ch rune, size int, err error)

PeekRune reads the next character but does not move the cursor

func (*Reader) ReadMatch

func (r *Reader) ReadMatch(expr string, includeWhitespaces bool) ([]string, reader.Position, bool)

ReadMatch reads a set of characters matching the given regular expression

func (*Reader) ReadRune

func (r *Reader) ReadRune() (ch rune, size int, err error)

ReadRune reads the next character

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

func (*Reader) Remaining

func (r *Reader) Remaining() int

Remaining returns with the remaining character count

func (*Reader) String

func (r *Reader) String() string

Directories

Path Synopsis
Package terminal contains basic terminal parsers for text parsing
Package terminal contains basic terminal parsers for text parsing

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL