How should I close include files in an ANLTR parser?
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Mike_Gardner
Posted On:   Monday, July 30, 2001 03:21 AM

I have used ANTLR to generate Java code for a parser. The language it is parsing has include files. I have modelled my own code for include files on the code in the ""includeFile"" example in the ANTLR distribution.


What is the recommended method of closing the included files? In uponEOF() there does not seem to be a clean way to find and close the included file.

Re: How should I close include files in an ANLTR parser?

Posted By:   Monty_Zukowski  
Posted On:   Tuesday, July 31, 2001 06:29 AM

Interestingly enough the InputBuffer class doesn't have a close() method, nor a method to get the Reader or InputStream it is using.



I would add an instance variable to your lexer for the Reader. Set it after you initialize the lexer. In uponEOF() you can then explicitly close it.



Yes, it's annoying that you can't handle it automatically in the initializer of the lexer, but that is something that is generated and hence difficult to change.

About | Sitemap | Contact