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