Subj : Re: wrestling a rhino down to the ground (experiences with 5R5 source) To : "Mark D. Anderson" From : Igor Bukanov Date : Mon Aug 04 2003 10:45 am Mark D. Anderson wrote: > >> > 5. There appears to be no easy way to retrieve source name and line >> > number from NativeScript. >> >>You can do it currently by using the debugger interface, see >>org.mozilla.javascript.debug.Debugger.handleCompilationDone and methods >>in org.mozilla.javascript.debug.DebuggableScript. But if you need a more >>direct way to get that info, I suggest to file an enhancement report for >>Rhino at bugzilla.mozilla.org. > > > hmmm.... at first glance, i don't see how to get from a DebuggableScript > instance to an InterpretedScript instance, or go the other direction. With org.mozilla.javascript.debug.Debugger instance installed by Context.setDebugger, Rhino will call its handleCompilationDone() method when generation of the internal byte code to represent a particular function or script is done. The method will receive instance of org.mozilla.javascript.debug.DebuggableScript which provides line/sourcename information. > > >>But IMO for pretty printing/source transformation you do not need access >>to the parser tree. If parser would have an option to include line >>number information/comments into token character array which is >>effectively a serialized version of parse tree, then source code >>transformer can work with that form directly and not depend on details >>of Parser/TokenStream. > > > That sounds reasonable. I guess that would mean TokenStream.java would > have new tokens, like > COMMENT = 143, // encoded like NAME > LINENO = 144, // encoded like NUMBER Actually 2 different tokens for COMMENTS are necessary to distinguish between // and /**/. Regards, Igor .