OLD | NEW |
---|---|
(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 | |
Nils Barth (inactive)
2014/03/26 09:13:39
This is fragile to renaming; more robust is to use
| |
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', | |
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 ' | |
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) | |
76 if token_type(i) else ' 0,' | |
77 for i in range(array_size)] | |
78 return CPP_TEMPLATE.format(array_size=array_size, token_lines='\n'.join( token_lines)) | |
79 | |
80 if __name__ == '__main__': | |
81 in_generator.Maker(MakeMediaQueryTokenizerCodePointsWriter).main(sys.argv) | |
OLD | NEW |