| OLD | NEW |
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import mojo_lexer | 5 import mojo_lexer |
| 6 import unittest | 6 import unittest |
| 7 | 7 |
| 8 # Try to load the ply module, if not, then assume it is in the third_party | 8 # Try to load the ply module, if not, then assume it is in the third_party |
| 9 # directory. | 9 # directory. |
| 10 try: | 10 try: |
| 11 # Disable lint check which fails to find the ply module. | 11 # Disable lint check which fails to find the ply module. |
| 12 # pylint: disable=F0401 | 12 # pylint: disable=F0401 |
| 13 from ply import lex | 13 from ply import lex |
| 14 except ImportError: | 14 except ImportError: |
| 15 # This assumes this file is in src/mojo/public/tools/bindings/pylib/parse/. |
| 15 module_path, module_name = os.path.split(__file__) | 16 module_path, module_name = os.path.split(__file__) |
| 16 third_party = os.path.join(module_path, os.pardir, os.pardir, os.pardir, | 17 third_party = os.path.join(module_path, os.pardir, os.pardir, os.pardir, |
| 17 os.pardir, os.pardir, 'third_party') | 18 os.pardir, os.pardir, os.pardir, 'third_party') |
| 18 sys.path.append(third_party) | 19 sys.path.append(third_party) |
| 19 # pylint: disable=F0401 | 20 # pylint: disable=F0401 |
| 20 from ply import lex | 21 from ply import lex |
| 21 | 22 |
| 22 | 23 |
| 23 # This (monkey-patching LexToken to make comparison value-based) is evil, but | 24 # This (monkey-patching LexToken to make comparison value-based) is evil, but |
| 24 # we'll do it anyway. (I'm pretty sure ply's lexer never cares about comparing | 25 # we'll do it anyway. (I'm pretty sure ply's lexer never cares about comparing |
| 25 # for object identity.) | 26 # for object identity.) |
| 26 def _LexTokenEq(self, other): | 27 def _LexTokenEq(self, other): |
| 27 return self.type == other.type and self.value == other.value and \ | 28 return self.type == other.type and self.value == other.value and \ |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 def _SingleTokenForInput(self, input): | 151 def _SingleTokenForInput(self, input): |
| 151 """Gets the single token for the given input string. (Raises an exception if | 152 """Gets the single token for the given input string. (Raises an exception if |
| 152 the input string does not result in exactly one token.)""" | 153 the input string does not result in exactly one token.)""" |
| 153 toks = self._TokensForInput(input) | 154 toks = self._TokensForInput(input) |
| 154 assert len(toks) == 1 | 155 assert len(toks) == 1 |
| 155 return toks[0] | 156 return toks[0] |
| 156 | 157 |
| 157 | 158 |
| 158 if __name__ == "__main__": | 159 if __name__ == "__main__": |
| 159 unittest.main() | 160 unittest.main() |
| OLD | NEW |