Refactor query parser to append query values with a separate method. This allows possible flag-fields (like 'numeric') to be added later, although currently this functionality is not required.

This commit is contained in:
Simo Kinnunen
2015-06-26 16:49:29 +09:00
parent c1a00dbad6
commit f5e76039cd

View File

@@ -14,6 +14,14 @@ function Term() {
this.query = ''
}
Term.prototype.append = function(input) {
this.query += input
}
Term.prototype.reset = function() {
this.query = ''
}
function QueryParser() {
this.terms = []
this.currentTerm = new Term()
@@ -93,11 +101,11 @@ QueryParser.prototype.consume = function(input) {
}
if (input === ':') {
this.currentTerm.field = this.currentTerm.query
this.currentTerm.query = ''
this.currentTerm.reset()
this.state = State.QUERY_START
return
}
this.currentTerm.query += input
this.currentTerm.append(input)
return
case State.QUERY_VALUE_DOUBLEQUOTED:
if (input === '\\') {
@@ -106,7 +114,7 @@ QueryParser.prototype.consume = function(input) {
if (input === '"') {
return this.concludeTerm()
}
this.currentTerm.query += input
this.currentTerm.append(input)
return
}
}