Commit f9a78db7 authored by ransome1's avatar ransome1
Browse files

Merge branch 'develop' of github.com:ransome1/sleek into develop

parents a38c0249 1d8c639b
......@@ -4,6 +4,7 @@
filterQuery
= _ left:orExpr _ { return left; }
/ _ { return []; }
orExpr
= left:andExpr _ OrOp _ right:orExpr { return left.concat(right, ["||"]); }
......@@ -28,11 +29,11 @@ boolExpr
project
= "+" left:name { return ["++", left]; }
/ "+*" { return ["++", "*"]; }
/ "+" { return ["++", "*"]; }
context
= "@" left:name { return ["@@", left]; }
/ "@*" { return ["@@", "*"]; }
/ "@" { return ["@@", "*"]; }
OrOp
= "||"
......@@ -113,10 +114,10 @@ number
= [0-9]+ { return text(); }
StringLiteral "string"
= '"' chars:DoubleStringCharacter* '"' {
= '"' chars:DoubleStringCharacter* '"'? {
return chars.join("");
}
/ "'" chars:SingleStringCharacter* "'" {
/ "'" chars:SingleStringCharacter* "'"? {
return chars.join("");
}
......@@ -132,7 +133,7 @@ RegexLiteral "regex"
= "/" chars:RegexCharacter* "/" "i" {
return new RegExp(chars.join(""), "i");
}
/ "/" chars:RegexCharacter* "/" {
/ "/" chars:RegexCharacter* "/"? {
return new RegExp(chars.join(""));
}
......@@ -144,7 +145,9 @@ SourceCharacter
= .
name
= [a-zA-Z_][a-zA-Z_0-9]* { return text(); }
= '"' [a-zA-Z_][a-zA-Z_0-9]* '"' { return text(); }
/ [a-zA-Z_][a-zA-Z_0-9]* '"' { return '"' + text(); }
/ [a-zA-Z_][a-zA-Z_0-9]* { return text(); }
_ "whitespace"
= [ \t\n\r]*
\ No newline at end of file
= [ \t\n\r]*
......@@ -4,6 +4,9 @@
// specifically for todo.txt searching and filtering.
function runQuery(item, compiledQuery) {
if (!compiledQuery) {
return true; // a null query matches everything
}
let stack = [];
let operand1 = false;
let operand2 = false;
......@@ -69,16 +72,26 @@ function runQuery(item, compiledQuery) {
next = q.shift();
if (next == "*") {
stack.push(item.projects ? true : false);
} else if (next.startsWith('"')) {
stack.push(item.projects && item.projects.includes(next.slice(1,-1)));
} else {
stack.push(item.projects && item.projects.includes(next));
// match the prefix of the project name
stack.push(item.projects && item.projects.findIndex(function(p) {
return p.startsWith(next);
}) > -1);
}
break;
case "@@":
next = q.shift();
if (next == "*") {
stack.push(item.contexts ? true : false);
} else if (next.startsWith('"')) {
stack.push(item.contexts && item.contexts.includes(next.slice(1,-1)));
} else {
stack.push(item.contexts && item.contexts.includes(next));
// match the prefix of the context name
stack.push(item.contexts && item.contexts.findIndex(function(c) {
return c.startsWith(next);
}) > -1);
}
break;
case "||":
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment