home *** CD-ROM | disk | FTP | other *** search
/ linuxmafia.com 2016 / linuxmafia.com.tar / linuxmafia.com / pub / palmos / pippy-0.6beta-src.tar.gz / pippy-0.6beta-src.tar / pippy-0.6beta-src / src / Lib / keyword.py < prev    next >
Text File  |  2000-12-21  |  2KB  |  95 lines

  1. #! /usr/bin/env python
  2.  
  3. """Keywords (from "graminit.c")
  4.  
  5. This file is automatically generated; please don't muck it up!
  6.  
  7. To update the symbols in this file, 'cd' to the top directory of
  8. the python source tree after building the interpreter and run:
  9.  
  10.     python Lib/keyword.py
  11. """
  12.  
  13. kwlist = [
  14. #--start keywords--
  15.         'and',
  16.         'assert',
  17.         'break',
  18.         'class',
  19.         'continue',
  20.         'def',
  21.         'del',
  22.         'elif',
  23.         'else',
  24.         'except',
  25.         'exec',
  26.         'finally',
  27.         'for',
  28.         'from',
  29.         'global',
  30.         'if',
  31.         'import',
  32.         'in',
  33.         'is',
  34.         'lambda',
  35.         'not',
  36.         'or',
  37.         'pass',
  38.         'print',
  39.         'raise',
  40.         'return',
  41.         'try',
  42.         'while',
  43. #--end keywords--
  44.         ]
  45.  
  46. kwdict = {}
  47. for keyword in kwlist:
  48.     kwdict[keyword] = 1
  49.  
  50. iskeyword = kwdict.has_key
  51.  
  52. def main():
  53.     import sys, re, string
  54.  
  55.     args = sys.argv[1:]
  56.     iptfile = args and args[0] or "Python/graminit.c"
  57.     if len(args) > 1: optfile = args[1]
  58.     else: optfile = "Lib/keyword.py"
  59.  
  60.     # scan the source file for keywords
  61.     fp = open(iptfile)
  62.     strprog = re.compile('"([^"]+)"')
  63.     lines = []
  64.     while 1:
  65.         line = fp.readline()
  66.         if not line: break
  67.         if string.find(line, '{1, "') > -1:
  68.             match = strprog.search(line)
  69.             if match:
  70.                 lines.append("        '" + match.group(1) + "',\n")
  71.     fp.close()
  72.     lines.sort()
  73.  
  74.     # load the output skeleton from the target
  75.     fp = open(optfile)
  76.     format = fp.readlines()
  77.     fp.close()
  78.  
  79.     # insert the lines of keywords
  80.     try:
  81.         start = format.index("#--start keywords--\n") + 1
  82.         end = format.index("#--end keywords--\n")
  83.         format[start:end] = lines
  84.     except ValueError:
  85.         sys.stderr.write("target does not contain format markers\n")
  86.         sys.exit(1)
  87.  
  88.     # write the output file
  89.     fp = open(optfile, 'w')
  90.     fp.write(string.join(format, ''))
  91.     fp.close()
  92.  
  93. if __name__ == "__main__":
  94.     main()
  95.