Alternative parser for Interpreter
"Devijver, Steven [JanBe Extern]" <SDEVIJVE-7I0wvx73XCc/[email protected]>
| Newsgroups | gmane.comp.java.beanshell.devel |
|---|---|
| Message-ID | <[email protected]> |
Hi,
I'm looking to develop an alternative parser for bsh. After going through
parts of the src tree I found out the parser is responsible for builing the
so called AST classes. The parser is created and called upon by the
Interpreter class, I'm not sure if the parser is used anywhere else.
The parser I'm looking to create would actually close the gap between bsh
and a xpath-2-java-syntax (x2j) parser I have created over the past few
months, but have not yet made public. Basically, x2j converts xpath into
java syntax. Here are some examples:
object1/object2/object3 would be outputted by x2j as:
object1.getObject2().getObject3()
equal(object1/object2, '6 june 1944') would be outputted by x2j as:
object1.getObject2().equals("6 june 1944")
test(isNotNull(object1) and isNotNull(object1/object2),
toString(object1/object2), '<not defined>') would be outputted by x2j
as:
(object1 != null && object1.getObject2() != null) ?
object1.getObject2().toString() : "<not defined>"
x2j is currently used in a template engine, so performance isn't really an
issue. However, after have looked at the Drools project and its DRL syntax,
I would like to replace the java-code-inside-an-xml-file into xpath. This
could be achieved by either converting xpath into java that would be fed to
bsh. This would require a high-level hack inside Drools and suffers from the
indirection syndrome.
The alternative would be to hook another parser into the bsh Interpreter and
let it handle the convertion directly into AST classes. This approach is
more beautiful in my opinion since it probably only requires minor changes
in the Interpreter (provide a hook for a alternative parser, basically a
getParser(java.io.Reader) method would do - it could be overridden by
classes extending from Interpreter, an interface for Parser would be nice as
well) and otherwise bsh would not be impacted, that is, as far as I
understand. I still have to look into the Drools src to find out what
changes are required. All that may need to be changed is the way the bsh
Interpreter instance is created.
The xpath-2-AST (x2a) parser only needs to handle a limited set of AST class
types, like method invocation, literal, variables, boolean tests and
operators. There would be no need to deal with try/catch blocks, exceptions,
method declaration, ...... .
Any feedback on how to handle this would be much appreciated.
Kind regards
Steven
-------------------------------------------------------
This SF.Net email is sponsored by: GNOME Foundation
Hackers Unite! GUADEC: The world's #1 Open Source Desktop Event.
GNOME Users and Developers European Conference, 28-30th June in Norway
http://2004/guadec.org