Closed bubunyo closed 4 years ago
This could indeed make sense to improve the parser flexibility but I'd probably call it "Lexed".
// Lexed instructs the lexer to match an arbitrary sequence of characters
// until Fn returns 0 and skip as many runes as returned by Fn on each step
type Lexed struct {
Kind FragmentKind
Designation string
Fn func(Cursor) uint
}
parser.Lexed{
Kind: 100,
Fn: func(crs Cursor) int {
if isEscapedString(crs) {
// Skip this rune and the next one too
return 2
}
if n := allowedStringRune(crs); n > 0 {
// Skip this rune
return n
}
// Stop, end of string reached
return 0
}
}
Proposal
Implement a new pattern type
parse.Any
to match a series of a specified set of characters.Current Workaround
Using
parse.Either
resulting in ugly code and an inefficient parse-tree structure.