(output: string)
| 133 | const asyncClassRegex = /^[^,\r\n]+/; |
| 134 | |
| 135 | export function parseMI(output: string): MINode { |
| 136 | /* |
| 137 | output ==> |
| 138 | ( |
| 139 | exec-async-output = [ token ] "*" ("stopped" | others) ( "," variable "=" (const | tuple | list) )* \n |
| 140 | status-async-output = [ token ] "+" ("stopped" | others) ( "," variable "=" (const | tuple | list) )* \n |
| 141 | notify-async-output = [ token ] "=" ("stopped" | others) ( "," variable "=" (const | tuple | list) )* \n |
| 142 | console-stream-output = "~" c-string \n |
| 143 | target-stream-output = "@" c-string \n |
| 144 | log-stream-output = "&" c-string \n |
| 145 | )* |
| 146 | [ |
| 147 | [ token ] "^" ("done" | "running" | "connected" | "error" | "exit") ( "," variable "=" (const | tuple | list) )* \n |
| 148 | ] |
| 149 | "(gdb)" \n |
| 150 | */ |
| 151 | |
| 152 | let token = undefined; |
| 153 | const outOfBandRecord = []; |
| 154 | let resultRecords = undefined; |
| 155 | |
| 156 | const asyncRecordType = { |
| 157 | "*": "exec", |
| 158 | "+": "status", |
| 159 | "=": "notify" |
| 160 | }; |
| 161 | const streamRecordType = { |
| 162 | "~": "console", |
| 163 | "@": "target", |
| 164 | "&": "log" |
| 165 | }; |
| 166 | |
| 167 | const parseCString = () => { |
| 168 | if (output[0] != '"') |
| 169 | return ""; |
| 170 | let stringEnd = 1; |
| 171 | let inString = true; |
| 172 | let remaining = output.substring(1); |
| 173 | let escaped = false; |
| 174 | while (inString) { |
| 175 | if (escaped) |
| 176 | escaped = false; |
| 177 | else if (remaining[0] == '\\') |
| 178 | escaped = true; |
| 179 | else if (remaining[0] == '"') |
| 180 | inString = false; |
| 181 | |
| 182 | remaining = remaining.substring(1); |
| 183 | stringEnd++; |
| 184 | } |
| 185 | let str; |
| 186 | try { |
| 187 | str = parseString(output.substring(0, stringEnd)); |
| 188 | } catch (e) { |
| 189 | str = output.substring(0, stringEnd); |
| 190 | } |
| 191 | output = output.substring(stringEnd); |
| 192 | return str; |
no test coverage detected