home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / pyos2bin.zip / Lib / keyword.py < prev    next >
Text File  |  1997-10-22  |  2KB  |  94 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. kwlist = [
  13. #--start keywords--
  14.         'and',
  15.         'assert',
  16.         'break',
  17.         'class',
  18.         'continue',
  19.         'def',
  20.         'del',
  21.         'elif',
  22.         'else',
  23.         'except',
  24.         'exec',
  25.         'finally',
  26.         'for',
  27.         'from',
  28.         'global',
  29.         'if',
  30.         'import',
  31.         'in',
  32.         'is',
  33.         'lambda',
  34.         'not',
  35.         'or',
  36.         'pass',
  37.         'print',
  38.         'raise',
  39.         'return',
  40.         'try',
  41.         'while',
  42. #--end keywords--
  43.         ]
  44.  
  45. kwdict = {}
  46. for keyword in kwlist:
  47.     kwdict[keyword] = 1
  48.  
  49. iskeyword = kwdict.has_key
  50.  
  51. def main():
  52.     import sys, re, string
  53.  
  54.     args = sys.argv[1:]
  55.     iptfile = args and args[0] or "Python/graminit.c"
  56.     if len(args) > 1: optfile = args[1]
  57.     else: optfile = "Lib/keyword.py"
  58.  
  59.     # scan the source file for keywords
  60.     fp = open(iptfile)
  61.     strprog = re.compile('"([^"]+)"')
  62.     lines = []
  63.     while 1:
  64.         line = fp.readline()
  65.         if not line: break
  66.     if string.find(line, '{1, "') > -1:
  67.         match = strprog.search(line)
  68.         if match:
  69.         lines.append("        '" + match.group(1) + "',\n")
  70.     fp.close()
  71.     lines.sort()
  72.  
  73.     # load the output skeleton from the target
  74.     fp = open(optfile)
  75.     format = fp.readlines()
  76.     fp.close()
  77.  
  78.     # insert the lines of keywords
  79.     try:
  80.         start = format.index("#--start keywords--\n") + 1
  81.         end = format.index("#--end keywords--\n")
  82.         format[start:end] = lines
  83.     except ValueError:
  84.         sys.stderr.write("target does not contain format markers\n")
  85.         sys.exit(1)
  86.  
  87.     # write the output file
  88.     fp = open(optfile, 'w')
  89.     fp.write(string.join(format, ''))
  90.     fp.close()
  91.  
  92. if __name__ == "__main__":
  93.     main()
  94.