Skip to content

Commit

Permalink
Fixes couchbaselabs#20: N1QL-like parser using participle
Browse files Browse the repository at this point in the history
This commit uses participle to build a parser that will be used for XDCR's advanced filtering feature.
It is similar to N1QL with a few differences
  • Loading branch information
nelio2k committed Jan 25, 2019
1 parent 95c036d commit c8a3c47
Show file tree
Hide file tree
Showing 7 changed files with 1,806 additions and 21 deletions.
22 changes: 22 additions & 0 deletions constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package gojsonsm

import (
"fmt"
"regexp"
)

// Function related constants
Expand Down Expand Up @@ -104,3 +105,24 @@ const (
type checkAndGetKeyFunc func(string) (bool, string)
type funcNameType string
type funcRecursiveIdx int

// Support for pcre's lookahead class of regex
const lookAheadPattern = "\\(\\?\\=.+\\)"
const lookBehindPattern = "\\(\\?\\<.+\\)"
const negLookAheadPattern = "\\(\\?\\!.+\\)"
const negLookBehindPattern = "\\(\\?\\<\\!.+\\)"

var pcreCheckers [4]*regexp.Regexp = [...]*regexp.Regexp{regexp.MustCompile(lookAheadPattern),
regexp.MustCompile(lookBehindPattern),
regexp.MustCompile(negLookAheadPattern),
regexp.MustCompile(negLookBehindPattern)}

// Returns true if the value is to be used for pcre types
func tokenIsPcreValueType(token string) bool {
for _, pcreChecker := range pcreCheckers {
if pcreChecker.MatchString(token) {
return true
}
}
return false
}
Loading

0 comments on commit c8a3c47

Please sign in to comment.