- #[allow(cast_possible_truncation)]
- fn word_span(mut span: Span, begin: usize, end: usize) -> Span {
- debug_assert_eq!(end as u32 as usize, end);
- debug_assert_eq!(begin as u32 as usize, begin);
- span.hi = span.lo + BytePos(end as u32);
- span.lo = span.lo + BytePos(begin as u32);
- span
- }
-
- let mut new_line = true;
- let len = doc.len();
- let mut chars = doc.char_indices().peekable();
- let mut current_word_begin = 0;
- loop {
- match chars.next() {
- Some((_, c)) => {
- match c {
- '#' if new_line => { // don’t warn on titles
- current_word_begin = jump_to!(chars, '\n', len);
- }
- '`' => {
- current_word_begin = jump_to!(chars, '`', len);
- }
- '[' => {
- let end = jump_to!(chars, ']', len);
- let link_text = &doc[current_word_begin + 1..end];
- let word_span = word_span(span, current_word_begin + 1, end + 1);
-
- match chars.peek() {
- Some(&(_, c)) => {
- // Trying to parse a link. Let’s ignore the link.
-
- // FIXME: how does markdown handles such link?
- // https://en.wikipedia.org/w/index.php?title=)
- match c {
- '(' => { // inline link
- current_word_begin = jump_to!(chars, ')', len);
- check_doc(cx, valid_idents, link_text, word_span);
- }
- '[' => { // reference link
- current_word_begin = jump_to!(chars, ']', len);
- check_doc(cx, valid_idents, link_text, word_span);
- }
- ':' => { // reference link
- current_word_begin = jump_to!(chars, '\n', len);
- }
- _ => { // automatic reference link
- current_word_begin = jump_to!(@next_char, chars, len);
- check_doc(cx, valid_idents, link_text, word_span);
- }
- }
- }
- None => return,
- }
- }
- // anything that’s neither alphanumeric nor '_' is not part of an ident anyway
- c if !c.is_alphanumeric() && c != '_' => {
- current_word_begin = jump_to!(@next_char, chars, len);
- }
- _ => {
- let end = match chars.find(|&(_, c)| !is_word_char(c)) {
- Some((end, _)) => end,
- None => len,
- };
- let word_span = word_span(span, current_word_begin, end);
- check_word(cx, valid_idents, &doc[current_word_begin..end], word_span);
- current_word_begin = jump_to!(@next_char, chars, len);
- }
- }