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

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: Refactored python code 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_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[{array_size }] = {{
18 {token_lines}
19 }};
20 const unsigned codePointsNumber = {array_size};
21 """
22
23
24 def token_type(i):
25 codepoints = {'(': "leftParenthesis",
Nils Barth (inactive) 2014/03/25 02:51:46 nit: single quote for strings throughout (at least
26 ')': "rightParenthesis",
27 '+': "plusOrFullStop",
28 '.': "plusOrFullStop",
29 '-': "hyphenMinus",
30 ',': "comma",
31 '/': "solidus",
32 '\\': "reverseSolidus",
33 ':': "colon",
34 ';': "semiColon",
35 }
36 whitespace = ['\n', '\r', '\t', '\f', ' ']
Nils Barth (inactive) 2014/03/25 02:51:46 You can actually make this a single string: whites
37 c = chr(i)
38 if c in whitespace:
39 return "whiteSpace"
40 if c.isdigit():
41 return "asciiDigit"
42 if c.isalpha() or c == '_':
43 return "nameStart"
44 if i == 0:
45 return "endOfFile"
46 return codepoints.get(c)
47
48
49 class MakeMediaQueryTokenizerCodePointsWriter(in_generator.Writer):
50 defaults = {
51 'Conditional': None,
52 'RuntimeEnabled': None,
53 'ImplementedAs': None,
54 }
55 filters = {
56 }
57 default_parameters = {
58 'namespace': '',
59 'export': '',
60 }
61
62 def __init__(self, in_file_path):
63 super(MakeMediaQueryTokenizerCodePointsWriter, self).__init__(in_file_pa th)
64
65 self._outputs = {
66 ('MediaQueryTokenizerCodepoints.cpp'): self.generate,
67 }
68 self._template_context = {
69 'namespace': '',
70 'export': '',
71 }
72
73 def generate(self):
74 array_size = 128 # SCHAR_MAX + 1
75 token_lines = [" &MediaQueryTokenizer::%s," % token_type(i) if token_ type(i) else " 0," for i in range(array_size)]
Nils Barth (inactive) 2014/03/25 02:51:46 This would be more legible with line breaks: token
76 return CPP_TEMPLATE.format(array_size=array_size, token_lines="\n".join( token_lines))
77
78 if __name__ == "__main__":
79 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