I have a file, there are "0D 0D 0A" (\r\r\n) at the end of each line. Editor tool(Nodepad++) regards it as two lines, but from 'ANTLR' point view, this is one line.
How to change ANTLR to follow editor tool rule. (the version of ANTLR is 4.5.3)
I have a file, there are "0D 0D 0A" (\r\r\n) at the end of each line. Editor tool(Nodepad++) regards it as two lines, but from 'ANTLR' point view, this is one line.
How to change ANTLR to follow editor tool rule. (the version of ANTLR is 4.5.3)
--
You received this message because you are subscribed to the Google Groups "antlr-discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to antlr-discussi...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
BufferedReader bufferedReader = new BufferedReader(reader);
StringBuilder sb = new StringBuilder();
String line;
while ((line = bufferedReader.readLine()) != null) {
sb.append(line);
sb.append('\n');
}
in = new ANTLRInputStream(sb.toString());
It’s much easier than that I think. Though I still think you shoudl find out the root cause of the file format error and fix that, all you need do is write your own inputstream that extends the supplied one. In the LA() method, just throw away the 0x0D characters, which means your parser will only see LF for EOL and everything will work as intended.
Something like this
package com.armorize.vicara.compiler.toolchain;
import java.io.IOException;
import org.antlr.v4.runtime.ANTLRFileStream;
public class MyInputStream extends ANTLRFileStream {
public MyInputStream(String fileName) throws IOException {
super(fileName);
}
@Override
public int LA(int i) {
int c;
while ((c = super.LA(i)) == 0x0D) {
}
return c;
}
}
This is also how I generally implement case in sensitivity (by returning all c in lowercase), instead of A: 'A' |'a';
Jim