Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(15)

Side by Side Diff: pkg/analysis_server/tool/spec/from_html.dart

Issue 1431683002: Refactor analysis server code generation to re-use logic from analyzer. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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';
11 11
12 import 'package:analyzer/src/codegen/html.dart';
12 import 'package:html/dom.dart' as dom; 13 import 'package:html/dom.dart' as dom;
13 import 'package:html/parser.dart' as parser; 14 import 'package:html/parser.dart' as parser;
15 import 'package:path/path.dart';
14 16
15 import 'api.dart'; 17 import 'api.dart';
16 import 'html_tools.dart';
17 18
18 const List<String> specialElements = const [ 19 const List<String> specialElements = const [
19 'domain', 20 'domain',
20 'feedback', 21 'feedback',
21 'object', 22 'object',
22 'refactorings', 23 'refactorings',
23 'refactoring', 24 'refactoring',
24 'type', 25 'type',
25 'types', 26 'types',
26 'request', 27 'request',
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 checkAttributes(child, ['field'], context); 281 checkAttributes(child, ['field'], context);
281 String field = child.attributes['field']; 282 String field = child.attributes['field'];
282 types.add( 283 types.add(
283 new TypeUnion(processContentsAsTypes(child, context), field, child)); 284 new TypeUnion(processContentsAsTypes(child, context), field, child));
284 } 285 }
285 }); 286 });
286 return types; 287 return types;
287 } 288 }
288 289
289 /** 290 /**
290 * Read the API description from the file 'spec_input.html'. 291 * Read the API description from the file 'spec_input.html'. [pkgPath] is the
292 * path to the current package.
291 */ 293 */
292 Api readApi() { 294 Api readApi(String pkgPath) {
293 File htmlFile = new File('spec_input.html'); 295 File htmlFile = new File(join(pkgPath, 'tool', 'spec', 'spec_input.html'));
294 String htmlContents = htmlFile.readAsStringSync(); 296 String htmlContents = htmlFile.readAsStringSync();
295 dom.Document document = parser.parse(htmlContents); 297 dom.Document document = parser.parse(htmlContents);
296 dom.Element htmlElement = document.children 298 dom.Element htmlElement = document.children
297 .singleWhere((element) => element.localName.toLowerCase() == 'html'); 299 .singleWhere((element) => element.localName.toLowerCase() == 'html');
298 return apiFromHtml(htmlElement); 300 return apiFromHtml(htmlElement);
299 } 301 }
300 302
301 void recurse(dom.Element parent, String context, 303 void recurse(dom.Element parent, String context,
302 Map<String, ElementProcessor> elementProcessors) { 304 Map<String, ElementProcessor> elementProcessors) {
303 for (String key in elementProcessors.keys) { 305 for (String key in elementProcessors.keys) {
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
538 TypeDefinition typeDefinition = typeDefinitionFromHtml(child); 540 TypeDefinition typeDefinition = typeDefinitionFromHtml(child);
539 types[typeDefinition.name] = typeDefinition; 541 types[typeDefinition.name] = typeDefinition;
540 } 542 }
541 }); 543 });
542 return new Types(types, html); 544 return new Types(types, html);
543 } 545 }
544 546
545 typedef void ElementProcessor(dom.Element element); 547 typedef void ElementProcessor(dom.Element element);
546 548
547 typedef void TextProcessor(dom.Text text); 549 typedef void TextProcessor(dom.Text text);
OLDNEW
« no previous file with comments | « pkg/analysis_server/tool/spec/codegen_tools.dart ('k') | pkg/analysis_server/tool/spec/generate_all.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698