This repository has been archived by the owner on Mar 6, 2020. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 22
/
gql.l
46 lines (36 loc) · 1.95 KB
/
gql.l
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/* lexical grammar */
%lex
%options case-insensitive
badcharsincnot [^\s'"\+\,\(\)\>\<=\[\]\-]
badcharsnonot [^\s'"\+\,\(\)\>\<=\[\]]
escapable ['"\+\,\(\)\>\<=\[\]]
%%
\s+ /* skip whitespace */
'NULL' return 'NULL';
'TRUE' return 'TRUE';
'FALSE' return 'FALSE';
[a-zA-Z_][a-zA-Z0-9_\.]*[:] return 'PROP';
[0-9]+(\.[0-9]+)?\b(?![\-]) return 'NUMBER';
'[' return 'LBRACKET';
']' return 'RBRACKET';
{badcharsincnot}(\\{escapable}|{badcharsnonot})+ return 'LITERAL';
['](\\['"]|[^'"])+?['] return 'STRING';
'(' return 'LPAREN';
')' return 'RPAREN';
',' return 'OR';
'+' return 'AND';
'-' return 'NOT';
'>=' return 'GTE';
'<=' return 'LTE';
'>' return 'GT';
'<' return 'LT';
%%
lexer.parseError = function(errStr, object) {
var lines = errStr.split("\n"),
caretPos,
char;
caretPos = lines[2].indexOf("^");
char = lines[1].charAt(caretPos);
lines[0] = "Query Error: unrecognized text \"" + char + "\" in filter at char " + (caretPos + 1);
throw Error(lines.join("\n"));
}