@@ -18,7 +18,6 @@ use std::io;
1818
1919use syntax:: parse;
2020use syntax:: parse:: lexer;
21- use syntax:: codemap:: { BytePos , Span } ;
2221
2322use html:: escape:: Escape ;
2423
@@ -59,38 +58,30 @@ fn doit(sess: &parse::ParseSess, mut lexer: lexer::StringReader,
5958 None => { }
6059 }
6160 try!( write ! ( out, "class='rust {}'>\n " , class. unwrap_or( "" ) ) ) ;
62- let mut last = BytePos ( 0 ) ;
6361 let mut is_attribute = false ;
6462 let mut is_macro = false ;
6563 let mut is_macro_nonterminal = false ;
6664 loop {
6765 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+
9169 if next. tok == t:: EOF { break }
9270
9371 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+ } ,
9485 // If this '&' token is directly adjacent to another token, assume
9586 // that it's the address-of operator instead of the and-operator.
9687 // 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,
144135 t:: LIT_CHAR ( ..) | t:: LIT_STR ( ..) | t:: LIT_STR_RAW ( ..) => "string" ,
145136
146137 // 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" ,
149139
150140 // keywords are also included in the identifier set
151141 t:: IDENT ( ident, _is_mod_sep) => {
0 commit comments