(input: string)
| 193 | } |
| 194 | |
| 195 | static parse(input: string): Query { |
| 196 | const p = NewParser(); |
| 197 | p.save(); |
| 198 | try { |
| 199 | p.feed(input); |
| 200 | p.save(); |
| 201 | } catch (error) { |
| 202 | // do nothing... this means we've got an incomplete or entirely incorrect query |
| 203 | } |
| 204 | |
| 205 | if (p.results?.length > 0) { |
| 206 | return Query.fromAst(p.results[0]); |
| 207 | } |
| 208 | |
| 209 | // partial parse result, also ok, we'll try our best with it :) |
| 210 | |
| 211 | // Parser.table is not defined in the type definitions, so we need to do this unfortunately. |
| 212 | const parserTable = (p as any).table; |
| 213 | const column = parserTable.filter((c: any) => |
| 214 | c.states.find( |
| 215 | (s: any) => |
| 216 | s.data !== undefined && |
| 217 | s.data != null && |
| 218 | Object.prototype.hasOwnProperty.call(s.data, 'profileName') |
| 219 | ) |
| 220 | )[0]; |
| 221 | if (column !== undefined) { |
| 222 | const data = column.states.find( |
| 223 | (s: any) => |
| 224 | s.data !== undefined && Object.prototype.hasOwnProperty.call(s.data, 'profileName') |
| 225 | ).data; |
| 226 | const rest = column.lexerState !== undefined ? input.slice(column.lexerState.col - 2) : input; |
| 227 | return new Query( |
| 228 | ProfileType.fromString(data.profileName), |
| 229 | [], |
| 230 | rest.length > 0 ? rest : input |
| 231 | ); |
| 232 | } |
| 233 | |
| 234 | return new Query(new ProfileType('', '', '', '', '', false), [], ''); |
| 235 | } |
| 236 | |
| 237 | static tryParse( |
| 238 | p: Parser, |
no test coverage detected