mi parser fixes

This commit is contained in:
Vadim Lopatin 2015-12-16 07:09:33 +03:00
parent 07254880d7
commit c0574c8219
2 changed files with 25 additions and 11 deletions

View File

@ -25,13 +25,13 @@ class Breakpoint {
} }
Breakpoint clone() { Breakpoint clone() {
Breakpoint v = new Breakpoint(); Breakpoint v = new Breakpoint();
id = v.id; v.id = id;
file = v.file; v.file = file;
fullFilePath = v.fullFilePath; v.fullFilePath = fullFilePath;
projectFilePath = v.projectFilePath; v.projectFilePath = projectFilePath;
line = v.line; v.line = line;
enabled = v.enabled; v.enabled = enabled;
projectName = v.projectName; v.projectName = projectName;
return v; return v;
} }
} }

View File

@ -181,17 +181,31 @@ MIValue parseMI(string s) {
MIToken[] tokens = tokenizeMI(s, err); MIToken[] tokens = tokenizeMI(s, err);
if (err) { if (err) {
// tokenizer error // tokenizer error
Log.e("Cannot tokenize MI output `" ~ src ~ "`");
return null; return null;
} }
MIValue[] items = parseMIList(tokens); MIValue[] items = parseMIList(tokens);
return new MIList(items); return new MIList(items);
} catch (Exception e) { } catch (Exception e) {
Log.e("Cannot parse MI from " ~ src, e); Log.e("Cannot parse MI output `" ~ src ~ "`", e.msg);
return null; return null;
} }
} }
string dumpTokens(MIToken[] tokens) {
char[] buf;
for (int i = 0; i < 10 && i < tokens.length; i++) {
if (tokens[i].type == MITokenType.str)
buf ~= '\"';
buf ~= tokens[i].str;
if (tokens[i].type == MITokenType.str)
buf ~= '\"';
}
return buf.dup;
}
MIValue parseMIValue(ref MIToken[] tokens) { MIValue parseMIValue(ref MIToken[] tokens) {
MIToken[] srctokens;
if (tokens.length == 0) if (tokens.length == 0)
return null; return null;
MITokenType tokenType = tokens.length > 0 ? tokens[0].type : MITokenType.eol; MITokenType tokenType = tokens.length > 0 ? tokens[0].type : MITokenType.eol;
@ -210,7 +224,7 @@ MIValue parseMIValue(ref MIToken[] tokens) {
MIValue res = new MIKeyValue(ident, value); MIValue res = new MIKeyValue(ident, value);
return res; return res;
} }
throw new Exception("Unexpected token " ~ to!string(tokenType)); throw new Exception("parseMIValue: Unexpected token " ~ to!string(tokenType) ~ " near " ~ srctokens.dumpTokens);
} else if (tokenType == MITokenType.str) { } else if (tokenType == MITokenType.str) {
string str = tokens[0].str; string str = tokens[0].str;
tokens = tokens[1..$]; tokens = tokens[1..$];
@ -224,7 +238,7 @@ MIValue parseMIValue(ref MIToken[] tokens) {
MIValue[] list = parseMIList(tokens, MITokenType.squareClose); MIValue[] list = parseMIList(tokens, MITokenType.squareClose);
return new MIList(list); return new MIList(list);
} }
throw new Exception("Invalid token at end of list: " ~ tokenType.to!string); throw new Exception("parseMIValue: Invalid token at end of list: " ~ tokenType.to!string ~ " near " ~ srctokens.dumpTokens);
} }
MIValue[] parseMIList(ref MIToken[] tokens, MITokenType closingToken = MITokenType.eol) { MIValue[] parseMIList(ref MIToken[] tokens, MITokenType closingToken = MITokenType.eol) {
@ -244,7 +258,7 @@ MIValue[] parseMIList(ref MIToken[] tokens, MITokenType closingToken = MITokenTy
tokens = tokens[1..$]; tokens = tokens[1..$];
continue; continue;
} }
throw new Exception("Unexpected token in list " ~ to!string(tokenType)); throw new Exception("parseMIList: Unexpected token " ~ to!string(tokenType) ~ " in list near " ~ tokens.dumpTokens);
} }
} }