[antlr-interest] Grammar for Windows Resource format.

Mike Lischke lists at lischke-online.de
Mon Dec 12 08:07:46 PST 2005


[grr, had to resend this mail because the list address is not set as reply address, what a time waster, I really hate
that]


Phil, 

> Does anyone know of a grammar for Windows resource files
> (*.rc) of have one that they'd be willing to share?

I have written a parser for rc files a year ago. I wanted to publish it already for a long while but since I did not
need it after all and nobody on the list seemed to be interested I kept it close so far. Let me put it into my public
Subversion server (www.soft-gems.net/WebSVN). Ok, see the "Windows *.rc file parser and converter" repository.

The project was actually something to convert *.rc files to xml (for further processing). It is quite complete, although
it does not have an attached documentation. There is a demo app (all written in Eclipse and ANTLR 2.7.x), so you have at
least a starting point (and it is well documented). It contains handling for unlimited include file nesting, a macro
table class, an evaluator and works with various encodings. Two things are missing. One is support for any meta
language. There seems to be kind of a superior language, stuff inserted by the MSVC "designer", which is originally not
part of the *.rc language spec and nowhere mentioned. I asked at several places for more info on that meta stuff, but
got no answer. Of my about 800 rc files only 5 or so contain this stuff so it shouldn't matter much. On the other hand
there is also support for a few specialities produced by the Borland resource compiler.

The second thing is that switching the encoding on the fly is not possible yet. According to the rc spec it is allowed
to specify a language and sublanguage in the file to allow for differently encoded strings. The reader works well also
with Unicode files (although I never found one so far) but switching the input language is difficult, as you have to set
up a new reader every time but have to make sure already buffered input makes it into the new reader. This is also the
reason why I added InputStreamReaderEx.java the project (which is a derivation of InputStreamReader.java). It was
planned to be used as starting point for that task but I never finished it.

There is also a full featured preprocessor, which handles line splicing and trigraph sequences (I mentioned unlimited
include file handling already). Last but not least the macro table implementation supports charizing and stringizing and
can also handle macros with empty parameters, like FOO(bar,,,,,,bar).

Let me know if this is what you need.

Mike
--
www.soft-gems.net 



More information about the antlr-interest mailing list