text

package
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2021 License: MPL-2.0 Imports: 10 Imported by: 5

Documentation

Overview

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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LeftTrim added in v0.6.0

func LeftTrim(p parsley.Parser, wsMode WsMode) parser.Func

LeftTrim skips the whitespaces before it tries to match the given parser

func RightTrim added in v0.6.0

func RightTrim(p parsley.Parser, wsMode WsMode) parser.Func

RightTrim reads and skips the whitespaces after any parser matches and updates the reader position

func Trim added in v0.6.0

func Trim(p parsley.Parser) parser.Func

Trim removes all whitespaces before and after the result token

Types

type File added in v0.6.0

type File struct {
	// contains filtered or unexported fields
}

File contains the contents of a file and the line offsets for quick line+column lookup

func NewFile added in v0.6.0

func NewFile(filename string, data []byte) *File

NewFile creates a new file object

func ReadFile added in v0.6.0

func ReadFile(filename string) (*File, error)

ReadFile reads a file and creates a File object

func (*File) Len added in v0.6.0

func (f *File) Len() int

Len returns with the length of the file in bytes

func (*File) Pos added in v0.6.0

func (f *File) Pos(pos int) parsley.Pos

Pos returns with a global offset in a file set

func (*File) Position added in v0.6.0

func (f *File) Position(pos int) parsley.Position

Position returns with a Position object for the given offset

func (*File) SetOffset added in v0.6.0

func (f *File) SetOffset(offset int)

SetOffset set the offset of this file related to a file set

type Position

type Position struct {
	Filename string
	Line     int
	Column   int
}

Position is a text file position

func NewPosition

func NewPosition(filename string, line int, column int) *Position

NewPosition creates a new text position

func (Position) String

func (pos 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.

func NewReader

func NewReader(file *File) *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) IsEOF

func (r *Reader) IsEOF(pos parsley.Pos) bool

IsEOF returns true if we reached the end of the buffer

func (*Reader) MatchString added in v0.6.0

func (r *Reader) MatchString(pos parsley.Pos, str string) (parsley.Pos, bool)

MatchString matches the given string

func (*Reader) MatchWord added in v0.6.0

func (r *Reader) MatchWord(pos parsley.Pos, word string) (parsley.Pos, bool)

MatchWord matches the given word It's different from MatchString() as it checks that the next character is not a word character

func (*Reader) Pos added in v0.6.0

func (r *Reader) Pos(cur int) parsley.Pos

Pos returns with the global position for the given cursor

func (*Reader) ReadRegexp added in v0.6.0

func (r *Reader) ReadRegexp(pos parsley.Pos, expr string) (parsley.Pos, []byte)

ReadRegexp matches part of the input based on the given regular expression and returns with the full match

func (*Reader) ReadRegexpSubmatch added in v0.6.0

func (r *Reader) ReadRegexpSubmatch(pos parsley.Pos, expr string) (parsley.Pos, [][]byte)

ReadRegexpSubmatch matches part of the input based on the given regular expression and returns with all capturing groups

func (*Reader) ReadRune

func (r *Reader) ReadRune(pos parsley.Pos, ch rune) (parsley.Pos, bool)

ReadRune matches the given rune

func (*Reader) Readf

func (r *Reader) Readf(pos parsley.Pos, f func(b []byte) ([]byte, int)) (parsley.Pos, []byte)

Readf uses the given function to match the next token

func (*Reader) Remaining

func (r *Reader) Remaining(pos parsley.Pos) int

Remaining returns with the remaining character count

func (*Reader) SkipWhitespaces added in v0.6.0

func (r *Reader) SkipWhitespaces(pos parsley.Pos, wsMode WsMode) (parsley.Pos, parsley.Error)

SkipWhitespaces skips all the whitespaces and returns true if it only encountered the required whitespace characters

type WsMode added in v0.6.0

type WsMode uint8

WsMode is a type for definining how to handle whitespaces after the tokens

const (
	WsNone WsMode = iota
	WsSpaces
	WsSpacesNl
	WsSpacesForceNl
)

Whitespace modes WsNone means no whitespaces will read and skipped after a token WsSpaces means spaces and tabs will be read and skipped automatically after a match WsSpacesNl means spaces, tabs and new lines will be read and skipped automatically after a match

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