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

Side by Side Diff: third_party/WebKit/Source/build/scripts/make_css_tokenizer_codepoints.py

Issue 2329463004: ABANDONED CL: Changes needed to make things compile after running rewrite_to_chrome_style tool. (Closed)
Patch Set: More fixes - things build fine at this point. Created 3 years, 8 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
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 2
3 # Copyright 2014 The Chromium Authors. All rights reserved. 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 4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file. 5 # found in the LICENSE file.
6 6
7 import in_generator 7 import in_generator
8 import sys 8 import sys
9 import os 9 import os
10 10
11 module_basename = os.path.basename(__file__) 11 module_basename = os.path.basename(__file__)
12 module_pyname = os.path.splitext(module_basename)[0] + '.py' 12 module_pyname = os.path.splitext(module_basename)[0] + '.py'
13 13
14 CPP_TEMPLATE = """ 14 CPP_TEMPLATE = """
15 // Copyright 2014 The Chromium Authors. All rights reserved. 15 // Copyright 2014 The Chromium Authors. All rights reserved.
16 // Use of this source code is governed by a BSD-style license that can be 16 // Use of this source code is governed by a BSD-style license that can be
17 // found in the LICENSE file. 17 // found in the LICENSE file.
18 18
19 // Auto-generated by {module_pyname} 19 // Auto-generated by {module_pyname}
20 20
21 const CSSTokenizer::CodePoint CSSTokenizer::codePoints[{array_size}] = {{ 21 const CSSTokenizer::CodePoint CSSTokenizer::kCodePoints[{array_size}] = {{
22 {token_lines} 22 {token_lines}
23 }}; 23 }};
24 const unsigned codePointsNumber = {array_size}; 24 const unsigned codePointsNumber = {array_size};
25 """ 25 """
26 26
27 27
28 def token_type(i): 28 def token_type(i):
29 codepoints = {'(': 'leftParenthesis', 29 codepoints = {'(': 'LeftParenthesis',
30 ')': 'rightParenthesis', 30 ')': 'RightParenthesis',
31 '[': 'leftBracket', 31 '[': 'LeftBracket',
32 ']': 'rightBracket', 32 ']': 'RightBracket',
33 '{': 'leftBrace', 33 '{': 'LeftBrace',
34 '}': 'rightBrace', 34 '}': 'RightBrace',
35 '+': 'plusOrFullStop', 35 '+': 'PlusOrFullStop',
36 '.': 'plusOrFullStop', 36 '.': 'PlusOrFullStop',
37 '-': 'hyphenMinus', 37 '-': 'HyphenMinus',
38 '*': 'asterisk', 38 '*': 'Asterisk',
39 '<': 'lessThan', 39 '<': 'LessThan',
40 ',': 'comma', 40 ',': 'Comma',
41 '/': 'solidus', 41 '/': 'Solidus',
42 '\\': 'reverseSolidus', 42 '\\': 'ReverseSolidus',
43 ':': 'colon', 43 ':': 'Colon',
44 ';': 'semiColon', 44 ';': 'SemiColon',
45 '#': 'hash', 45 '#': 'Hash',
46 '^': 'circumflexAccent', 46 '^': 'CircumflexAccent',
47 '$': 'dollarSign', 47 '$': 'DollarSign',
48 '|': 'verticalLine', 48 '|': 'VerticalLine',
49 '~': 'tilde', 49 '~': 'Tilde',
50 '@': 'commercialAt', 50 '@': 'CommercialAt',
51 'u': 'letterU', 51 'u': 'LetterU',
52 'U': 'letterU', 52 'U': 'LetterU',
53 } 53 }
54 c = chr(i) 54 c = chr(i)
55 if c in codepoints: 55 if c in codepoints:
56 return codepoints[c] 56 return codepoints[c]
57 whitespace = '\n\r\t\f ' 57 whitespace = '\n\r\t\f '
58 quotes = '"\'' 58 quotes = '"\''
59 if c in whitespace: 59 if c in whitespace:
60 return 'whiteSpace' 60 return 'WhiteSpace'
61 if c.isdigit(): 61 if c.isdigit():
62 return 'asciiDigit' 62 return 'AsciiDigit'
63 if c.isalpha() or c == '_': 63 if c.isalpha() or c == '_':
64 return 'nameStart' 64 return 'NameStart'
65 if c in quotes: 65 if c in quotes:
66 return 'stringStart' 66 return 'StringStart'
67 if i == 0: 67 if i == 0:
68 return 'endOfFile' 68 return 'EndOfFile'
69 69
70 70
71 class MakeCSSTokenizerCodePointsWriter(in_generator.Writer): 71 class MakeCSSTokenizerCodePointsWriter(in_generator.Writer):
72 def __init__(self, in_file_path): 72 def __init__(self, in_file_path):
73 super(MakeCSSTokenizerCodePointsWriter, self).__init__(in_file_path) 73 super(MakeCSSTokenizerCodePointsWriter, self).__init__(in_file_path)
74 74
75 self._outputs = { 75 self._outputs = {
76 ('CSSTokenizerCodepoints.cpp'): self.generate, 76 ('CSSTokenizerCodepoints.cpp'): self.generate,
77 } 77 }
78 78
79 def generate(self): 79 def generate(self):
80 array_size = 128 # SCHAR_MAX + 1 80 array_size = 128 # SCHAR_MAX + 1
81 token_lines = [' &CSSTokenizer::%s,' % token_type(i) 81 token_lines = [' &CSSTokenizer::%s,' % token_type(i)
82 if token_type(i) else ' 0,' 82 if token_type(i) else ' 0,'
83 for i in range(array_size)] 83 for i in range(array_size)]
84 return CPP_TEMPLATE.format(array_size=array_size, token_lines='\n'.join( token_lines), module_pyname=module_pyname) 84 return CPP_TEMPLATE.format(array_size=array_size, token_lines='\n'.join( token_lines), module_pyname=module_pyname)
85 85
86 if __name__ == '__main__': 86 if __name__ == '__main__':
87 in_generator.Maker(MakeCSSTokenizerCodePointsWriter).main(sys.argv) 87 in_generator.Maker(MakeCSSTokenizerCodePointsWriter).main(sys.argv)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698