Question

are there any ways to print the content of line if an error occurs during parsing a file via xtext into the log file? Currently, all I get is a line number but this is not enough to find a problem if you do have only a log file.

I didn't find a section in the documentation for this. Do you have any idea or resource to help?

Was it helpful?

Solution

something like

IParser parser = i.getInstance(IParser.class);
    IParseResult parseResult = parser.parse(new InputStreamReader(new StringInputStream("element a\nelement a\nxxxx")));
    for (INode e : parseResult.getSyntaxErrors()) {
        System.out.println(e.getSyntaxErrorMessage());
        System.out.println(e.getStartLine());
                    System.out.println(e.getText());
    }

and if that is not enhough

for (INode x : parseResult.getRootNode().getLeafNodes()) {
            if (x.getStartLine()==e.getStartLine()) {
                System.out.print(x.getText());
            }
        }
        System.out.println();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top