PageRenderTime 48ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/Python/system/keyword.py

https://bitbucket.org/cwalther/moulscript-dlanor
Python | 97 lines | 93 code | 2 blank | 2 comment | 1 complexity | 94ce799b6c0dc9a6df23579c33d04454 MD5 | raw file
Possible License(s): AGPL-1.0, GPL-3.0
  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. '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. 'yield',
  40. #--end keywords--
  41. ]
  42. kwdict = {}
  43. for keyword in kwlist:
  44. kwdict[keyword] = 1
  45. iskeyword = kwdict.has_key
  46. def main():
  47. import sys, re
  48. args = sys.argv[1:]
  49. iptfile = args and args[0] or "Python/graminit.c"
  50. if len(args) > 1: optfile = args[1]
  51. else: optfile = "Lib/keyword.py"
  52. # scan the source file for keywords
  53. fp = open(iptfile)
  54. strprog = re.compile('"([^"]+)"')
  55. lines = []
  56. while 1:
  57. line = fp.readline()
  58. if not line: break
  59. if line.find('{1, "') > -1:
  60. match = strprog.search(line)
  61. if match:
  62. lines.append(" '" + match.group(1) + "',\n")
  63. fp.close()
  64. lines.sort()
  65. # load the output skeleton from the target
  66. fp = open(optfile)
  67. format = fp.readlines()
  68. fp.close()
  69. # insert the lines of keywords
  70. try:
  71. start = format.index("#--start keywords--\n") + 1
  72. end = format.index("#--end keywords--\n")
  73. format[start:end] = lines
  74. except ValueError:
  75. sys.stderr.write("target does not contain format markers\n")
  76. sys.exit(1)
  77. # write the output file
  78. fp = open(optfile, 'w')
  79. fp.write(''.join(format))
  80. fp.close()
  81. if __name__ == "__main__":
  82. main()