/**
* Parse the string passed as parameter returning the string representing the structure of the UI
* described by the parameter.
* @param document
* @return
* @throws Exception
*/
private String parse(String document) throws Exception {
ANTLRInputStream input = new ANTLRInputStream(document);
SaltLexer lexer = new SaltLexer(input);
// The lexer should not recover errors.
lexer.addErrorListener(new BaseErrorListener() {
@Override
public void syntaxError(Recognizer<?, ?> arg0, Object arg1, int arg2,
int arg3, String arg4, RecognitionException arg5) {
throw new RuntimeException(arg5);
}
});
CommonTokenStream tokens = new CommonTokenStream(lexer);
SaltParser parser = new SaltParser(tokens);
ParseTree tree = parser.document();
if (parser.getNumberOfSyntaxErrors() > 0) {
throw new SyntaxException("Syntax error into the document: " + document);
}
//
SaltTextVisitor visitor = new SaltTextVisitor(parser);
return visitor.visit(tree);
}
SaltTest.java 文件源码
java
阅读 19
收藏 0
点赞 0
评论 0
项目:salt9000
作者:
评论列表
文章目录