Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(25)

Side by Side Diff: Source/build/scripts/make_mediaquery_tokenizer_codepoints.py

Issue 209503003: Convert MediaQueryTokenizer's codepoints array to be static data (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Newline at end of generated file Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | Source/core/core_generated.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/env python
2
3 # Copyright 2014 The Chromium Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file.
6
7 import in_generator
8 import sys
9
10 CPP_START_TEMPLATE = """
11 // Copyright 2014 The Chromium Authors. All rights reserved.
12 // Use of this source code is governed by a BSD-style license that can be
13 // found in the LICENSE file.
14
15 // Auto-generated by make_mediaquery_tokenizer_codepoints.py
16
17 const MediaQueryTokenizer::CodePoint MediaQueryTokenizer::codePoints[%d] = {
18 """
19
20 CPP_FOOTER_TEMPLATE = """ };
21 const unsigned codePointsNumber = %d;
22 """
23
24
25 class MakeMediaQueryTokenizerCodePointsWriter(in_generator.Writer):
26 defaults = {
27 'Conditional': None,
28 'RuntimeEnabled': None,
29 'ImplementedAs': None,
30 }
31 filters = {
32 }
33 default_parameters = {
34 'namespace': '',
35 'export': '',
36 }
37
38 def __init__(self, in_file_path):
39 super(MakeMediaQueryTokenizerCodePointsWriter, self).__init__(in_file_pa th)
40
41 self._outputs = {
42 ('MediaQueryTokenizerCodepoints.cpp'): self.generate,
43 }
44 self._template_context = {
45 'namespace': '',
46 'export': '',
47 }
48
49 def generate(self):
50 array_size = 128 # SCHAR_MAX + 1
51 output_string = CPP_START_TEMPLATE % array_size
52 for i in range(array_size):
53 c = chr(i)
54 if c in ['\n', '\r', '\t', '\f', ' ']:
Nils Barth (inactive) 2014/03/24 01:34:23 This would be rather clearer and less redundant if
Timothy Loh 2014/03/24 03:22:19 Also I'll add that I'd write the function as: if
Nils Barth (inactive) 2014/03/24 03:24:27 <snip> Good point - even better!
55 output_string += " &MediaQueryTokenizer::whiteSpace,\n"
56 elif c == '(':
57 output_string += " &MediaQueryTokenizer::leftParenthesis, \n"
58 elif c == ')':
59 output_string += " &MediaQueryTokenizer::rightParenthesis ,\n"
60 elif c in ['+', '.']:
61 output_string += " &MediaQueryTokenizer::plusOrFullStop,\ n"
62 elif c == '-':
63 output_string += " &MediaQueryTokenizer::hyphenMinus,\n"
64 elif c == ',':
65 output_string += " &MediaQueryTokenizer::comma,\n"
66 elif c == '/':
67 output_string += " &MediaQueryTokenizer::solidus,\n"
68 elif c == ':':
69 output_string += " &MediaQueryTokenizer::colon,\n"
70 elif c == ';':
71 output_string += " &MediaQueryTokenizer::semiColon,\n"
72 elif c == '\\':
73 output_string += " &MediaQueryTokenizer::reverseSolidus,\ n"
74 elif c >= '0' and c <= '9':
75 output_string += " &MediaQueryTokenizer::asciiDigit,\n"
76 elif (c >= 'a' and c <= 'z') or (c >= 'A' and c <= 'Z') or c == '_':
77 output_string += " &MediaQueryTokenizer::nameStart,\n"
78 elif i == 0:
79 output_string += " &MediaQueryTokenizer::endOfFile,\n"
80 else:
81 output_string += " 0,\n"
82
83 output_string += CPP_FOOTER_TEMPLATE % array_size
84
85 return output_string
86
87 if __name__ == "__main__":
88 in_generator.Maker(MakeMediaQueryTokenizerCodePointsWriter).main(sys.argv)
OLDNEW
« no previous file with comments | « no previous file | Source/core/core_generated.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698