Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error format strings preventing compilation #33

Merged
merged 1 commit into from
Dec 22, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 34 additions & 35 deletions lit/main.lit
Original file line number Diff line number Diff line change
Expand Up @@ -293,44 +293,42 @@ given by the array `codeLinenums` that we created earlier.

--- Check for compiler errors +=
if (errorFormat !is null) {
if (errorFormat.indexOf("%l") != -1 && errorFormat.indexOf("%f") != -1 && errorFormat.indexOf("%m") != -1) {
auto r = regex("");
try {
r = regex("^" ~ errorFormat.replaceAll(regex("%s"), ".*?")
.replaceAll(regex("%l"), "(?P<linenum>\\d+?)")
.replaceAll(regex("%f"), "(?P<filename>.*?)")
.replaceAll(regex("%m"), "(?P<message>.*?)") ~ "$");
} catch (Exception e) {
error(errorFormatCmd.filename, errorFormatCmd.lineNum, "Regular expression error: " ~ e.msg);
return;
}

writeln(compilerCmd);
auto output = executeShell(compilerCmd).output.split("\n");
int i = 0;

foreach (line; output) {
auto matches = matchFirst(line, r);

string linenum = matches["linenum"];
string fname = matches["filename"];
string message = matches["message"];

if (linenum != "" && fname != "") {
if (codeLinenums[fname].length > to!int(linenum)) {
auto codeline = codeLinenums[fname][to!int(linenum) - 1];
error(codeline.file, codeline.lineNum, message);
} else {
auto codeline = codeLinenums[fname][codeLinenums[fname].length - 2];
error(codeline.file, codeline.lineNum, message);
}
auto r = regex("");
try {
r = regex("^" ~ errorFormat.replaceAll(regex("%s"), ".*?")
.replaceAll(regex("%l"), "(?P<linenum>\\d+?)")
.replaceAll(regex("%f"), "(?P<filename>.*?)")
.replaceAll(regex("%m"), "(?P<message>.*?)") ~ "$");
} catch (Exception e) {
error(errorFormatCmd.filename, errorFormatCmd.lineNum, "Regular expression error: " ~ e.msg);
return;
}

writeln(compilerCmd);
auto output = executeShell(compilerCmd).output.split("\n");
int i = 0;

foreach (line; output) {
auto matches = matchFirst(line, r);

string linenum = matches.canFind("linenum") ? matches["linenum"] : "";
string fname = matches.canFind("filename") ? matches["filename"] : "";
string message = matches.canFind("message") ? matches["message"] : "";

if (linenum != "" && fname != "") {
if (codeLinenums[fname].length > to!int(linenum)) {
auto codeline = codeLinenums[fname][to!int(linenum) - 1];
error(codeline.file, codeline.lineNum, message);
} else {
if (!(line == "" && i == output.length - 1)) {
writeln(line);
}
auto codeline = codeLinenums[fname][codeLinenums[fname].length - 2];
error(codeline.file, codeline.lineNum, message);
}
} else {
if (!(line == "" && i == output.length - 1)) {
writeln(line);
}
i++;
}
i++;
}
}
---
Expand Down Expand Up @@ -380,5 +378,6 @@ import std.file;
import std.string;
import std.process;
import std.regex;
import std.algorithm: canFind;
import std.conv;
---