OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 #library('classify'); | 5 #library('classify'); |
6 | 6 |
7 #import('../../lib/compiler/implementation/scanner/scannerlib.dart'); | 7 #import('../../lib/compiler/implementation/scanner/scannerlib.dart'); |
8 #import('markdown.dart', prefix: 'md'); | 8 #import('markdown.dart', prefix: 'md'); |
9 | 9 |
10 /** | 10 /** |
11 * Kinds of tokens that we care to highlight differently. The values of the | 11 * Kinds of tokens that we care to highlight differently. The values of the |
12 * fields here will be used as CSS class names for the generated spans. | 12 * fields here will be used as CSS class names for the generated spans. |
13 */ | 13 */ |
14 class Classification { | 14 class Classification { |
15 static final NONE = null; | 15 static const NONE = null; |
16 static final ERROR = "e"; | 16 static const ERROR = "e"; |
17 static final COMMENT = "c"; | 17 static const COMMENT = "c"; |
18 static final IDENTIFIER = "i"; | 18 static const IDENTIFIER = "i"; |
19 static final KEYWORD = "k"; | 19 static const KEYWORD = "k"; |
20 static final OPERATOR = "o"; | 20 static const OPERATOR = "o"; |
21 static final STRING = "s"; | 21 static const STRING = "s"; |
22 static final NUMBER = "n"; | 22 static const NUMBER = "n"; |
23 static final PUNCTUATION = "p"; | 23 static const PUNCTUATION = "p"; |
24 | 24 |
25 // A few things that are nice to make different: | 25 // A few things that are nice to make different: |
26 static final TYPE_IDENTIFIER = "t"; | 26 static const TYPE_IDENTIFIER = "t"; |
27 | 27 |
28 // Between a keyword and an identifier | 28 // Between a keyword and an identifier |
29 static final SPECIAL_IDENTIFIER = "r"; | 29 static const SPECIAL_IDENTIFIER = "r"; |
30 | 30 |
31 static final ARROW_OPERATOR = "a"; | 31 static const ARROW_OPERATOR = "a"; |
32 | 32 |
33 static final STRING_INTERPOLATION = 'si'; | 33 static const STRING_INTERPOLATION = 'si'; |
34 } | 34 } |
35 | 35 |
36 String classifySource(String text) { | 36 String classifySource(String text) { |
37 var html = new StringBuffer(); | 37 var html = new StringBuffer(); |
38 var tokenizer = new StringScanner(text, includeComments: true); | 38 var tokenizer = new StringScanner(text, includeComments: true); |
39 | 39 |
40 var whitespaceOffset = 0; | 40 var whitespaceOffset = 0; |
41 var token = tokenizer.tokenize(); | 41 var token = tokenizer.tokenize(); |
42 var inString = false; | 42 var inString = false; |
43 while (token.kind != EOF_TOKEN) { | 43 while (token.kind != EOF_TOKEN) { |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 } | 195 } |
196 return Classification.KEYWORD; | 196 return Classification.KEYWORD; |
197 | 197 |
198 case EOF_TOKEN: | 198 case EOF_TOKEN: |
199 return Classification.NONE; | 199 return Classification.NONE; |
200 | 200 |
201 default: | 201 default: |
202 return Classification.NONE; | 202 return Classification.NONE; |
203 } | 203 } |
204 } | 204 } |
OLD | NEW |