不建议使用ANTLRInputStream和ANTLRFileStream,有哪些替代方法? [英] ANTLRInputStream and ANTLRFileStream are deprecated, what are the alternatives?

查看:1347
本文介绍了不建议使用ANTLRInputStream和ANTLRFileStream,有哪些替代方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我使用

ANTLRFileStream antlrFileStream = new ANTLRFileStream("myfile.testlang");

ANTLRInputStream input = new ANTLRInputStream( new FileInputStream("myfile.testlang") );

编译器均显示两个类的弃用错误,替代方法是什么?

Compiler shows deprecation error for both the classes what is alternative?

推荐答案

您可以使用CharStreams类而不是下面不推荐使用的类.

You can use the CharStreams class instead of the deprecated classes as below.

CharStream codePointCharStream = CharStreams.fromFileName("myfile.testlang");
TESTLANGLexer lexer = new TESTLANGLexer(codePointCharStream);
TESTLANGParser parser = new TESTLANGParser(new CommonTokenStream(lexer));
parser.addParseListener(new TESTLANGEventListener());

// Start parsing
parser.testlangFile(); 

这篇关于不建议使用ANTLRInputStream和ANTLRFileStream,有哪些替代方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