Documentation ¶
Index ¶
- Constants
- func AnyHasInvalidReader(strs []string) bool
- func CheckRuleName(name string) error
- func CheckRules(g Grammar) error
- func GrammarLines(g []*Rule) []string
- func HasInvalidReader(str string) bool
- func InvalidReader(format string, a ...interface{}) invalidReader
- func Janus(name string, r Reader) (Reader, Reader)
- func MustCheckRules(g Grammar)
- func MustSetRuleNames(g Grammar)
- func SetRuleNames(g Grammar) error
- func SortSegments(values []Segment)
- func SortSegmentsByOrder(values []Segment, order []string)
- type Basket
- type BoolReader
- type Grammar
- type Graph
- type IntReader
- type Log
- type LogEntry
- type MapFunc
- type Marker
- type MatchFunc
- type Node
- type ReadError
- type ReadFunc
- type Reader
- func Any(list ...interface{}) Reader
- func AnyFold(list ...string) Reader
- func AnyRune(str string) Reader
- func At(r Reader) Reader
- func AtEnd() Reader
- func Between(min rune, max rune) Reader
- func BetweenAny(str string) Reader
- func Body(body, tail Reader) Reader
- func BodyTail(body, tail Reader) Reader
- func BuildBetweenAny(minMax ...rune) Reader
- func Digit() Reader
- func Fold(str string) Reader
- func HexDigit() Reader
- func Holey(min rune, max rune, holes string) Reader
- func Lit(str string) Reader
- func Many(i interface{}) Reader
- func Map(r Reader, f MapFunc) Reader
- func Match(what string, f MatchFunc) Reader
- func Monitor(r Reader, l *Log, info string) Reader
- func NL() Reader
- func Named(name string, r Reader) Reader
- func Not(r Reader) Reader
- func Opt(i interface{}) Reader
- func Past(i interface{}) Reader
- func Pick(r Reader, b *Basket, info string) Reader
- func RuleName() Reader
- func Rune(r rune) Reader
- func Seq(list ...interface{}) Reader
- func Set(ranges string, singles string) Reader
- func SkipSeq(skip Reader, list ...interface{}) Reader
- func SkipWSSeq(list ...interface{}) Reader
- func Times(n int, r Reader) Reader
- func To(i interface{}) Reader
- func WS() Reader
- func Wrap(what string, f ReadFunc) Reader
- func Zom(i interface{}) Reader
- type Rule
- type Scanner
- func (s *Scanner) AtEnd() bool
- func (s *Scanner) AtStart() bool
- func (s *Scanner) BoolErrorFor(ok bool, name string) error
- func (s *Scanner) Capture(f ScopeFunc) (string, bool)
- func (s *Scanner) CaptureUse(r Reader) (string, error)
- func (s *Scanner) ErrorFor(name string) error
- func (s *Scanner) Get(t Token) string
- func (s *Scanner) Head() string
- func (s *Scanner) If(str string) bool
- func (s *Scanner) IfAny(strs ...string) bool
- func (s *Scanner) IfAnyRune(str string) bool
- func (s *Scanner) IfBetween(min, max rune) bool
- func (s *Scanner) IfFold(str string) bool
- func (s *Scanner) IfMatch(check MatchFunc) bool
- func (s *Scanner) IfRune(r rune) bool
- func (s *Scanner) LineCol(tab int) (int, int)
- func (s *Scanner) Mark() Marker
- func (s *Scanner) Move(n int) bool
- func (s *Scanner) MoveRunes(n int) bool
- func (s *Scanner) NewBasket() *Basket
- func (s *Scanner) NewBasketFor(g Grammar) *Basket
- func (s *Scanner) ReadBool(format string) (bool, error)
- func (s *Scanner) ReadInt(base int, bitSize int) (int64, error)
- func (s *Scanner) ReadRune() (rune, error)
- func (s *Scanner) ReadUint(base int, bitSize int) (uint64, error)
- func (s *Scanner) RevIf(str string) bool
- func (s *Scanner) RevIfAny(strs []string) bool
- func (s *Scanner) RevIfAnyRune(str string) bool
- func (s *Scanner) RevIfBetween(min, max rune) bool
- func (s *Scanner) RevIfFold(str string) bool
- func (s *Scanner) RevIfMatch(check MatchFunc) bool
- func (s *Scanner) RevIfRune(r rune) bool
- func (s *Scanner) RevReadRune() (rune, error)
- func (s *Scanner) RevTo(str string) bool
- func (s *Scanner) RevToAnyRune(str string) bool
- func (s *Scanner) RevToBetween(min, max rune) bool
- func (s *Scanner) RevToFold(str string) bool
- func (s *Scanner) RevToMatch(check MatchFunc) bool
- func (s *Scanner) RevToRune(r rune) bool
- func (s *Scanner) RevWhileAnyRune(str string) bool
- func (s *Scanner) RevWhileBetween(min, max rune) bool
- func (s *Scanner) RevWhileMatch(check MatchFunc) bool
- func (s *Scanner) RevWhileRune(r rune) bool
- func (s *Scanner) ScanString(n int) (string, bool)
- func (s *Scanner) Scope(f ScopeFunc) bool
- func (s *Scanner) Segmentate(segments []Segment) ([]Segment, error)
- func (s *Scanner) Since(m Marker) string
- func (s *Scanner) Tail() string
- func (s *Scanner) To(str string) bool
- func (s *Scanner) ToAnyRune(str string) bool
- func (s *Scanner) ToBetween(min, max rune) bool
- func (s *Scanner) ToEnd() bool
- func (s *Scanner) ToFold(str string) bool
- func (s *Scanner) ToMarker(m Marker) bool
- func (s *Scanner) ToMatch(check MatchFunc) bool
- func (s *Scanner) ToRune(r rune) bool
- func (s *Scanner) ToStart() bool
- func (s *Scanner) Tokenize(f ScopeFunc) (Token, bool)
- func (s *Scanner) TokenizeUse(r Reader) (Token, error)
- func (s *Scanner) Trace(f ScopeFunc) (string, bool)
- func (s *Scanner) TraceUse(r Reader) (string, error)
- func (s *Scanner) TraceUseFunc(f ReadFunc) (string, error)
- func (s *Scanner) Use(r Reader) error
- func (s *Scanner) UseFunc(f ReadFunc) error
- func (s *Scanner) While(f ScopeFunc) bool
- func (s *Scanner) WhileAnyRune(str string) bool
- func (s *Scanner) WhileBetween(min, max rune) bool
- func (s *Scanner) WhileMatch(check MatchFunc) bool
- func (s *Scanner) WhileRune(r rune) bool
- type ScopeFunc
- type Segment
- type Token
- type Tracker
- type UintReader
Constants ¶
const InvalidReaderMarker = "::INVALID-READER::"
InvalidReaderMarker is the value that can be used to identify invalid reader in a Reader, Rule or Grammar.
Variables ¶
This section is empty.
Functions ¶
func AnyHasInvalidReader ¶
AnyHasInvalidReader returns true if any of the strings in strs contains the :INVALID-READER: marker.
func CheckRuleName ¶
CheckRuleName validates the Name field of a RuleReader.
func CheckRules ¶
CheckRules checks if the Rules in a Grammar have a Name and a Reader set.
func GrammarLines ¶
GrammarRules calls the Rule function on all rules and returns the result.
func HasInvalidReader ¶
HasInvalidReader returns true if str contains the :INVALID-READER: marker.
func InvalidReader ¶
func InvalidReader(format string, a ...interface{}) invalidReader
InvalidReader is a Reader that allways fails. The arguments will be passed to fmt.Errorf.
func Janus ¶
Janus creates two Reader. The first one tries to match with r. If the first matches expects the second the matched sub string.
func MustCheckRules ¶
func MustCheckRules(g Grammar)
MustCheckRules panics if an error occurs during CheckRules.
func MustSetRuleNames ¶
func MustSetRuleNames(g Grammar)
MustSetRuleNames panics if an error occurs during SetRuleNames.
func SetRuleNames ¶
SetRuleNames sets the rule names via the associated Field-Tag.
func SortSegments ¶
func SortSegments(values []Segment)
SortSegments sorts the segments in a slice. Segments that cover other segments will appear before the covered values.
func SortSegmentsByOrder ¶
SortSegmentsByOrder sorts like SortSegments with an order as additional tiebreaker. The appearence of an information in the order slice determines the order for segments with equal tokens.
Types ¶
type Basket ¶
type Basket struct {
// contains filtered or unexported fields
}
Basket can be used to Pick readed Segments.
type BoolReader ¶
------------------------------------------------------------------------------ BoolReader is a Reader that stores the readed bool value in the field Value.
func Bool ¶
func Bool(format string) *BoolReader
Bool creates a Reader to Read bool values from the scanner. Valid format values are - "l" for true and false - "U" for TRUE and FALSE - "Cc" for True and False - "*" for all cases An empty format string will be interpreted as "*".
func (*BoolReader) Read ¶
func (r *BoolReader) Read(s *Scanner) error
func (*BoolReader) What ¶
func (r *BoolReader) What() string
type Graph ¶
type Graph struct {
Root *Node
}
Graph allows to arrange the picked values hierarchically.
func BuildGraph ¶
BuildGraph creates a graph with the segments. The name argument will be used as the info of the root node.
type IntReader ¶
------------------------------------------------------------------------------ IntReader is a Reader that stores the readed int value in the field Value.
type Log ¶
type Log struct { Entries []LogEntry // contains filtered or unexported fields }
func MonitorGrammar ¶
func (*Log) PrintWithPreview ¶
type MapFunc ¶
type MapFunc func(Token)
------------------------------------------------------------------------------
type Marker ¶
type Marker int
---------------------------------------------------------------------- Marker Marker represents a position in the text that will be scanned.
type MatchFunc ¶
---------------------------------------------------------------------- match Type of functions to check a rune.
type ReadError ¶
Error type that ReadFunc and the Reader here return.
type Reader ¶
Reader can be used by the scanner to read from the scanner.
func Any ¶
func Any(list ...interface{}) Reader
Any creates a Reader that tries to Read with any of the given Reader. The type of the list values can be rune, string or Reader. The first Reader that reads without an error will be used.
func AnyFold ¶
AnyFold creates a Reader that tries to Read any of the strings in list. The first string that matches under Unicode case-folding will be used.
func At ¶
At creates a Reader that checks the current postion of the scanner. The Reader does not move the scanner.
func BetweenAny ¶
BetweenAny creates a Reader that tries to Read a rune that is between any of the ranges that str describes. A range can look like "a-z", multible ranges can look like "a-zA-Z0-9". An invalid str value that can't be interpreted lead to an invalid reader.
func Body ¶
Body creates a Reader that ends before something that matches tail and all runes inbetween can be read with body.
func BodyTail ¶
BodyTail creates a Reader that ends with something that matches tail and all runes inbetween can be read with body.
func BuildBetweenAny ¶
BuildBetweenAny creates a Reader that tries to Read a rune that is between any of the ranges that minMax descibe. The number minMax arguments must be even, an invalid number of minMax values lead to an invalid reader.
func Digit ¶
func Digit() Reader
------------------------------------------------------------------------------ Digit creates a Reader that reads the digit runes '0'-'9'
func HexDigit ¶
func HexDigit() Reader
------------------------------------------------------------------------------ HexDigit creates a Reader that reads the hex digit runes '0'-'9'/'a'-'f'/'A'-'F'.
func Holey ¶
Holey creates a Reader that tries to Read a rune that is >= min and <= max without the runes in holes.
func Many ¶
func Many(i interface{}) Reader
Many creates a Reader that expects that i matches one or more times. The type of i can be rune, string or Reader. See Zom for a Reader that expects zero or more.
func NL ¶
func NL() Reader
------------------------------------------------------------------------------ NL creates a Reader to read new lines.
func Opt ¶
func Opt(i interface{}) Reader
Opt creates Reader that catches the error that i can produce and returns allways nil. The type of i can be rune, string or Reader.
func Past ¶
func Past(i interface{}) Reader
Past creates a Reader that reads until i matches, with the matched part. The type of i can be rune, string or Reader.
func Pick ¶
Pick creates a Reader that appends the Segments that r reads forward to the Basket with info as Info value.
func RuleName ¶
func RuleName() Reader
RuleName returns a Reader to validate a Name field of a RuleReader.
func Seq ¶
func Seq(list ...interface{}) Reader
Seq creates a Reader that tries to Read with all readers in list sequential. The type of the list values can be rune, string or Reader.
func Set ¶
Set creates a Reader that tries to Read a rune that is between any of the ranges and singles describe. A range can look like "a-z", multible ranges can look like "a-zA-Z0-9". A single value is a range that covers a single value. An invalid ranges value that can't be interpreted lead to an invalid reader.
func SkipSeq ¶
SkipSeq creates a Reader that tries to Read with all readers in list sequential and skip add the beginning, between and the end everything that matches skip. The type of the list values can be rune, string or Reader.
func SkipWSSeq ¶
func SkipWSSeq(list ...interface{}) Reader
SkipSeq creates a Reader that tries to Read with all readers in list sequential and skip whitespaces add the beginning, between and the end. The type of the list values can be rune, string or Reader.
func To ¶
func To(i interface{}) Reader
To creates a Reader that reads until i matches, without the matched part. The type of i can be rune, string or Reader.
type Rule ¶
------------------------------------------------------------------------------ RuleReader can be used to set the rules of a grammar.
func CollectRules ¶
CollectRules collects the Rules in a Grammar.
type Scanner ¶
type Scanner struct { Tracker Tracker // contains filtered or unexported fields }
func NewRevScanner ¶
----------------------------------------------------------------------------- Creates a new Scanner to scan the str string and moves the scanner to the end.
func NewScanner ¶
Creates a new Scanner to scan the str string.
func (*Scanner) BoolErrorFor ¶
Generates a ErrorFor if ok is false, otherwise returns the function nil.
func (*Scanner) CaptureUse ¶
CaptureUse returns the sub string that was scanned by r.
func (*Scanner) If ¶
---------------------------------------------------------------------- string Moves s the length of str forward if Tail() has str as the prefix. Returns true if s was moved, otherwise false.
func (*Scanner) IfAny ¶
Moves s the length of the value in strs forward if Tail() that is the prefix. Returns true if s was moved, otherwise false.
func (*Scanner) IfAnyRune ¶
--------------------------------------------------------------------- anyrune Moves s one rune forward if the first rune in Tail() is any of the runes in str. Returns true if s was moved, otherwise false.
func (*Scanner) IfBetween ¶
Moves s one rune forward if the first rune in Tail() is >= min and <= max. Returns true if s was moved, otherwise false.
func (*Scanner) IfFold ¶
------------------------------------------------------------------------ fold Moves s the length of str forward if Tail() has str as the prefix under Unicode case-folding. Returns true if s was moved, otherwise false.
func (*Scanner) IfMatch ¶
Moves s one rune value forward if the first rune in Tail() passes the check. Returns true if s was moved, otherwise false.
func (*Scanner) IfRune ¶
------------------------------------------------------------------------ rune Moves s one rune value forward if the first rune in Tail() equals r. Returns true if s was moved, otherwise false.
func (*Scanner) Move ¶
A positive value moves s n bytes to the right, a negative value moves s n bytes to the left.
func (*Scanner) MoveRunes ¶
A positve value moves s n runes to the right, a negative value moves s n runes to the left.
func (*Scanner) NewBasketFor ¶
Returns a new empty Basket that is coupled as Tracker on the scanner. Each Rule that matches picks the Segment to the Basket.
func (*Scanner) ReadBool ¶
ReadBool reads bool value from the scanner. Valid format values are - "l" for true and false - "U" for TRUE and FALSE - "Cc" for True and False - "*" for all cases An empty format string will be interpreted as "*".
func (*Scanner) ReadInt ¶
ReadInt reads a integer value from the scanner. Valid base values are 8. 10 and 16. Valid bitSize values are 8, 16, 32 and 64.
func (*Scanner) ReadUint ¶
ReadUint reads a unsigned integer value from the scanner. Valid base values are 8, 10 and 16. Valid bitSize values are 8, 16, 32 and 64.
func (*Scanner) RevIf ¶
---------------------------------------------------------------------- string Moves s the length of str backward if Head() has str as the prefix. Returns true if s was moved, otherwise false.
func (*Scanner) RevIfAny ¶
Moves s the length fo the value in strs backward if Head() is the suffix. Returns true if s was moved, otherwise false.
func (*Scanner) RevIfAnyRune ¶
--------------------------------------------------------------------- anyrune Moves s one rune backward if the last rune in Head() is any of the runes in str. Returns true if s was moved, otherwise false.
func (*Scanner) RevIfBetween ¶
--------------------------------------------------------------------- between Moves s one rune backward if the last rune in Head() is >= min and <= max. Returns true if s was moved, otherwise false.
func (*Scanner) RevIfFold ¶
------------------------------------------------------------------------ fold Moves s the length of str backward if Head() has str as the suffix under Unicode case-folding. Returns true if s was moved, otherwise false.
func (*Scanner) RevIfMatch ¶
---------------------------------------------------------------------- match Moves s one rune backward if the last rune in Head() passes the check. Returns true if s was moved, otherwise false.
func (*Scanner) RevIfRune ¶
------------------------------------------------------------------------ rune Moves s one rune value backward if the last rune in Head() equals r. Returns true if s was moved, otherwise false.
func (*Scanner) RevReadRune ¶
RevReadRune reads one rune value from the scanner the reverse way.
func (*Scanner) RevTo ¶
Moves s to the last appearance of str in Head(). Returns true if s was moved, otherwise false.
func (*Scanner) RevToAnyRune ¶
Moves s to the last rune in Head() that matches any of the runes in str. Returns true if a match was found, otherwise false.
func (*Scanner) RevToBetween ¶
Moves s to the last rune in Head() that is >= min and <= max. Returns true if s was moved, otherwise false.
func (*Scanner) RevToFold ¶
Moves s to the last appearance of str in Head() under Unicode case-folding. Returns true if s was moved, otherwise false.
func (*Scanner) RevToMatch ¶
Moves s to the last rune in Head() that passes the ckeck. Returns true if s was moved, otherwise false.
func (*Scanner) RevToRune ¶
Moves s to the last rune in Head() that matches with r. The function does not move s if not values matches with r. Returns true if a match was found, otherwise false.
func (*Scanner) RevWhileAnyRune ¶
Moves s to the last rune in Head() that does not match any of the runes in str. Returns true if s was moved, otherwise false.
func (*Scanner) RevWhileBetween ¶
Moves s to the last rune in Head() that is < min or > max. Returns true if s was moved, otherwise false.
func (*Scanner) RevWhileMatch ¶
Moves s to the last rune in Head() that does not pass the ckeck. Returns true if s was moved, otherwise false.
func (*Scanner) RevWhileRune ¶
Moves s to the last rune in Head() that does not match with r. Returns true if s was moved, otherwise false.
func (*Scanner) ScanString ¶
ScanString reads n runes as string from the scanner. The scanner will only be moved if all n runes can be read from the scanner. Returns true if s was moved, otherwise false.
func (*Scanner) Segmentate ¶
Segmentate splits the full string of a Scanner into segments.
func (*Scanner) Tail ¶
----------------------------------------------------------------------- state Returns the right side from the current position in s.
func (*Scanner) To ¶
Moves s to the first appearance of str in Tail(). Returns true if s was moved, otherwise false.
func (*Scanner) ToAnyRune ¶
Moves s to the first rune in Tail() that matches any of the runes in str. Returns true if a match was found, otherwise false.
func (*Scanner) ToBetween ¶
Moves s to the first rune in Tail() that is >= min and <= max. Returns true if a match was found, otherwise false.
func (*Scanner) ToFold ¶
Moves s to the first appearance of str in Tail() under Unicode case-folding. Returns true if s was moved, otherwise false.
func (*Scanner) ToMarker ¶
Moves s to the marked position. Returns true if s was moved, otherwise false.
func (*Scanner) ToMatch ¶
Moves s to the first rune in Tail() that passes the check. Returns true if s was moved, otherwise false.
func (*Scanner) ToRune ¶
Moves s to the first rune in Tail() that matches with r. The function does not move s if no value matches with r. Returns true if a match was found, otherwise false.
func (*Scanner) Tokenize ¶
------------------------------------------------------------------------------ Tokenize marks the sub string that was scanned by f.
func (*Scanner) TokenizeUse ¶
TokenizeUse marks the sub string that was read by r.
func (*Scanner) TraceUseFunc ¶
TraceUseFunc traces the via f traced sub string.
func (*Scanner) UseFunc ¶
UseFunc uses f on the scanner. The scanner is only moved if no error occurs.
func (*Scanner) WhileAnyRune ¶
Moves s to the first rune in Tail() that does not match any of the runes in str. Returns true if s was moved, otherwise false.
func (*Scanner) WhileBetween ¶
Moves s to the first rune in Tail() that is < min or > max. Returns true if s was moved, otherwise false.
func (*Scanner) WhileMatch ¶
Moves s to the first rune in Tail() that does not pass the check. Returns true if s was moved, otherwise false.
type ScopeFunc ¶
type ScopeFunc func() bool
Type of functions to mark the use of the scanner. The main use case are lambda functions.
type Segment ¶
------------------------------------------------------------------------------ Segment is a Token with additional Meta-Information that can be stored in Info.
func (Segment) Segmentate ¶
Segmentate splits a segment into subsegments.
type Token ¶
type Token struct {
// contains filtered or unexported fields
}
Token marks a sub string in a Scanner.
type Tracker ¶
type Tracker interface {
Update(m Marker)
}
Tracker is an interface that can be coupled with a Scannar and track the movemend.
type UintReader ¶
------------------------------------------------------------------------------ UintReader is a Reader that stores the readed uint value in the field Value.
func Uint ¶
func Uint(base int, bitSize int) *UintReader
Uint creates a Reader to Read uint values from the scanner. Valid base values are 8, 10 and 16. Valid bitSize values are 8, 16, 32 and 64.
func (*UintReader) Read ¶
func (r *UintReader) Read(s *Scanner) error
func (*UintReader) What ¶
func (r *UintReader) What() string