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 """ Parser for PPAPI IDL """ | 6 """ Parser for PPAPI IDL """ |
7 | 7 |
8 # | 8 # |
9 # IDL Parser | 9 # IDL Parser |
10 # | 10 # |
11 # The parser is uses the PLY yacc library to build a set of parsing rules based | 11 # The parser is uses the PLY yacc library to build a set of parsing rules based |
12 # on WebIDL. | 12 # on WebIDL. |
13 # | 13 # |
14 # WebIDL, and WebIDL grammar can be found at: | 14 # WebIDL, and WebIDL grammar can be found at: |
15 # http://dev.w3.org/2006/webapi/WebIDL/ | 15 # http://heycam.github.io/webidl/ |
16 # PLY can be found at: | 16 # PLY can be found at: |
17 # http://www.dabeaz.com/ply/ | 17 # http://www.dabeaz.com/ply/ |
18 # | 18 # |
19 # The parser generates a tree by recursively matching sets of items against | 19 # The parser generates a tree by recursively matching sets of items against |
20 # defined patterns. When a match is made, that set of items is reduced | 20 # defined patterns. When a match is made, that set of items is reduced |
21 # to a new item. The new item can provide a match for parent patterns. | 21 # to a new item. The new item can provide a match for parent patterns. |
22 # In this way an AST is built (reduced) depth first. | 22 # In this way an AST is built (reduced) depth first. |
23 # | 23 # |
24 | 24 |
25 # | 25 # |
(...skipping 17 matching lines...) Expand all Loading... |
43 # | 43 # |
44 # [0] Insert a TOP definition for Copyright and Comments | 44 # [0] Insert a TOP definition for Copyright and Comments |
45 def p_Top(self, p): | 45 def p_Top(self, p): |
46 """Top : COMMENT COMMENT Definitions""" | 46 """Top : COMMENT COMMENT Definitions""" |
47 Copyright = self.BuildComment('Copyright', p, 1) | 47 Copyright = self.BuildComment('Copyright', p, 1) |
48 Filedoc = self.BuildComment('Comment', p, 2) | 48 Filedoc = self.BuildComment('Comment', p, 2) |
49 p[0] = ListFromConcat(Copyright, Filedoc, p[3]) | 49 p[0] = ListFromConcat(Copyright, Filedoc, p[3]) |
50 | 50 |
51 # | 51 # |
52 #The parser is based on the WebIDL standard. See: | 52 #The parser is based on the WebIDL standard. See: |
53 # http://www.w3.org/TR/WebIDL/#idl-grammar | 53 # http://heycam.github.io/webidl/#idl-grammar |
54 # | 54 # |
55 # [1] | 55 # [1] |
56 def p_Definitions(self, p): | 56 def p_Definitions(self, p): |
57 """Definitions : ExtendedAttributeList Definition Definitions | 57 """Definitions : ExtendedAttributeList Definition Definitions |
58 | """ | 58 | """ |
59 if len(p) > 1: | 59 if len(p) > 1: |
60 p[2].AddChildren(p[1]) | 60 p[2].AddChildren(p[1]) |
61 p[0] = ListFromConcat(p[2], p[3]) | 61 p[0] = ListFromConcat(p[2], p[3]) |
62 | 62 |
63 # [2] Add INLINE definition | 63 # [2] Add INLINE definition |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 print '\n'.join(ast.Tree(accept_props=['PROD', 'TYPE', 'VALUE'])) | 295 print '\n'.join(ast.Tree(accept_props=['PROD', 'TYPE', 'VALUE'])) |
296 if errors: | 296 if errors: |
297 print '\nFound %d errors.\n' % errors | 297 print '\nFound %d errors.\n' % errors |
298 | 298 |
299 | 299 |
300 return errors | 300 return errors |
301 | 301 |
302 | 302 |
303 if __name__ == '__main__': | 303 if __name__ == '__main__': |
304 sys.exit(main(sys.argv[1:])) | 304 sys.exit(main(sys.argv[1:])) |
OLD | NEW |