PageRenderTime 70ms CodeModel.GetById 39ms RepoModel.GetById 1ms app.codeStats 0ms

/lib-python/2.7/keyword.py

https://bitbucket.org/bwesterb/pypy
Python | 93 lines | 89 code | 2 blank | 2 comment | 1 complexity | f989bf735a1e817073584270bc527afc MD5 | raw file
  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", "kwlist"]
  9. kwlist = [
  10. #--start keywords--
  11. 'and',
  12. 'as',
  13. 'assert',
  14. 'break',
  15. 'class',
  16. 'continue',
  17. 'def',
  18. 'del',
  19. 'elif',
  20. 'else',
  21. 'except',
  22. 'exec',
  23. 'finally',
  24. 'for',
  25. 'from',
  26. 'global',
  27. 'if',
  28. 'import',
  29. 'in',
  30. 'is',
  31. 'lambda',
  32. 'not',
  33. 'or',
  34. 'pass',
  35. 'print',
  36. 'raise',
  37. 'return',
  38. 'try',
  39. 'while',
  40. 'with',
  41. 'yield',
  42. #--end keywords--
  43. ]
  44. iskeyword = frozenset(kwlist).__contains__
  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. for line in fp:
  56. if '{1, "' in line:
  57. match = strprog.search(line)
  58. if match:
  59. lines.append(" '" + match.group(1) + "',\n")
  60. fp.close()
  61. lines.sort()
  62. # load the output skeleton from the target
  63. fp = open(optfile)
  64. format = fp.readlines()
  65. fp.close()
  66. # insert the lines of keywords
  67. try:
  68. start = format.index("#--start keywords--\n") + 1
  69. end = format.index("#--end keywords--\n")
  70. format[start:end] = lines
  71. except ValueError:
  72. sys.stderr.write("target does not contain format markers\n")
  73. sys.exit(1)
  74. # write the output file
  75. fp = open(optfile, 'w')
  76. fp.write(''.join(format))
  77. fp.close()
  78. if __name__ == "__main__":
  79. main()