OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * Code for reading an HTML API description. | 6 * Code for reading an HTML API description. |
7 */ | 7 */ |
8 library from.html; | 8 library from.html; |
9 | 9 |
10 import 'dart:io'; | 10 import 'dart:io'; |
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
381 types.add(new TypeMap(keyType, valueType, child)); | 381 types.add(new TypeMap(keyType, valueType, child)); |
382 }, | 382 }, |
383 'enum': (dom.Element child) { | 383 'enum': (dom.Element child) { |
384 types.add(typeEnumFromHtml(child)); | 384 types.add(typeEnumFromHtml(child)); |
385 }, | 385 }, |
386 'ref': (dom.Element child) { | 386 'ref': (dom.Element child) { |
387 checkAttributes(child, []); | 387 checkAttributes(child, []); |
388 types.add(new TypeReference(innerText(child), child)); | 388 types.add(new TypeReference(innerText(child), child)); |
389 }, | 389 }, |
390 'union': (dom.Element child) { | 390 'union': (dom.Element child) { |
391 checkAttributes(child, []); | 391 checkAttributes(child, ['field']); |
392 types.add(new TypeUnion(processContentsAsTypes(child), child)); | 392 String field = child.attributes['field']; |
| 393 types.add(new TypeUnion(processContentsAsTypes(child), field, child)); |
393 } | 394 } |
394 }); | 395 }); |
395 return types; | 396 return types; |
396 } | 397 } |
397 | 398 |
398 /** | 399 /** |
399 * Create a [TypeEnum] from an HTML description. | 400 * Create a [TypeEnum] from an HTML description. |
400 */ | 401 */ |
401 TypeEnum typeEnumFromHtml(dom.Element html) { | 402 TypeEnum typeEnumFromHtml(dom.Element html) { |
402 checkName(html, 'enum'); | 403 checkName(html, 'enum'); |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
493 | 494 |
494 /** | 495 /** |
495 * Read the API description from the file 'spec_input.html'. | 496 * Read the API description from the file 'spec_input.html'. |
496 */ | 497 */ |
497 Api readApi() { | 498 Api readApi() { |
498 File htmlFile = new File('spec_input.html'); | 499 File htmlFile = new File('spec_input.html'); |
499 String htmlContents = htmlFile.readAsStringSync(); | 500 String htmlContents = htmlFile.readAsStringSync(); |
500 dom.Document document = parser.parse(htmlContents); | 501 dom.Document document = parser.parse(htmlContents); |
501 return apiFromHtml(document.firstChild); | 502 return apiFromHtml(document.firstChild); |
502 } | 503 } |
OLD | NEW |