Use DefaultProblem to put error marker in editor [message #507786] |
Thu, 14 January 2010 11:24  |
Eclipse User |
|
|
|
Hi,
I have a DLTK editor and its content is parsed by another int another language. Anyway, when this language receive code with syntax error, parsing fails. I'm parsing the error string to be able to retreive its position in source. I've tried to use the DefaultProblem class to notify the error to the problem reporter but at runtime. There are no markers in editor. Any idea?
Regardspublic class LuaSourceParser extends AbstractSourceParser {
/**
* AST cache, allow to keep previous AST in mind when syntax errors occurs
*/
private static ModuleDeclaration _cache = null;
/**
* Provide DLTK compliant AST
*
* @return {@link ModuleDeclaration}, in case of syntax errors, the previous
* valid AST is given
* @see org.eclipse.dltk.ast.parser.ISourceParser#parse(char[], char[],
* org.eclipse.dltk.compiler.problem.IProblemReporter)
*/
@Override
public ModuleDeclaration parse(char[] fileName, char[] source,
IProblemReporter reporter) {
// Analyze code
NodeFactory factory = new NodeFactory(new String(source));
/*
* Keep older version of AST in case of syntax errors, when cache is
* defined.
*/
if ((_cache == null) || !factory.errorDetected()) {
_cache = factory.getRoot();
}
// Transfers problems if there is any
if (factory.errorDetected()) {
IProblem problem = buildProblem(fileName, factory.analyser());
reporter.reportProblem(problem);
}
return _cache;
}
public IProblem buildProblem(char[] fileName, LuaParseErrorAnalyzer analyzer) {
int col = analyzer.syntaxErrorColumn();
int offset = analyzer.syntaxErrorOffset();
int line = analyzer.syntaxErrorLine();
int id = 1;
int severity = ProblemSeverities.Error;
String[] args = {};
String error = analyzer.getErrorString();
String file = new String(fileName);
IProblem problem = new DefaultProblem(file, error, id, args, severity,
offset, offset, line, col);
return problem;
}
}
[Updated on: Thu, 14 January 2010 11:25] by Moderator
|
|
|
|
|
|
|
|
Re: Use DefaultProblem to put error marker in editor [message #663589 is a reply to message #663586] |
Tue, 05 April 2011 13:58  |
Eclipse User |
|
|
|
ok, the problem was that start/end positions were set to zero (I guess there is no "default" value for these), which made the line number ignored.
Perhaps we could use -1 as default values for start/end so they default to the line start/end if the line number is given? Otherwise calculating the line start/end is going to be useless boilerplate.
|
|
|
Powered by
FUDForum. Page generated in 0.03672 seconds