Merge pull request #4855 from owncloud/extend-lexer

Support new lex syntaxes
This commit is contained in:
Florian Schade authored and GitHub committed 2022-10-26 14:47:03 +02:00
commit 2eda183b7c
3 files changed
+25 -2

No files matched your search

+8 -2
View File
@@ -10,7 +10,8 @@ import (
// Lexer is responsible for lexing the query.
type Lexer struct {
r *bufio.Reader
r *bufio.Reader
plain bool
}
// NewLexer creates a new Lexer
@@ -33,6 +34,7 @@ func (l *Lexer) Scan() (Token, string) {
}
if r == '"' {
l.plain = !l.plain
return TQuotationMark, ""
}
@@ -40,6 +42,10 @@ func (l *Lexer) Scan() (Token, string) {
return TNegation, ""
}
if r == '+' {
return TAddition, ""
}
if r != ':' {
l.unread()
return l.scanUnknown(TValue)
@@ -68,7 +74,7 @@ func (l *Lexer) scanUnknown(t Token) (Token, string) {
break
}
if r == ':' {
if r == ':' && !l.plain {
return TField, buf.String()
}
+15
View File
@@ -317,6 +317,21 @@ func TestLexer(t *testing.T) {
{k: TEof},
},
},
{
input: "+ID:1284d238-aa92-42ce-bdc4-0b0000009157$4c510ada-c86b-4815-8820-42cdf82c3d51!4c510ada-c86b-4815-8820-42cdf82c3d51 +Mtime:>=\"2022-10-19T10:35:21.064277496+02:00\"",
exp: []kv[Token, string]{
{k: TAddition},
{k: TField, v: "ID"},
{k: TValue, v: "1284d238-aa92-42ce-bdc4-0b0000009157$4c510ada-c86b-4815-8820-42cdf82c3d51!4c510ada-c86b-4815-8820-42cdf82c3d51"},
{k: TAddition},
{k: TField, v: "Mtime"},
{k: TValue, v: ">="},
{k: TQuotationMark},
{k: TValue, v: "2022-10-19T10:35:21.064277496+02:00"},
{k: TQuotationMark},
{k: TEof},
},
},
}
for _, c := range cases {
+2
View File
@@ -8,6 +8,8 @@ const (
TEof Token = iota
// TUnknown unknown token type
TUnknown
// TAddition addition token type
TAddition
// TNegation negation token type
TNegation
// TQuotationMark quotation-mark token type, e.g. not of type - "-"