Created
February 16, 2021 10:13
-
-
Save geobde/4b5e4716ba91904dd0a1400415f3155a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%lex | |
%% | |
\s+ | |
\"[^"]+\" return 'WORD' | |
"or" return 'OR' | |
"and" return 'AND' | |
"not" return 'NOT' | |
"(" return '(' | |
")" return ')' | |
<<EOF>> return 'EOF' | |
. return 'INVALID' | |
/lex | |
%left 'OR' 'AND' | |
%left 'NOT' | |
%start expressions | |
%% | |
expressions | |
: e EOF | |
{ | |
var query = $1; | |
return query; | |
} | |
; | |
e | |
: e 'OR' e | |
{$$ = {_or: [$1, $3]};} | |
| e 'AND' e | |
{$$ = {_and: [$1, $3]};} | |
| 'NOT' e %prec NOT | |
{$$ = {_not: $2};} | |
| '(' e ')' | |
{$$ = $2;} | |
| WORD | |
{ | |
$$ = "%" + yytext.substr(1, yytext.length-2) + "%"; | |
$$ = {text: {_like: $$}}; | |
} | |
; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment