9

If I use

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

or

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

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

Mike Lischke
  • 48,925
  • 16
  • 119
  • 181
Ameer Tamboli
  • 1,218
  • 12
  • 20
  • 1
    As for @Mike Lischke's comment about it being unfortunate that Unicode support was not simply folded into the existing ANTLRInputStream rather than creating the new CharStreams class (and breaking existing code, albeit in a (maybe? usually?) "easy-to-fix manner": Could it be that some code writte for ANTLRInputStream depending on it being a non-Unicode stream (e.g. 8 or 16 bit characters only)? I'm new to ANTLR (and picking up rusty Java again after learning it 10 years ago in CS class.), so I don't know how much the *incomplete* Unicode support for ANTLRInputStream was. The "don't change the – Jim Witte Mar 08 '19 at 18:02

1 Answers1

13

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(); 
SimoV8
  • 1,382
  • 1
  • 18
  • 32
Ameer Tamboli
  • 1,218
  • 12
  • 20
  • 5
    It's a bit unfortunate that these classes (which are totally fine) have been deprecated in the Java target (and only there, other targets don't do that). The reason for creating the new function `CharStreams.fromFileName()` is because of the now complete Unicode support. That could have been folded into the existing classes, but it was decided to not touch them and create a new API instead. – Mike Lischke May 27 '18 at 09:29