Skip to content

Commit f1cea3c

Browse files
author
Margaret Meyerhofer
committed
Changed the lexer to accept #! comments on the first line.
1 parent 248e439 commit f1cea3c

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/librustsyntax/codemap.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export new_filemap;
1212
export new_filemap_w_substr;
1313
export mk_substr_filename;
1414
export lookup_char_pos;
15+
export lookup_char_pos_adj;
1516
export adjust_span;
1617
export span_to_str;
1718
export span_to_filename;

src/librustsyntax/parse/lexer.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,17 @@ fn consume_any_line_comment(rdr: reader) {
119119
'*' { rdr.bump(); rdr.bump(); ret consume_block_comment(rdr); }
120120
_ { ret; }
121121
}
122+
} else if rdr.curr == '#' {
123+
if rdr.next() == '!' {
124+
let cmap = codemap::new_codemap();
125+
(*cmap).files.push(rdr.filemap);
126+
let mut loc = codemap::lookup_char_pos_adj(cmap, rdr.chpos);
127+
if loc.line == 1u && loc.col == 0u {
128+
while rdr.curr != '\n' && !rdr.is_eof() { rdr.bump(); }
129+
loc = codemap::lookup_char_pos_adj(cmap, rdr.chpos);
130+
ret consume_whitespace_and_comments(rdr);
131+
}
132+
}
122133
}
123134
}
124135

0 commit comments

Comments
 (0)