You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

keyword.py 2.1KB

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