matcho

package module
v0.0.0-...-85e9133 Latest Latest
Warning

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

Go to latest
Published: May 19, 2019 License: MIT Imports: 11 Imported by: 3

README

Matcho Go Report Card Build Status

Text processing index abstraction and helpers

Motivation

It was supposed to be a simple parsing job and then it grew up into loopy-checkindex-check-error-regexy stuff?

Now there is one more thing you can throw in

Installation

go get gitlab.com/iamgoroot/matcho

What can (possibly?) it do

So far I used it to parse imports in go files and there are some examples looking up property files and json (not that you have to make json parser out of it.)

It's nice if you need to read that one specific thing out of text (for now only text) but really want to struggle (should i say "less" or "more"? let me know)

See test package for examples.

Basics

First of all: There is no silver bullet. If you better of parsing without Matcho you can grab all the state:

type Matcho struct {
	Source   []byte	//Your string or data
	Index    int	//Position you are in
	ErrorStr string		//Last error string
	OperationResult []byte	//Last "Select" operation result
}

Wrap your with matcho.Of([]byte) or matcho.OfStr(string) and you are ready to go

See Method reference

Usage example

See test package for more examples

Examples basic Examples looping Parsing specific part of json array External tool to parse imports

Debugging

It has debugging interface with "new year mode" just do matcho.DebugOnPort(int) and run app in debug folder

IMAGE ALT TEXT

Contributing

Feel free to contribure with code or feedback

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DebugOnPort

func DebugOnPort(p int)

Types

type DebugInfo

type DebugInfo struct {
	From     int
	To       int
	Data     string //more readable json
	OpResult string
	Error    string

	StackTrace string
}

type InsertPoint

type InsertPoint struct {
	Matcho Matcho
	Value  string
}

type Matcho

type Matcho struct {
	Source          []byte //Your string or data
	Index           int    //Position you are in
	ErrorStr        string //Last error string
	OperationResult []byte //Last "Select" operation result
}

func Join

func Join(matchos ...Matcho) Matcho

func JoinBytes

func JoinBytes(b ...[]byte) Matcho

func Of

func Of(bytes []byte) Matcho

func OfStr

func OfStr(string string) Matcho

func (Matcho) Before

func (m Matcho) Before(token string) Matcho

func (Matcho) Between

func (m Matcho) Between(start, end string) Matcho

func (Matcho) BetweenBlock

func (m Matcho) BetweenBlock(start, end string) Matcho

func (Matcho) CurrentLine

func (m Matcho) CurrentLine() string

func (Matcho) CurrentLineDebug

func (m Matcho) CurrentLineDebug() string

func (Matcho) Cut

func (m Matcho) Cut(start, end Matcho) Matcho

func (Matcho) Dbg

func (m Matcho) Dbg() Matcho

func (Matcho) Eof

func (m Matcho) Eof() bool

End Of File

func (Matcho) Err

func (m Matcho) Err() string

Err

func (Matcho) ErrReset

func (m Matcho) ErrReset() Matcho

End Of File

func (Matcho) ErrSet

func (m Matcho) ErrSet(prt *string) Matcho

Err

func (Matcho) ExpectNot

func (m Matcho) ExpectNot(raw ...string) Matcho

func (Matcho) ExpectRaw

func (m Matcho) ExpectRaw(raw string) Matcho

func (Matcho) ExpectRune

func (m Matcho) ExpectRune(r rune) Matcho

func (Matcho) Fail

func (m Matcho) Fail(err ...string) Matcho

func (Matcho) FailEof

func (m Matcho) FailEof(err ...string) Matcho

func (Matcho) HandleErr

func (m Matcho) HandleErr(handle func(self Matcho) error) Matcho

func (Matcho) HandleOk

func (m Matcho) HandleOk(handle func(self Matcho) error) Matcho

func (Matcho) Indent

func (m Matcho) Indent() Matcho

func (Matcho) Insert

func (m Matcho) Insert(s string) Matcho

Probably breaks all other Matchos

func (Matcho) InsertAll

func (m Matcho) InsertAll(points ...InsertPoint) Matcho

Makes new backing slice

func (Matcho) InsertPoint

func (m Matcho) InsertPoint(s string) InsertPoint

func (Matcho) Len

func (m Matcho) Len() int

func (Matcho) LimitEnd

func (m Matcho) LimitEnd(to string) Matcho

func (Matcho) LimitEndPos

func (m Matcho) LimitEndPos(to Matcho) Matcho

func (Matcho) LimitStartPos

func (m Matcho) LimitStartPos(start Matcho) Matcho

func (Matcho) LookbackExpect

