| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 | 2 |
| 3 import os.path | 3 import os.path |
| 4 import re | 4 import re |
| 5 import subprocess | 5 import subprocess |
| 6 import sys | 6 import sys |
| 7 | 7 |
| 8 from in_file import InFile | |
| 9 from name_utilities import enum_for_css_keyword | 8 from name_utilities import enum_for_css_keyword |
| 10 from name_utilities import upper_first_letter | 9 from name_utilities import upper_first_letter |
| 11 import in_generator | 10 import json5_generator |
| 12 import license | 11 import license |
| 13 | 12 |
| 14 | 13 |
| 15 HEADER_TEMPLATE = """ | 14 HEADER_TEMPLATE = """ |
| 16 %(license)s | 15 %(license)s |
| 17 | 16 |
| 18 #ifndef %(class_name)s_h | 17 #ifndef %(class_name)s_h |
| 19 #define %(class_name)s_h | 18 #define %(class_name)s_h |
| 20 | 19 |
| 21 #include "core/css/parser/CSSParserMode.h" | 20 #include "core/css/parser/CSSParserMode.h" |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 return isUASheetBehavior(mode) || isQuirksModeBehavior(mode); | 98 return isUASheetBehavior(mode) || isQuirksModeBehavior(mode); |
| 100 default: | 99 default: |
| 101 return true; | 100 return true; |
| 102 } | 101 } |
| 103 } | 102 } |
| 104 | 103 |
| 105 } // namespace blink | 104 } // namespace blink |
| 106 """ | 105 """ |
| 107 | 106 |
| 108 | 107 |
| 109 class CSSValueKeywordsWriter(in_generator.Writer): | 108 class CSSValueKeywordsWriter(json5_generator.Writer): |
| 110 class_name = "CSSValueKeywords" | 109 class_name = "CSSValueKeywords" |
| 111 defaults = { | |
| 112 'mode': None, | |
| 113 } | |
| 114 | 110 |
| 115 def __init__(self, file_paths): | 111 def __init__(self, file_paths): |
| 116 in_generator.Writer.__init__(self, file_paths) | 112 json5_generator.Writer.__init__(self, file_paths) |
| 117 self._outputs = {(self.class_name + ".h"): self.generate_header, | 113 self._outputs = {(self.class_name + ".h"): self.generate_header, |
| 118 (self.class_name + ".cpp"): self.generate_implementatio
n, | 114 (self.class_name + ".cpp"): self.generate_implementatio
n, |
| 119 } | 115 } |
| 120 | 116 |
| 121 self._value_keywords = self.in_file.name_dictionaries | 117 self._value_keywords = self.json5_file.name_dictionaries |
| 122 first_keyword_id = 1 | 118 first_keyword_id = 1 |
| 123 for offset, keyword in enumerate(self._value_keywords): | 119 for offset, keyword in enumerate(self._value_keywords): |
| 124 keyword['lower_name'] = keyword['name'].lower() | 120 keyword['lower_name'] = keyword['name'].lower() |
| 125 keyword['enum_name'] = enum_for_css_keyword(keyword['name']) | 121 keyword['enum_name'] = enum_for_css_keyword(keyword['name']) |
| 126 keyword['enum_value'] = first_keyword_id + offset | 122 keyword['enum_value'] = first_keyword_id + offset |
| 127 if keyword['name'].startswith('-internal-'): | 123 if keyword['name'].startswith('-internal-'): |
| 128 assert keyword['mode'] is None, 'Can\'t specify mode for value k
eywords with the prefix "-internal-".' | 124 assert keyword['mode'] is None, 'Can\'t specify mode for value k
eywords with the prefix "-internal-".' |
| 129 keyword['mode'] = 'UASheet' | 125 keyword['mode'] = 'UASheet' |
| 130 else: | 126 else: |
| 131 assert keyword['mode'] != 'UASheet', 'UASheet mode only value ke
ywords should have the prefix "-internal-".' | 127 assert keyword['mode'] != 'UASheet', 'UASheet mode only value ke
ywords should have the prefix "-internal-".' |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 } | 163 } |
| 168 # FIXME: If we could depend on Python 2.7, we would use subprocess.check
_output | 164 # FIXME: If we could depend on Python 2.7, we would use subprocess.check
_output |
| 169 gperf_args = [self.gperf_path, '--key-positions=*', '-P', '-n'] | 165 gperf_args = [self.gperf_path, '--key-positions=*', '-P', '-n'] |
| 170 gperf_args.extend(['-m', '50']) # Pick best of 50 attempts. | 166 gperf_args.extend(['-m', '50']) # Pick best of 50 attempts. |
| 171 gperf_args.append('-D') # Allow duplicate hashes -> More compact code. | 167 gperf_args.append('-D') # Allow duplicate hashes -> More compact code. |
| 172 gperf = subprocess.Popen(gperf_args, stdin=subprocess.PIPE, stdout=subpr
ocess.PIPE, universal_newlines=True) | 168 gperf = subprocess.Popen(gperf_args, stdin=subprocess.PIPE, stdout=subpr
ocess.PIPE, universal_newlines=True) |
| 173 return gperf.communicate(gperf_input)[0] | 169 return gperf.communicate(gperf_input)[0] |
| 174 | 170 |
| 175 | 171 |
| 176 if __name__ == "__main__": | 172 if __name__ == "__main__": |
| 177 in_generator.Maker(CSSValueKeywordsWriter).main(sys.argv) | 173 json5_generator.Maker(CSSValueKeywordsWriter).main(sys.argv) |
| OLD | NEW |