forked from bi-tm/express-nedb-rest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathorder.js
45 lines (38 loc) · 1.17 KB
/
order.js
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
var grammar = {
"lex": {
"rules": [
["\\s+", "/* skip whitespace */"],
[",", "return ',';"],
["(asc|ASC)\\b", "return 'ASC';"],
["(desc|DESC)\\b", "return 'DESC';"],
["\\w+\\b", "return 'WORD';"],
["$", "return 'EOF';"]
]
},
"operators": [
],
"bnf": {
"order": [
["o EOF", "return $1;"]
],
"o": [
["o , f", "$$ = $1; for (var attr in $3) $$[attr] = $3[attr];"],
["f", "$$ = $1;" ]
],
"f": [
["WORD", "$$ = new Object; $$[$1] = 1;"],
["WORD ASC", "$$ = new Object; $$[$1] = 1;"],
["WORD DESC", "$$ = new Object; $$[$1] = -1;"]
]
}
};
var Parser = require("jison").Parser;
var parser = new Parser(grammar);
module.exports = function(input) {
if (typeof(input) == 'string' && input != "") {
return parser.parse(decodeURI(input));
}
else {
return {};
}
};