func (m Matcho) LookbackExpect(str string) Matcho

func (Matcho) Maybe

func (m Matcho) Maybe(raw string) Matcho

Set Op on match

func (Matcho) Move

func (m Matcho) Move(off int) Matcho

func (Matcho) MoveTo

func (m Matcho) MoveTo(to Matcho) Matcho

func (Matcho) Next

func (m Matcho) Next(after string) Matcho

func (Matcho) NextAny

func (m Matcho) NextAny(any ...string) Matcho

Sets Op TODO: make faster?

func (Matcho) On

func (m Matcho) On(condition bool, matcho Matcho) Matcho

func (Matcho) OnEof

func (m Matcho) OnEof(matcho Matcho) Matcho

func (Matcho) OnErr

func (m Matcho) OnErr(matcho Matcho) Matcho

Moves received value one position right

func (Matcho) OnErrCall

func (m Matcho) OnErrCall(f func(Matcho) Matcho) Matcho

func (Matcho) OnErrStep

func (m Matcho) OnErrStep(matcho Matcho) Matcho

func (Matcho) OnOk

func (m Matcho) OnOk(matcho Matcho) Matcho

func (Matcho) OnOkCall

func (m Matcho) OnOkCall(f func(Matcho) Matcho) Matcho

func (Matcho) OnOkOpStr

func (m Matcho) OnOkOpStr(op *string) Matcho

func (Matcho) Op

func (m Matcho) Op() Matcho

Returns Matcho for last operation retult

func (Matcho) OpBytes

func (m Matcho) OpBytes() []byte

OpBytes last operation retult

func (Matcho) OpNil

func (m Matcho) OpNil() Matcho

Set last operation retult

func (Matcho) OpSet

func (m Matcho) OpSet(result []byte) Matcho

Set last operation retult

func (Matcho) OpStr

func (m Matcho) OpStr() string

OpStr last operation retult

func (Matcho) Pof

func (m Matcho) Pof() Matcho

Panic Nn ErrorStr

func (Matcho) Pos

func (m Matcho) Pos() int

func (Matcho) Replace

func (m Matcho) Replace(old, new string) Matcho

Makes copy with replaced next occurrence. Places position after replacement

func (Matcho) ReplaceAll

func (m Matcho) ReplaceAll(old, new string) Matcho

func (Matcho) Reset

func (m Matcho) Reset() Matcho

func (Matcho) Rest

func (m Matcho) Rest() []byte

func (Matcho) Rewind

func (m Matcho) Rewind(until string) Matcho

func (Matcho) Select

func (m Matcho) Select(until string) Matcho

func (Matcho) SelectVal

func (m Matcho) SelectVal(allowed string) string

not moves

func (Matcho) SelectVar

func (m Matcho) SelectVar(allowed string) Matcho

moves. get result matcho.SelectVar().Op()

func (Matcho) SelectVarFunc

func (m Matcho) SelectVarFunc(f func(r rune) bool) Matcho

func (Matcho) SelectVarInto

func (m Matcho) SelectVarInto(allowed string, v *string) Matcho

func (Matcho) SelectVarUntil

func (m Matcho) SelectVarUntil(v *string, until string) Matcho

func (Matcho) Skip

func (m Matcho) Skip(anyOf string) Matcho

func (Matcho) SkipSeq

func (m Matcho) SkipSeq(tokens ...string) Matcho

func (Matcho) Slice

func (m Matcho) Slice(beforeCount, afterCount int) Matcho

func (Matcho) SliceCombine

func (m Matcho) SliceCombine(beforeCount int, insert string, afterCount int) Matcho

func (Matcho) SliceHead

func (m Matcho) SliceHead() Matcho

returns slice [:current]

func (Matcho) SliceTail

func (m Matcho) SliceTail() Matcho

returns slice [current:]

func (Matcho) Sp

func (m Matcho) Sp() Matcho

func (Matcho) SpMb

func (m Matcho) SpMb() Matcho

space maybe

func (Matcho) String

func (m Matcho) String() string

func (Matcho) StringDebug

func (m Matcho) StringDebug() string

func (Matcho) UntilEof

func (m Matcho) UntilEof(repeat func(m Matcho) Matcho) Matcho

Loop Success (no fails) or EOF

func (Matcho) UntilFail

func (m Matcho) UntilFail(repeat func(m Matcho) Matcho) Matcho

func (Matcho) UntilPass

func (m Matcho) UntilPass(repeat func(m Matcho) Matcho) Matcho

Loop Success (no fails) or EOF

func (Matcho) Zoe

func (m Matcho) Zoe() Matcho

Zero on error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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