@@ -18,7 +18,6 @@ use std::io;
18
18
19
19
use syntax:: parse;
20
20
use syntax:: parse:: lexer;
21
- use syntax:: codemap:: { BytePos , Span } ;
22
21
23
22
use html:: escape:: Escape ;
24
23
@@ -59,38 +58,30 @@ fn doit(sess: &parse::ParseSess, mut lexer: lexer::StringReader,
59
58
None => { }
60
59
}
61
60
try!( write ! ( out, "class='rust {}'>\n " , class. unwrap_or( "" ) ) ) ;
62
- let mut last = BytePos ( 0 ) ;
63
61
let mut is_attribute = false ;
64
62
let mut is_macro = false ;
65
63
let mut is_macro_nonterminal = false ;
66
64
loop {
67
65
let next = lexer. next_token ( ) ;
68
- let test = if next. tok == t:: EOF { lexer. pos } else { next. sp . lo } ;
69
-
70
- // The lexer consumes all whitespace and non-doc-comments when iterating
71
- // between tokens. If this token isn't directly adjacent to our last
72
- // token, then we need to emit the whitespace/comment.
73
- //
74
- // If the gap has any '/' characters then we consider the whole thing a
75
- // comment. This will classify some whitespace as a comment, but that
76
- // doesn't matter too much for syntax highlighting purposes.
77
- if test > last {
78
- let snip = sess. span_diagnostic . cm . span_to_snippet ( Span {
79
- lo : last,
80
- hi : test,
81
- expn_info : None ,
82
- } ) . unwrap ( ) ;
83
- if snip. as_slice ( ) . contains ( "/" ) {
84
- try!( write ! ( out, "<span class='comment'>{}</span>" ,
85
- Escape ( snip. as_slice( ) ) ) ) ;
86
- } else {
87
- try!( write ! ( out, "{}" , Escape ( snip. as_slice( ) ) ) ) ;
88
- }
89
- }
90
- last = next. sp . hi ;
66
+
67
+ let snip = |sp| sess. span_diagnostic . cm . span_to_snippet ( sp) . unwrap ( ) ;
68
+
91
69
if next. tok == t:: EOF { break }
92
70
93
71
let klass = match next. tok {
72
+ t:: WS => {
73
+ try!( write ! ( out, "{}" , Escape ( snip( next. sp) . as_slice( ) ) ) ) ;
74
+ continue
75
+ } ,
76
+ t:: COMMENT => {
77
+ try!( write ! ( out, "<span class='comment'>{}</span>" ,
78
+ Escape ( snip( next. sp) . as_slice( ) ) ) ) ;
79
+ continue
80
+ } ,
81
+ t:: SHEBANG ( s) => {
82
+ try!( write ! ( out, "{}" , Escape ( s. as_str( ) ) ) ) ;
83
+ continue
84
+ } ,
94
85
// If this '&' token is directly adjacent to another token, assume
95
86
// that it's the address-of operator instead of the and-operator.
96
87
// This allows us to give all pointers their own class (`Box` and
@@ -144,8 +135,7 @@ fn doit(sess: &parse::ParseSess, mut lexer: lexer::StringReader,
144
135
t:: LIT_CHAR ( ..) | t:: LIT_STR ( ..) | t:: LIT_STR_RAW ( ..) => "string" ,
145
136
146
137
// number literals
147
- t:: LIT_INT ( ..) | t:: LIT_UINT ( ..) | t:: LIT_INT_UNSUFFIXED ( ..) |
148
- t:: LIT_FLOAT ( ..) | t:: LIT_FLOAT_UNSUFFIXED ( ..) => "number" ,
138
+ t:: LIT_INTEGER ( ..) | t:: LIT_FLOAT ( ..) => "number" ,
149
139
150
140
// keywords are also included in the identifier set
151
141
t:: IDENT ( ident, _is_mod_sep) => {
0 commit comments