Re: Java and awk (jawk)
On Tue, 6 Jul 2010, Sascha Effert wrote:
I am implementing a key/value store, which maps Strings to Strings. This
store needs some kind of filters. These filters have to support regular
expressions, but they also have to be able to interpret the key as a
number (if it is one) to get ranges.
I would like to support awk as filter language as it can do anything I
want. I know there is jawk[1] as an Java implementation of awk. My
Problem is that the homepage only describes how to use it from the
command line, not how to use out of Java code. I would like to use the
library and give it the skript and the Input as String or as InputStream
and I would like to get the output as OutputStream or String. Is here
anybody who used jawk and can give me a hint how to do it?
Not me. But you can get the source, so get it, and figure out how the main
class does it, then do that yourself.
I've had a quick look, and it doesn't look easy: the
central interpreter class is org.jawk.backend.AVM, and its only real
entrypoint is a method:
public int interpret(AwkTuples tuples)
Which has no obvious way to return a value - it's the moral equivalent of
'main'. If you delve a bit deeper, you find things like the PRINT opcode
being hardwired to System.out; this is clearly not code that was designed
for embedding.
I'm not saying you can't do it, just that it's going to require some major
hackery to wrap it in a facade that will let you use it as a filter.
I strongly suspect writing something far simpler from scratch (ie a
language which can express regular expressions and integer ranges) will be
an easier way of getting to the goal that is important to you.
tom
--
I DO IT WRONG!!!