Does a standalone WML preprocessor exist?

The place to post your WML questions and answers.

Moderator: Forum Moderators

Forum rules
  • Please use [code] BBCode tags in your posts for embedding WML snippets.
  • To keep your code readable so that others can easily help you, make sure to indent it following our conventions.
Post Reply
jonathantan86
Posts: 57
Joined: February 26th, 2005, 9:26 am

Does a standalone WML preprocessor exist?

Post by jonathantan86 »

Does a standalone WML preprocessor exist (i.e. can convert unpreprocessed WML files to one large preprocessed WML file)? If not, what would be the problems in creating one (other than the fact that no one seems to want one enough to program one themselves)?
User avatar
allefant
Units Database Administrator
Posts: 516
Joined: May 6th, 2005, 3:04 pm

Post by allefant »

CampGen has such a parser, it's not something very hard to write:

http://cvs.savannah.nongnu.org/viewcvs/ ... ot=campgen

Depending on what you want to do with it, that one might already work standalone (or not).

There are some small problems in creating one. For example, how will you handle conditionals? E.g.

#ifdef CAMPAIGN_HTTT
#ifdef EASY
[wml here]
#endif
#ifdef HARD
[wml here]
#endif
#else
[wml here]
#endif

Also, how do you handle pathes? The data and userdata directories are often implicitly used in macro processing, so you need to specify them somehow.

And lastly, to successfully parse any of the Wesnoth WML, you need to first parse all the standard macros.
jonathantan86
Posts: 57
Joined: February 26th, 2005, 9:26 am

Post by jonathantan86 »

Thanks. :-) I preprocessed the terrain graphics configurations (which does not use that many strange macros) and it worked.

CampGen is still a bit of a black box to me, but I changed the end of newparser.py a little bit and got the results I wanted. For the reference of anyone who might want to do the same, here it is:

Code: Select all

if __name__ == "__main__":
    import sys
    parser = Parser("/usr/local/share/wesnoth/data", "/home/elias/.wesnoth/data") # Change the user dir if you want to reference files there, probably
    parser.verbose = False # I changed this line
    parser.parse_file(sys.argv[1])
    data = wmldata.DataSub("WML")
    parser.parse_top(data)
    data.write_file(sys.stdout)
    #data.debug(show_contents = True) I deleted this line
I used Bash to redirect the output to a file.

Remember that Python is indentation-sensitive. CampGen uses spaces for indentation, so you should use spaces too and not tabs.
Post Reply