forked from google/gumbo-parser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gentags.py
34 lines (26 loc) · 971 Bytes
/
gentags.py
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
import sys
def open_and_write_header(filename, comment_prefix):
f = open(filename, 'w')
f.write(comment_prefix + ' Generated via `gentags.py src/tag.in`.\n')
f.write(comment_prefix + ' Do not edit; edit src/tag.in instead.\n')
f.write(comment_prefix + ' clang-format off\n')
return f
tag_strings = open_and_write_header('src/tag_strings.h', '//')
tag_enum = open_and_write_header('src/tag_enum.h', '//')
tag_sizes = open_and_write_header('src/tag_sizes.h', '//')
tag_py = open_and_write_header('python/gumbo/gumboc_tags.py', '#')
tag_py.write('TagNames = [\n')
tagfile = open(sys.argv[1])
for tag in tagfile:
tag = tag.strip()
tag_upper = tag.upper().replace('-', '_')
tag_strings.write('"%s",\n' % tag)
tag_enum.write('GUMBO_TAG_%s,\n' % tag_upper)
tag_sizes.write('%d, ' % len(tag))
tag_py.write(' "%s",\n' % tag_upper)
tagfile.close()
tag_strings.close()
tag_enum.close()
tag_sizes.close()
tag_py.write(']\n')
tag_py.close()