OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2013 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2013 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """ Lexer for PPAPI IDL | 6 """ Lexer for PPAPI IDL |
7 | 7 |
8 The lexer uses the PLY library to build a tokenizer which understands both | 8 The lexer uses the PLY library to build a tokenizer which understands both |
9 WebIDL and Pepper tokens. | 9 WebIDL and Pepper tokens. |
10 | 10 |
11 WebIDL, and WebIDL regular expressions can be found at: | 11 WebIDL, and WebIDL regular expressions can be found at: |
12 http://www.w3.org/TR/2012/CR-WebIDL-20120419/ | 12 http://www.w3.org/TR/2012/CR-WebIDL-20120419/ |
13 PLY can be found at: | 13 PLY can be found at: |
14 http://www.dabeaz.com/ply/ | 14 http://www.dabeaz.com/ply/ |
15 """ | 15 """ |
16 | 16 |
17 import os.path | 17 import os.path |
18 import sys | 18 import sys |
19 | 19 |
20 # | 20 SRC_DIR = os.path.join(os.path.dirname(__file__), os.pardir, os.pardir) |
21 # Try to load the ply module, if not, then assume it is in the third_party | 21 sys.path.insert(0, os.path.join(SRC_DIR, 'third_party')) |
22 # directory. | 22 from ply import lex |
23 # | 23 |
24 try: | |
25 # Disable lint check which fails to find the ply module. | |
26 # pylint: disable=F0401 | |
27 from ply import lex | |
28 except ImportError: | |
29 module_path, module_name = os.path.split(__file__) | |
30 third_party = os.path.join(module_path, '..', '..', 'third_party') | |
31 sys.path.append(third_party) | |
32 # pylint: disable=F0401 | |
33 from ply import lex | |
34 | 24 |
35 # | 25 # |
36 # IDL Lexer | 26 # IDL Lexer |
37 # | 27 # |
38 class IDLLexer(object): | 28 class IDLLexer(object): |
39 # 'literals' is a value expected by lex which specifies a list of valid | 29 # 'literals' is a value expected by lex which specifies a list of valid |
40 # literal tokens, meaning the token type and token value are identical. | 30 # literal tokens, meaning the token type and token value are identical. |
41 literals = r'"*.(){}[],;:=+-/~|&^?<>' | 31 literals = r'"*.(){}[],;:=+-/~|&^?<>' |
42 | 32 |
43 # 't_ignore' contains ignored characters (spaces and tabs) | 33 # 't_ignore' contains ignored characters (spaces and tabs) |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 self.tokens = [] | 276 self.tokens = [] |
287 self._AddTokens(IDLLexer.tokens) | 277 self._AddTokens(IDLLexer.tokens) |
288 self._AddKeywords(IDLLexer.keywords) | 278 self._AddKeywords(IDLLexer.keywords) |
289 self._lexobj = None | 279 self._lexobj = None |
290 self.last = None | 280 self.last = None |
291 self.lines = None | 281 self.lines = None |
292 | 282 |
293 # If run by itself, attempt to build the lexer | 283 # If run by itself, attempt to build the lexer |
294 if __name__ == '__main__': | 284 if __name__ == '__main__': |
295 lexer_object = IDLLexer() | 285 lexer_object = IDLLexer() |
OLD | NEW |