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 import os |
| 10 |
| 11 module_basename = os.path.basename(__file__) |
| 12 module_pyname = os.path.splitext(module_basename)[0] + '.py' |
| 13 |
| 14 CPP_TEMPLATE = """ |
| 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 |
| 17 // found in the LICENSE file. |
| 18 |
| 19 // Auto-generated by {module_pyname} |
| 20 |
| 21 const MediaQueryTokenizer::CodePoint MediaQueryTokenizer::codePoints[{array_size
}] = {{ |
| 22 {token_lines} |
| 23 }}; |
| 24 const unsigned codePointsNumber = {array_size}; |
| 25 """ |
| 26 |
| 27 |
| 28 def token_type(i): |
| 29 codepoints = {'(': 'leftParenthesis', |
| 30 ')': 'rightParenthesis', |
| 31 '+': 'plusOrFullStop', |
| 32 '.': 'plusOrFullStop', |
| 33 '-': 'hyphenMinus', |
| 34 ',': 'comma', |
| 35 '/': 'solidus', |
| 36 '\\': 'reverseSolidus', |
| 37 ':': 'colon', |
| 38 ';': 'semiColon', |
| 39 } |
| 40 whitespace = '\n\r\t\f ' |
| 41 c = chr(i) |
| 42 if c in whitespace: |
| 43 return 'whiteSpace' |
| 44 if c.isdigit(): |
| 45 return 'asciiDigit' |
| 46 if c.isalpha() or c == '_': |
| 47 return 'nameStart' |
| 48 if i == 0: |
| 49 return 'endOfFile' |
| 50 return codepoints.get(c) |
| 51 |
| 52 |
| 53 class MakeMediaQueryTokenizerCodePointsWriter(in_generator.Writer): |
| 54 defaults = { |
| 55 'Conditional': None, |
| 56 'RuntimeEnabled': None, |
| 57 'ImplementedAs': None, |
| 58 } |
| 59 filters = { |
| 60 } |
| 61 default_parameters = { |
| 62 'namespace': '', |
| 63 'export': '', |
| 64 } |
| 65 |
| 66 def __init__(self, in_file_path): |
| 67 super(MakeMediaQueryTokenizerCodePointsWriter, self).__init__(in_file_pa
th) |
| 68 |
| 69 self._outputs = { |
| 70 ('MediaQueryTokenizerCodepoints.cpp'): self.generate, |
| 71 } |
| 72 self._template_context = { |
| 73 'namespace': '', |
| 74 'export': '', |
| 75 } |
| 76 |
| 77 def generate(self): |
| 78 array_size = 128 # SCHAR_MAX + 1 |
| 79 token_lines = [' &MediaQueryTokenizer::%s,' % token_type(i) |
| 80 if token_type(i) else ' 0,' |
| 81 for i in range(array_size)] |
| 82 return CPP_TEMPLATE.format(array_size=array_size, token_lines='\n'.join(
token_lines), module_pyname=module_pyname) |
| 83 |
| 84 if __name__ == '__main__': |
| 85 in_generator.Maker(MakeMediaQueryTokenizerCodePointsWriter).main(sys.argv) |
OLD | NEW |