Home | History | Annotate | Download | only in torque
      1 #!/usr/bin/env python
      2 # Copyright 2014 the V8 project authors. All rights reserved.
      3 # Use of this source code is governed by a BSD-style license that can be
      4 # found in the LICENSE file.
      5 
      6 """This program either generates the parser files for Torque, generating
      7 the source and header files directly in V8's src directory."""
      8 
      9 import subprocess
     10 import sys
     11 import re
     12 from subprocess import Popen, PIPE
     13 
     14 if len(sys.argv) < 2 or len(sys.argv) > 3:
     15   print "invalid number of arguments"
     16   sys.exit(-1)
     17 
     18 use_stdout = True
     19 if len(sys.argv) == 3 and sys.argv[1] == '-i':
     20   use_stdout = False
     21 
     22 filename = sys.argv[len(sys.argv) - 1]
     23 
     24 with open(filename, 'r') as content_file:
     25   content = content_file.read()
     26 p = Popen(['clang-format', '-assume-filename=.ts'], stdin=PIPE, stdout=PIPE, stderr=PIPE)
     27 output, err = p.communicate(content)
     28 rc = p.returncode
     29 if (rc <> 0):
     30   sys.exit(rc);
     31 if use_stdout:
     32   print output
     33 else:
     34   output_file = open(filename, 'w')
     35   output_file.write(output);
     36   output_file.close()
     37