File tree Expand file tree Collapse file tree 1 file changed +16
-2
lines changed
Expand file tree Collapse file tree 1 file changed +16
-2
lines changed Original file line number Diff line number Diff line change 11#!/usr/bin/env python
22# -*- coding: utf-8 -*-
3+ import compiler
34import optparse
45import os .path
56import sys
@@ -52,8 +53,18 @@ def transform(options):
5253
5354 set_config (options .configs , options .includedefaults )
5455 M = Module (filein , fileout )
55- W .walk (ast , M )
56- print >> output , M
56+ W .walk (ast , M )
57+ source = str (M )
58+ print >> output , source
59+
60+ if options .syntaxcheck :
61+ try :
62+ compiler .parse (source )
63+ except (SyntaxError , ):
64+ msg = '## ERR: invalid syntax in generated source.'
65+ else :
66+ msg = '## INFO: generated source has valid syntax.'
67+ print >> sys .stderr , msg
5768 return 0
5869
5970
@@ -72,6 +83,9 @@ def cli_options(argv):
7283 parser .add_option ('-n' , '--nodefaults' , dest = 'includedefaults' ,
7384 help = 'ignore default configuration' ,
7485 default = True , action = 'store_false' )
86+ parser .add_option ('-s' , '--syntaxcheck' , dest = 'syntaxcheck' ,
87+ help = 'Check source syntax after generation' ,
88+ default = False , action = 'store_true' )
7589 options , args = parser .parse_args (argv )
7690 return options , args
7791
You can’t perform that action at this time.
0 commit comments