#!/usr/bin/python

names = {} 
nameValues = {}

outfile = open( '../Lua/Units.lua', 'w' )
outfile.write( 'module("Units",package.seeall)\n' )
outfile.write( 'require("Tethys")\n' )

# we are using regular expression matching
import re
pattern = re.compile('[\s]*const[\s]+(?:Base)?Unit[\s]+Units::([\w_]+)[\s]*[\(][\s]*\"([^\"]+)\"[\s]*,[\s]*\"(.+)\"[, )]+')
commentPattern = re.compile('[\s]*////[\s]*(.+)')

infile = open( "../Source/units/Units.cpp")
for line in infile.readlines():
    matches = pattern.match(line)
    if matches:
        outfile.write( matches.group(2) )
        outfile.write( ' = __DECLARE_UNIT("' + matches.group(2) + '",' )
        outfile.write( '"' + matches.group(3) + '");\n' )
    else:
        commentMatches = commentPattern.match(line)
        if commentMatches:
            outfile.write( '\n' )
            outfile.write( '-- ' + commentMatches.group(1) + '\n' )

infile.close()

outfile.close()    
