支持readLine

时间:2016-04-21 03:03:20

标签: java antlr readline bufferedinputstream

我想实现支持FilterInputStream界面的BufferedInputStream,特别是readLine()方法。

当前代码如下所示(标准antlr):

theInput = new BufferedInputStream( Files.newInputStream(inputPath) );
theOutput = new PrintStream(Files.newOutputStream(outputPath));

grammar.execute(theInput, theOutput);

建议的代码看起来像这样:

theInput = new RemoveCommentsInputStream( Files.newInputStream(inputPath) );
theOutput = new PrintStream(Files.newOutputStream(outputPath));

grammar.execute(theInput, theOutput);

RemoveCommentsInputStream的作用类似于java.io.FilterInputStream

问题在于FilterInputStream延伸InputStream,但execute()需要BufferedInputStream

这个用例是我想编写一个过滤器,在我将代码传递给antlr之前删除代码的注释和其他内容。实现规则来处理antlr中的cruft很困难,因为规则基于输入中某些字符的列位置。但是在普通的旧java中很容易摆脱它。

有什么建议吗?

0 个答案:

没有答案