tags:

views:

77

answers:

2

Hi, I'm writing an audio player using java, and I want a title formatter similar to foobar2000. Examples are:

$if($strcmp(%album artist%,%artist%),%artist%,$if2(%album%,Unknown))

or

[%album%][ '('CD $ifgreater(%totaldiscs%,1,%discnumber%,)')']

first example returns a string, and if it is same for sequential tracks in a playlist, they are grouped, second example formats album name and adds a cd number if it exists. Full reference is here

I do not need everything but at least some of the functionality.

How difficult is it to write a parser for such a language. Are there any compiler compilers for java?

Would it be easier to use java's javascript engine? How fast will it be (processing several thousand tracks)?

+2  A: 

Have you considered using a templating engine such as Freemarker or Velocity? Their markup languages aren't exactly what you specified, but they're very flexible. Might be too verbose if it's for end-users, though.

skaffman
thanks but I guess javascript would be less verbose.
tulskiy
Very likely, yes
skaffman
+1  A: 

There are some tools around for parsing custom languages. One of the common tools is the parser generator antlr.

To answer your question, if it's difficult? Yes, it is. Parsing the statements into a syntax tree is just the first step. You still need to write the interpreter, and this foobar2000 title generator syntax looks pretty complex!

Andreas_D
antlr looks like a solution. i guess my program will not have configurable title formatting. :) maybe later.Thanks.
tulskiy