#!/usr/bin/env python
"""
    @author Christophe Eymard <christophe.eymard@ravelsoft.com>
"""

from pwpeg.pwpeglang import toplevel
from pwpeg import Parser, SyntaxError
from pwpeg.visitor_python import PythonVisitor

#####################################################

parser = Parser(toplevel)

#####################################################

if __name__ == "__main__":
    from optparse import OptionParser
    optparser = OptionParser()

    options, args = optparser.parse_args()

    for a in args:
        f = open(a, "r")
        s = f.read()
        f.close()

        try:
            res = parser.parse(s)
            pv = PythonVisitor()
            print(pv.compile(res))
            #print(res.to_python())
        except SyntaxError as e:
            import sys
            sys.stderr.write(e.fullmessage() + "\n")

