Skip to content

Instantly share code, notes, and snippets.

getLiteralStrings = function (queryString) {
// this function steps through the input string, recognizes literal strings,
// remembers their position in the input string and returns an array that
// contains objects like this:
// {startPoint: n, endPoint: m, sequenceOfCharacters: s}
var currentlyInString = false;
var delimeterOfCurrentString = "";
var numberOfCurrentString = 0;
parseQuery = function (queryString) {
var literalStrings = getLiteralStrings(queryString);
var strippedString = stripLiteralStrings(queryString, literalStrings);
var booleanExpression = getBooleanExpression(strippedString);
var strippedComparisons = getStrippedComparisons(strippedString);
var comparisons = constructComparisons(strippedComparisons, literalStrings);
return { booleanExpression: booleanExpression,
comparisons: comparisons
parseQuery = function (queryString) {
var literalStrings = getLiteralStrings(queryString);
var strippedString = stripLiteralStrings(queryString, literalStrings);
var booleanExpression = getBooleanExpression(strippedString);
var strippedComparisons = getStrippedComparisons(strippedString);
var comparisons = constructComparisons(strippedComparisons, literalStrings);
return { booleanExpression: booleanExpression,
comparisons: strippedComparisons //temporary, will be comparisons then finished
var queryGrammar = {
'UNKNOWN' : {
firstCharacter : /\S/,
notAllowed : /[\s'"\w\d\(\)]/,
reserved : {
'WILD_CARD' : ['@%'],
'COMPARATOR' : ['=','!=','<','<=','>','>=']
}},
var buildTokenTree = function (tokenList) {
//var tokenList = tokenList;
var openParenthesisStack = [];
var booleanOperatorStack = [];
//var currentToken = null;
/*
Copy this code into the console and execute t=tree(q) for a start
Check the tree t with t[0].leftSide, t[0].rightSide.leftSide and so on...
Known problems:
-Tokenizer doesn't recognise tokens of lengh 1 at the end of the query string
-Boolean NOT doesn't work
-All logic patterns are still only in general binary form
// this one works, calling Obj1.f(1) gives [1,3,5,7,9]
Obj1 = {
n: 10,
s: [],
f: function(m){
if(m<=this.n){
this.s.push(m);
this.g.g1(m+1);
}
// this one works, calling Obj1.f(1) gives [1,3,5,7,9]
Obj1 = {
n: 10,
s: [],
f: function(m){
if(m<=this.n){
this.s.push(m);
this.g.g1(m+1);
}
/*
Copy this code into the console and execute Query.analyzeQuery(q1) for a start.
Check the Query object for its properties...
If an error occured while parsing, Query.tokenTree.error will give an explanation.
Execute Query.recordMatchesQuery(r1) to see validation of example record.
Execute Query.analyzeQuery(q2) followed by
/*
Copy this code into the console and execute Query.analyze(q1) for a start.
Check the Query object for its properties...
If an error occured while parsing, Query.tokenTree.error will give an explanation.
Execute Query.recordMatches(r1) to see validation of example record.
Execute Query.analyze(q2) followed by