DefaultParseResult dpr = new DefaultParseResult(this);
dpr.setParsedLines(0, lineCount);
// Suppress output...
Ruby runtime = container.getProvider().getRuntime();
GlobalVariables gvars = runtime.getGlobalVariables();
IRubyObject orig = gvars.get("$stderr");
// Todo: cache this or find a better way of supressing output...
gvars.set("$stderr", new RubyIO(runtime, new ByteArrayOutputStream()));
try {
container.parse(scr, lineNumbers);
} catch (ParseFailedException e) {
ScriptException se = parseRubyParseException(e);
// find start of error (column is normally the end)...
int targetLine = se.getLineNumber() - 1;
if (targetLine >= lineCount)
targetLine = lineCount - 1; // For EOF errors
int col = se.getColumnNumber();
String l = lines[targetLine];
char[] chars = l.toCharArray();
int start = col;
for (; start > 0; start--) {
char c = chars[start];
if (Character.isWhitespace(c)) {
start++;
break;
}
}
int end = col;
for (; end < chars.length; end++) {
char c = chars[end];
if (Character.isWhitespace(c))
break;
}
int len = end - start;
dpr.setParsedLines(0, targetLine);
int off = 0;
for (int i = 0; i < targetLine; i++)
off += lines[i].length() + 1;
off += start;
DefaultParserNotice not = new DefaultParserNotice(this, se.getLocalizedMessage(), targetLine, off, len);
not.setShowInEditor(true);
not.setLevel(DefaultParserNotice.ERROR);
dpr.addNotice(not);
} catch (Exception e) {
e.printStackTrace();
} finally {
gvars.set("$stderr", orig);
}
return dpr;
}