#!/usr/bin/env python2
import codecs, json, sys
from source_text_parser import parse


def main():
    try:
	fn = sys.argv[1]
    except (IndexError, ):
	print >> sys.stderr, 'usage: %s filename' % (sys.argv[0], )
	return
    try:
	data = parse(fn)
	sys.stdout = codecs.getwriter('utf8')(sys.stdout)
	print json.dumps(data, indent=4)
    except (Exception, ), exc:
	print >> sys.stderr, 'exception during parse or output: ', exc


if __name__ == '__main__':
    main()
