readQuery reads a full string until reaching a closing parentheses. Counts opening parens to ensure that balance is maintained.
()
| 194 | // readQuery reads a full string until reaching a closing parentheses. Counts |
| 195 | // opening parens to ensure that balance is maintained. |
| 196 | func (t *Tokenizer) readQuery() string { |
| 197 | var query string |
| 198 | |
| 199 | var count = 1 |
| 200 | for count > 0 { |
| 201 | for unicode.IsSpace(t.current()) { |
| 202 | t.input = t.input[1:] |
| 203 | } |
| 204 | |
| 205 | word := fmt.Sprintf("%s", t.readWord()) |
| 206 | |
| 207 | if t.current() == -1 { |
| 208 | break |
| 209 | } |
| 210 | |
| 211 | if t.current() == '(' { |
| 212 | count++ |
| 213 | word = "(" |
| 214 | } else if t.current() == ')' { |
| 215 | count-- |
| 216 | if count <= 0 { |
| 217 | query += word |
| 218 | break |
| 219 | } |
| 220 | word = ")" |
| 221 | } else if t.currentIs('\'', '`') { |
| 222 | word += string(t.current()) |
| 223 | } else { |
| 224 | word += " " |
| 225 | } |
| 226 | |
| 227 | query += word |
| 228 | t.input = t.input[1:] |
| 229 | } |
| 230 | |
| 231 | return query |
| 232 | } |
| 233 | |
| 234 | // readUnitl reads the input starting at start, until reaching a rune in runes. |
| 235 | func (t *Tokenizer) readUntil(runes ...rune) string { |