~mna/siberian

1b54b1d9f1f30cd518f343131dc5be3a58caaddc — Martin Angers 4 years ago f3c8ffd
add And matcher, fix escape in json parser
2 files changed, 13 insertions(+), 3 deletions(-)

M ebnf.go
M internal/jsonmatcher/jsonmatcher.go
M ebnf.go => ebnf.go +12 -2
@@ 23,8 23,18 @@ func (a *Alt) Match(b []byte, p int) int {
// and a no-match if m does match.
func Not(m Matcher) MatcherFunc {
	return func(b []byte, p int) int {
		n := m.Match(b, p)
		if n >= 0 {
		if n := m.Match(b, p); n < 0 {
			return 0
		}
		return -1
	}
}

// And returns a Matcher that returns a zero-match if m does match, and
// a no-match if m does not match.
func And(m Matcher) MatcherFunc {
	return func(b []byte, p int) int {
		if n := m.Match(b, p); n < 0 {
			return -1
		}
		return 0

M internal/jsonmatcher/jsonmatcher.go => internal/jsonmatcher/jsonmatcher.go +1 -1
@@ 122,7 122,7 @@ var (
	}}

	mustEscapeChar   = siberian.ASCII(buildASCIITable("\x00-\x1f", "\"\\"))
	singleEscapeChar = siberian.ASCII(buildASCIITable("\\/bfnrt"))
	singleEscapeChar = siberian.ASCII(buildASCIITable("\\/bfnrt\""))
	unicodeEscapeSeq = &siberian.Seq{Ms: []siberian.Matcher{
		siberian.Equal("u"),
		&siberian.Repeat{