Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

keyword.py 2.2 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
  1. #! /usr/bin/env python3
  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. 'False',
  12. 'None',
  13. 'True',
  14. 'and',
  15. 'as',
  16. 'assert',
  17. 'async',
  18. 'await',
  19. 'break',
  20. 'class',
  21. 'continue',
  22. 'def',
  23. 'del',
  24. 'elif',
  25. 'else',
  26. 'except',
  27. 'finally',
  28. 'for',
  29. 'from',
  30. 'global',
  31. 'if',
  32. 'import',
  33. 'in',
  34. 'is',
  35. 'lambda',
  36. 'nonlocal',
  37. 'not',
  38. 'or',
  39. 'pass',
  40. 'raise',
  41. 'return',
  42. 'try',
  43. 'while',
  44. 'with',
  45. 'yield',
  46. #--end keywords--
  47. ]
  48. iskeyword = frozenset(kwlist).__contains__
  49. def main():
  50. import sys, re
  51. args = sys.argv[1:]
  52. iptfile = args and args[0] or "Python/graminit.c"
  53. if len(args) > 1: optfile = args[1]
  54. else: optfile = "Lib/keyword.py"
  55. # load the output skeleton from the target, taking care to preserve its
  56. # newline convention.
  57. with open(optfile, newline='') as fp:
  58. format = fp.readlines()
  59. nl = format[0][len(format[0].strip()):] if format else '\n'
  60. # scan the source file for keywords
  61. with open(iptfile) as fp:
  62. strprog = re.compile('"([^"]+)"')
  63. lines = []
  64. for line in fp:
  65. if '{1, "' in line:
  66. match = strprog.search(line)
  67. if match:
  68. lines.append(" '" + match.group(1) + "'," + nl)
  69. lines.sort()
  70. # insert the lines of keywords into the skeleton
  71. try:
  72. start = format.index("#--start keywords--" + nl) + 1
  73. end = format.index("#--end keywords--" + nl)
  74. format[start:end] = lines
  75. except ValueError:
  76. sys.stderr.write("target does not contain format markers\n")
  77. sys.exit(1)
  78. # write the output file
  79. with open(optfile, 'w', newline='') as fp:
  80. fp.writelines(format)
  81. if __name__ == "__main__":
  82. main()
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...