OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # | 2 # |
3 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 3 # Copyright (c) 2011 The Chromium Authors. All rights reserved. |
4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
6 | 6 |
7 """ Parser for PPAPI IDL """ | 7 """ Parser for PPAPI IDL """ |
8 | 8 |
9 # | 9 # |
10 # IDL Parser | 10 # IDL Parser |
(...skipping 27 matching lines...) Expand all Loading... |
38 from idl_lint import Lint | 38 from idl_lint import Lint |
39 | 39 |
40 from ply import lex | 40 from ply import lex |
41 from ply import yacc | 41 from ply import yacc |
42 | 42 |
43 Option('build_debug', 'Debug tree building.') | 43 Option('build_debug', 'Debug tree building.') |
44 Option('parse_debug', 'Debug parse reduction steps.') | 44 Option('parse_debug', 'Debug parse reduction steps.') |
45 Option('token_debug', 'Debug token generation.') | 45 Option('token_debug', 'Debug token generation.') |
46 Option('dump_tree', 'Dump the tree.') | 46 Option('dump_tree', 'Dump the tree.') |
47 Option('srcroot', 'Working directory.', default=os.path.join('..', 'api')) | 47 Option('srcroot', 'Working directory.', default=os.path.join('..', 'api')) |
| 48 Option('include_private', 'Include private IDL directory in default API paths.') |
48 | 49 |
49 # | 50 # |
50 # ERROR_REMAP | 51 # ERROR_REMAP |
51 # | 52 # |
52 # Maps the standard error formula into a more friendly error message. | 53 # Maps the standard error formula into a more friendly error message. |
53 # | 54 # |
54 ERROR_REMAP = { | 55 ERROR_REMAP = { |
55 'Unexpected ")" after "(".' : 'Empty argument list.', | 56 'Unexpected ")" after "(".' : 'Empty argument list.', |
56 'Unexpected ")" after ",".' : 'Missing argument.', | 57 'Unexpected ")" after ",".' : 'Missing argument.', |
57 'Unexpected "}" after ",".' : 'Trailing comma in block.', | 58 'Unexpected "}" after ",".' : 'Trailing comma in block.', |
(...skipping 936 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
994 ast = ParseFiles(testnames) | 995 ast = ParseFiles(testnames) |
995 InfoOut.SetConsole(True) | 996 InfoOut.SetConsole(True) |
996 | 997 |
997 errs = ast.GetProperty('ERRORS') | 998 errs = ast.GetProperty('ERRORS') |
998 if errs: | 999 if errs: |
999 ErrOut.Log("Failed namespace test.") | 1000 ErrOut.Log("Failed namespace test.") |
1000 else: | 1001 else: |
1001 InfoOut.Log("Passed namespace test.") | 1002 InfoOut.Log("Passed namespace test.") |
1002 return errs | 1003 return errs |
1003 | 1004 |
1004 default_dirs = ['.', 'trusted', 'dev', 'private'] | 1005 default_dirs = ['.', 'trusted', 'dev'] |
1005 def ParseFiles(filenames): | 1006 def ParseFiles(filenames): |
1006 parser = IDLParser() | 1007 parser = IDLParser() |
1007 filenodes = [] | 1008 filenodes = [] |
1008 | 1009 |
1009 if not filenames: | 1010 if not filenames: |
1010 filenames = [] | 1011 filenames = [] |
1011 srcroot = GetOption('srcroot') | 1012 srcroot = GetOption('srcroot') |
1012 for dirname in default_dirs: | 1013 dirs = default_dirs |
| 1014 if GetOption('include_private'): |
| 1015 dirs += ['private'] |
| 1016 for dirname in dirs: |
1013 srcdir = os.path.join(srcroot, dirname, '*.idl') | 1017 srcdir = os.path.join(srcroot, dirname, '*.idl') |
1014 srcdir = os.path.normpath(srcdir) | 1018 srcdir = os.path.normpath(srcdir) |
1015 filenames += sorted(glob.glob(srcdir)) | 1019 filenames += sorted(glob.glob(srcdir)) |
1016 | 1020 |
1017 for filename in filenames: | 1021 for filename in filenames: |
1018 filenode = parser.ParseFile(filename) | 1022 filenode = parser.ParseFile(filename) |
1019 filenodes.append(filenode) | 1023 filenodes.append(filenode) |
1020 | 1024 |
1021 ast = IDLAst(filenodes) | 1025 ast = IDLAst(filenodes) |
1022 if GetOption('dump_tree'): ast.Dump(0) | 1026 if GetOption('dump_tree'): ast.Dump(0) |
(...skipping 17 matching lines...) Expand all Loading... |
1040 # Otherwise, build the AST | 1044 # Otherwise, build the AST |
1041 ast = ParseFiles(filenames) | 1045 ast = ParseFiles(filenames) |
1042 errs = ast.GetProperty('ERRORS') | 1046 errs = ast.GetProperty('ERRORS') |
1043 if errs: | 1047 if errs: |
1044 ErrOut.Log('Found %d error(s).' % errs); | 1048 ErrOut.Log('Found %d error(s).' % errs); |
1045 InfoOut.Log("%d files processed." % len(filenames)) | 1049 InfoOut.Log("%d files processed." % len(filenames)) |
1046 return errs | 1050 return errs |
1047 | 1051 |
1048 if __name__ == '__main__': | 1052 if __name__ == '__main__': |
1049 sys.exit(Main(sys.argv[1:])) | 1053 sys.exit(Main(sys.argv[1:])) |
1050 | |
OLD | NEW |