textparser

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2025 License: MIT Imports: 7 Imported by: 0

README

textparser

When a regexp is just not convenient…

This library is meant as a quick way of parsing a string by code, but without implementing all the low-level handling from scratch.

Goals

  • be more dynamic than a regexp, easier to branch and with "memory" by allowing Go variables as storage
  • support unicode strings throughout
  • provide rune based as well as string based functions
  • emit relevant and useful error messages

Non-goals

  • streaming support
  • high-performance parsing

Example

Parse Key Value List

Input:

name: Tom Williams
role: CEO
os: Debian Linux

Parsing Code:

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EndOfInputError

type EndOfInputError struct{}

func (EndOfInputError) Error

func (x EndOfInputError) Error() string

type Parser

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

func NewParser

func NewParser(input string) *Parser

func NewParserFromReader

func NewParserFromReader(input io.Reader) (*Parser, error)

func (*Parser) Captured

func (x *Parser) Captured() string

Captured retrieves output since StartCapture was last called.

func (*Parser) CurrentContext

func (x *Parser) CurrentContext() string

func (*Parser) CurrentIndex

func (x *Parser) CurrentIndex() int

CurrentIndex returns the current internal parser index aka how many runes have been processed already.

func (*Parser) GetNext

func (x *Parser) GetNext(runeCount int) (string, error)

GetNext returns the next runeCount runes as a string.

func (*Parser) GetNextMax

func (x *Parser) GetNextMax(runeCount int) string

func (*Parser) GetNextRune

func (x *Parser) GetNextRune() (rune, error)

func (*Parser) HasMore

func (x *Parser) HasMore() bool

func (*Parser) IsExhausted

func (x *Parser) IsExhausted() bool

func (*Parser) LookingAtDigit added in v0.2.0

func (x *Parser) LookingAtDigit() bool

func (*Parser) LookingAtLetter added in v0.2.0

func (x *Parser) LookingAtLetter() bool

func (*Parser) LookingAtRune

func (x *Parser) LookingAtRune(r rune) bool

func (*Parser) LookingAtString

func (x *Parser) LookingAtString(expected string) bool

LookingAtString determines if from the current position, the next runes would equal the expected string provided.

func (*Parser) LookingAtWhitespace

func (x *Parser) LookingAtWhitespace() bool

func (*Parser) MustGetNext

func (x *Parser) MustGetNext(runeCount int) string

func (*Parser) MustGetNextRune

func (x *Parser) MustGetNextRune() rune

func (*Parser) MustGetNextWord

func (x *Parser) MustGetNextWord() string

func (*Parser) MustReadInt

func (x *Parser) MustReadInt() int

func (*Parser) MustReadRestOfInput

func (x *Parser) MustReadRestOfInput() string

func (*Parser) MustReadRestOfLine

func (x *Parser) MustReadRestOfLine() string

func (*Parser) MustReadRune

func (x *Parser) MustReadRune() rune

func (*Parser) MustReadRunes

func (x *Parser) MustReadRunes(runeCount int) []rune

func (*Parser) MustReadToAnyString

func (x *Parser) MustReadToAnyString(limitStrings []string) string

func (*Parser) MustReadToAnyStringOrEnd

func (x *Parser) MustReadToAnyStringOrEnd(limitStrings []string) string

func (*Parser) MustReadToMatching

func (x *Parser) MustReadToMatching(open, close rune) string

func (*Parser) MustReadToPositionString

func (x *Parser) MustReadToPositionString(newPosition int) string

func (*Parser) MustReadToRune

func (x *Parser) MustReadToRune(stopRune rune) string

func (*Parser) MustReadWord

func (x *Parser) MustReadWord() string

func (*Parser) MustSkip

func (x *Parser) MustSkip(runeCount int) *Parser

MustSkip (chainable).

func (*Parser) MustSkipAnyWhitespaces

func (x *Parser) MustSkipAnyWhitespaces() *Parser

func (*Parser) MustSkipNewlines

func (x *Parser) MustSkipNewlines() *Parser

func (*Parser) MustSkipRestOfLine

func (x *Parser) MustSkipRestOfLine() *Parser

func (*Parser) MustSkipSpaces

func (x *Parser) MustSkipSpaces() *Parser

func (*Parser) MustSkipString

func (x *Parser) MustSkipString(expected string) *Parser

func (*Parser) MustSkipToString

func (x *Parser) MustSkipToString(expected string) *Parser

func (*Parser) MustSkipToWhitespace

func (x *Parser) MustSkipToWhitespace() *Parser

func (*Parser) Processed

func (x *Parser) Processed() string

func (*Parser) ReadInt

func (x *Parser) ReadInt() (int, error)

func (*Parser) ReadRestOfInput

func (x *Parser) ReadRestOfInput() (string, error)

func (*Parser) ReadRestOfLine

func (x *Parser) ReadRestOfLine() (string, error)

func (*Parser) ReadRune

func (x *Parser) ReadRune() (rune, error)

func (*Parser) ReadRunes

func (x *Parser) ReadRunes(runeCount int) ([]rune, error)

func (*Parser) ReadToAnyString

func (x *Parser) ReadToAnyString(limitStrings []string) (string, error)

func (*Parser) ReadToAnyStringOrEnd

func (x *Parser) ReadToAnyStringOrEnd(limitStrings []string) (string, error)

func (*Parser) ReadToMatching

func (x *Parser) ReadToMatching(open, close rune) (string, error)

func (*Parser) ReadToPositionString

func (x *Parser) ReadToPositionString(newPosition int) (string, error)

func (*Parser) ReadToRune

func (x *Parser) ReadToRune(stopRune rune) (string, error)

func (*Parser) ReadWord

func (x *Parser) ReadWord() (string, error)

ReadWord reads exactly one word of input. Stops at space, newline and end of input. Error if the input end is already reached.

func (*Parser) Remaining

func (x *Parser) Remaining() string

func (*Parser) RemainingRuneCount

func (x *Parser) RemainingRuneCount() int

func (*Parser) Skip

func (x *Parser) Skip(runeCount int) error

Skip skips runeCount runes without returning them.

func (*Parser) SkipAny

func (x *Parser) SkipAny(runes []rune) error

func (*Parser) SkipAnyWhitespaces

func (x *Parser) SkipAnyWhitespaces() error

func (*Parser) SkipNewlines

func (x *Parser) SkipNewlines() error

func (*Parser) SkipRestOfLine

func (x *Parser) SkipRestOfLine() error

func (*Parser) SkipSpaces

func (x *Parser) SkipSpaces() error

func (*Parser) SkipString

func (x *Parser) SkipString(expected string) error

func (*Parser) SkipTo

func (x *Parser) SkipTo(newIndex int) error

SkipTo skips to index newIndex without returning the intermediate runes (forward only).

func (*Parser) SkipToEnd

func (x *Parser) SkipToEnd() *Parser

func (*Parser) SkipToString

func (x *Parser) SkipToString(expected string) error

func (*Parser) SkipToWhitespace

func (x *Parser) SkipToWhitespace() error

func (*Parser) StartCapture

func (x *Parser) StartCapture() *Parser

StartCapture starts collecting output, see Captured to retrieve it.

func (*Parser) String

func (x *Parser) String() string

Jump to

Keyboard shortcuts

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