Add tests for gql to sql compile

This commit is contained in:
Vikram Rangnekar
2019-03-24 18:16:03 -04:00
parent 0f5ce2f69d
commit b48a929538
8 changed files with 371 additions and 106 deletions

View File

@ -172,7 +172,7 @@ func (l *lexer) accept(valid string) bool {
return false
}
// accept onsumes a run of runes while they are alpha nums
// acceptAlphaNum consumes a run of runes while they are alpha nums
func (l *lexer) acceptAlphaNum() bool {
n := 0
for r := l.next(); isAlphaNumeric(r); r = l.next() {
@ -182,6 +182,14 @@ func (l *lexer) acceptAlphaNum() bool {
return (n != 0)
}
// acceptComment consumes a run of runes while till the end of line
func (l *lexer) acceptComment() {
n := 0
for r := l.next(); !isEndOfLine(r); r = l.next() {
n++
}
}
// acceptRun consumes a run of runes from the valid set.
func (l *lexer) acceptRun(valid string) {
for strings.ContainsRune(valid, l.next()) {
@ -231,6 +239,10 @@ func lexRoot(l *lexer) stateFn {
l.ignore()
case isSpace(r):
l.ignore()
case r == '#':
l.ignore()
l.acceptComment()
l.ignore()
case r == '@':
l.ignore()
if l.acceptAlphaNum() {

31
qcode/utils.go Normal file
View File

@ -0,0 +1,31 @@
package qcode
import (
"fmt"
"regexp"
"strings"
)
func NewBlacklist(list []string) *regexp.Regexp {
var bl *regexp.Regexp
if len(list) != 0 {
re := fmt.Sprintf("(?i)%s", strings.Join(list, "|"))
bl = regexp.MustCompile(re)
}
return bl
}
func NewFilterMap(filters map[string]string) FilterMap {
fm := make(FilterMap)
for k, v := range filters {
fil, err := CompileFilter(v)
if err != nil {
panic(err)
}
key := strings.ToLower(k)
fm[key] = fil
}
return fm
}