From: Michael R H. <bu...@zc...> - 2003-12-28 21:31:38
|
I've been spending some time with my JScheme plugin for Eclipse again (I just added matching parenthesis highlighting to the version in CVS), and I've come to a point at which I have to really parse the input buffer to add the next features on my TODO: http://cvs.zclipse.org/viewcvs.py/zclipse/org.zclipse.jscheme/TODO?view=markup For details on the plugin: http://www.zclipse.org/projects/jscheme I've toyed with rolling my own parser (which I've started twice: once ad-hoc, and once from the r4rs spec), writing a SableCC grammar for JScheme, and using the jsint.InputPort.read() function. None of these has struck me as quite perfect. Rolling my own gives me the most control over error reporting and recovery, and I would have full access to all parts of the input (including comments), but it's a lot of work that has already been done in JScheme itself, and it would likely be less sharable with other projects that might have similar needs. Writing a SableCC grammar is less work, more sharable in some ways (possibly directly contributable to the jscheme project itself), and generates a very pleasant AST for traversal, but isn't so good at error reporting or recovery during the parse (at least in the current release of SableCC). Using InputPort.read() is great because I would be using precisely the same parsing mechanism as JScheme itself, and it's already been written. However, to my mind, API isn't quite amenable for general use. Since it returns Object, I have to use Java's RTTI features to examine and process the parsed data (or I have to write parts of my code in JScheme to process the input) -- I'd prefer a syntax tree that I implements the Visitor design pattern for traversal so I don't have to do any downcasting. My understanding is also that because it's meant for execution, the InputPort throws away comments and will print errors to System.err. Basically, in my understanding, it's not meant to be a Java API for parsing JScheme. It might not be too bad to cause the InputPort.read() to return an AST, instead of Object, possibly adding comments to the syntax tree. It would probably be harder to push error handling into the API level. Does anyone have any other recommendations for this? Once I have an AST that I can work with, it should be easy to add a TreeView of the source and a source formatter, the two major remaining features I want before I release 1.0.0 of the plugin. mike -- Michael R Head <bu...@zc...> ZClipse -- OpenSource Eclipse plugins |