| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # | 2 # |
| 3 # Copyright 2012 the V8 project authors. All rights reserved. | 3 # Copyright 2012 the V8 project authors. All rights reserved. |
| 4 # Redistribution and use in source and binary forms, with or without | 4 # Redistribution and use in source and binary forms, with or without |
| 5 # modification, are permitted provided that the following conditions are | 5 # modification, are permitted provided that the following conditions are |
| 6 # met: | 6 # met: |
| 7 # | 7 # |
| 8 # * Redistributions of source code must retain the above copyright | 8 # * Redistributions of source code must retain the above copyright |
| 9 # notice, this list of conditions and the following disclaimer. | 9 # notice, this list of conditions and the following disclaimer. |
| 10 # * Redistributions in binary form must reproduce the above | 10 # * Redistributions in binary form must reproduce the above |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 def expander(s): | 138 def expander(s): |
| 139 return ExpandMacros(s, macros) | 139 return ExpandMacros(s, macros) |
| 140 lines = ExpandMacroDefinition(lines, 0, name_pattern, macro, expander) | 140 lines = ExpandMacroDefinition(lines, 0, name_pattern, macro, expander) |
| 141 return lines | 141 return lines |
| 142 | 142 |
| 143 class TextMacro: | 143 class TextMacro: |
| 144 def __init__(self, args, body): | 144 def __init__(self, args, body): |
| 145 self.args = args | 145 self.args = args |
| 146 self.body = body | 146 self.body = body |
| 147 def expand(self, mapping): | 147 def expand(self, mapping): |
| 148 result = self.body | 148 # Keys could be substrings of earlier values. To avoid unintended |
| 149 for key, value in mapping.items(): | 149 # clobbering, apply all replacements simultaneously. |
| 150 result = result.replace(key, value) | 150 any_key_pattern = "|".join(re.escape(k) for k in mapping.iterkeys()) |
| 151 return result | 151 def replace(match): |
| 152 return mapping[match.group(0)] |
| 153 return re.sub(any_key_pattern, replace, self.body) |
| 152 | 154 |
| 153 class PythonMacro: | 155 class PythonMacro: |
| 154 def __init__(self, args, fun): | 156 def __init__(self, args, fun): |
| 155 self.args = args | 157 self.args = args |
| 156 self.fun = fun | 158 self.fun = fun |
| 157 def expand(self, mapping): | 159 def expand(self, mapping): |
| 158 args = [] | 160 args = [] |
| 159 for arg in self.args: | 161 for arg in self.args: |
| 160 args.append(mapping[arg]) | 162 args.append(mapping[arg]) |
| 161 return str(self.fun(*args)) | 163 return str(self.fun(*args)) |
| (...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 595 JS2C(args[2:], | 597 JS2C(args[2:], |
| 596 args[0], | 598 args[0], |
| 597 args[1], | 599 args[1], |
| 598 options.raw, | 600 options.raw, |
| 599 options.startup_blob, | 601 options.startup_blob, |
| 600 options.js) | 602 options.js) |
| 601 | 603 |
| 602 | 604 |
| 603 if __name__ == "__main__": | 605 if __name__ == "__main__": |
| 604 main() | 606 main() |
| OLD | NEW |