Use DefaultProblem to put error marker in editor [message #507786] |
Thu, 14 January 2010 16:24 |
Kevin KIN-FOO Messages: 58 Registered: January 2010 |
Member |
|
|
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 16:25] Report message to a moderator
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03443 seconds