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)?
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!