OLD | NEW |
1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 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 from collections import defaultdict, Mapping | 5 from collections import defaultdict, Mapping |
| 6 import traceback |
6 | 7 |
7 from third_party.json_schema_compiler import json_parse, idl_schema, idl_parser | 8 from third_party.json_schema_compiler import json_parse, idl_schema, idl_parser |
8 | 9 |
9 | 10 |
10 def RemoveNoDocs(item): | 11 def RemoveNoDocs(item): |
11 '''Removes nodes that should not be rendered from an API schema. | 12 '''Removes nodes that should not be rendered from an API schema. |
12 ''' | 13 ''' |
13 if json_parse.IsDict(item): | 14 if json_parse.IsDict(item): |
14 if item.get('nodoc', False): | 15 if item.get('nodoc', False): |
15 return True | 16 return True |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 if is_idl: | 105 if is_idl: |
105 DetectInlineableTypes(schema) | 106 DetectInlineableTypes(schema) |
106 InlineDocs(schema) | 107 InlineDocs(schema) |
107 return schema | 108 return schema |
108 | 109 |
109 if path.endswith('.idl'): | 110 if path.endswith('.idl'): |
110 idl = idl_schema.IDLSchema(idl_parser.IDLParser().ParseData(file_data)) | 111 idl = idl_schema.IDLSchema(idl_parser.IDLParser().ParseData(file_data)) |
111 # Wrap the result in a list so that it behaves like JSON API data. | 112 # Wrap the result in a list so that it behaves like JSON API data. |
112 return [trim_and_inline(idl.process()[0], is_idl=True)] | 113 return [trim_and_inline(idl.process()[0], is_idl=True)] |
113 | 114 |
114 schemas = json_parse.Parse(file_data) | 115 try: |
| 116 schemas = json_parse.Parse(file_data) |
| 117 except: |
| 118 raise ValueError('Cannot parse "%s" as JSON:\n%s' % |
| 119 (path, traceback.format_exc())) |
115 for schema in schemas: | 120 for schema in schemas: |
116 # Schemas could consist of one API schema (data for a specific API file) | 121 # Schemas could consist of one API schema (data for a specific API file) |
117 # or multiple (data from extension_api.json). | 122 # or multiple (data from extension_api.json). |
118 trim_and_inline(schema) | 123 trim_and_inline(schema) |
119 return schemas | 124 return schemas |
OLD | NEW |