简体   繁体   English

打印xtext解析器错误的行内容

[英]Print line content of a xtext parser error

are there any ways to print the content of line if an error occurs during parsing a file via xtext into the log file? 如果通过xtext解析文件到日志文件期间发生错误,有什么方法可以打印行的内容? 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? 您有什么想法或资源可以帮助您吗?

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();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM