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

Side by Side Diff: pkg/analyzer/lib/src/task/html.dart

Issue 1185443002: Support for parsing HTML in the new task model (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 years, 6 months 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
(Empty)
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
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.
4
5 library analyzer.src.task.html;
6
7 import 'package:analyzer/src/generated/engine.dart' hide AnalysisTask;
8 import 'package:analyzer/src/generated/source.dart';
9 import 'package:analyzer/src/task/general.dart';
10 import 'package:analyzer/task/general.dart';
11 import 'package:analyzer/task/html.dart';
12 import 'package:analyzer/task/model.dart';
13 import 'package:html/dom.dart';
14 import 'package:html/parser.dart';
15
16 /**
17 * A task that scans the content of a file, producing a set of Dart tokens.
18 */
19 class ParseHtmlTask extends SourceBasedAnalysisTask {
20 /**
21 * The name of the input whose value is the content of the file.
22 */
23 static const String CONTENT_INPUT_NAME = 'CONTENT_INPUT_NAME';
24
25 /**
26 * The task descriptor describing this kind of task.
27 */
28 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor('ParseHtmlTask',
29 createTask, buildInputs, <ResultDescriptor>[DOCUMENT, DOCUMENT_ERRORS]);
30
31 /**
32 * Initialize a newly created task to access the content of the source
33 * associated with the given [target] in the given [context].
34 */
35 ParseHtmlTask(InternalAnalysisContext context, AnalysisTarget target)
36 : super(context, target);
37
38 @override
39 TaskDescriptor get descriptor => DESCRIPTOR;
40
41 @override
42 void internalPerform() {
43 String content = getRequiredInput(CONTENT_INPUT_NAME);
44
45 HtmlParser parser = new HtmlParser(content);
46 Document document = parser.parse();
47 List<ParseError> errors = parser.errors;
48
49 outputs[DOCUMENT] = document;
50 outputs[DOCUMENT_ERRORS] = errors;
51 }
52
53 /**
54 * Return a map from the names of the inputs of this kind of task to the task
55 * input descriptors describing those inputs for a task with the given
56 * [source].
57 */
58 static Map<String, TaskInput> buildInputs(Source source) {
59 return <String, TaskInput>{CONTENT_INPUT_NAME: CONTENT.of(source)};
60 }
61
62 /**
63 * Create a [ParseHtmlTask] based on the given [target] in the given [context] .
64 */
65 static ParseHtmlTask createTask(
66 AnalysisContext context, AnalysisTarget target) {
67 return new ParseHtmlTask(context, target);
68 }
69 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698