Lines Matching refs:input
65 fn skip_whitespace(input: Cursor) -> Cursor { in skip_whitespace()
66 let mut s = input; in skip_whitespace()
113 fn block_comment(input: Cursor) -> PResult<&str> { in block_comment()
114 if !input.starts_with("/*") { in block_comment()
119 let bytes = input.as_bytes(); in block_comment()
130 return Ok((input.advance(i + 2), &input.rest[..i + 2])); in block_comment()
145 fn word_break(input: Cursor) -> Result<Cursor, Reject> { in word_break()
146 match input.chars().next() { in word_break()
148 Some(_) | None => Ok(input), in word_break()
152 pub(crate) fn token_stream(mut input: Cursor) -> Result<TokenStream, LexError> { in token_stream()
157 input = skip_whitespace(input); in token_stream()
159 if let Ok((rest, tt)) = doc_comment(input) { in token_stream()
161 input = rest; in token_stream()
166 let lo = input.off; in token_stream()
168 let first = match input.bytes().next() { in token_stream()
189 input = input.advance(1); in token_stream()
203 None => return Err(lex_error(input)), in token_stream()
209 return Err(lex_error(input)); in token_stream()
211 input = input.advance(1); in token_stream()
217 hi: input.off, in token_stream()
222 let (rest, mut tt) = match leaf_token(input) { in token_stream()
224 Err(Reject) => return Err(lex_error(input)), in token_stream()
233 input = rest; in token_stream()
251 fn leaf_token(input: Cursor) -> PResult<TokenTree> { in leaf_token()
252 if let Ok((input, l)) = literal(input) { in leaf_token()
254 Ok((input, TokenTree::Literal(crate::Literal::_new_stable(l)))) in leaf_token()
255 } else if let Ok((input, p)) = punct(input) { in leaf_token()
256 Ok((input, TokenTree::Punct(p))) in leaf_token()
257 } else if let Ok((input, i)) = ident(input) { in leaf_token()
258 Ok((input, TokenTree::Ident(i))) in leaf_token()
264 fn ident(input: Cursor) -> PResult<crate::Ident> { in ident()
267 .any(|prefix| input.starts_with(prefix)) in ident()
271 ident_any(input) in ident()
275 fn ident_any(input: Cursor) -> PResult<crate::Ident> { in ident_any()
276 let raw = input.starts_with("r#"); in ident_any()
277 let rest = input.advance((raw as usize) << 1); in ident_any()
294 fn ident_not_raw(input: Cursor) -> PResult<&str> { in ident_not_raw()
295 let mut chars = input.char_indices(); in ident_not_raw()
302 let mut end = input.len(); in ident_not_raw()
310 Ok((input.advance(end), &input.rest[..end])) in ident_not_raw()
313 pub(crate) fn literal(input: Cursor) -> PResult<Literal> { in literal()
314 let rest = literal_nocapture(input)?; in literal()
315 let end = input.len() - rest.len(); in literal()
316 Ok((rest, Literal::_new(input.rest[..end].to_string()))) in literal()
319 fn literal_nocapture(input: Cursor) -> Result<Cursor, Reject> { in literal_nocapture()
320 if let Ok(ok) = string(input) { in literal_nocapture()
322 } else if let Ok(ok) = byte_string(input) { in literal_nocapture()
324 } else if let Ok(ok) = byte(input) { in literal_nocapture()
326 } else if let Ok(ok) = character(input) { in literal_nocapture()
328 } else if let Ok(ok) = float(input) { in literal_nocapture()
330 } else if let Ok(ok) = int(input) { in literal_nocapture()
337 fn literal_suffix(input: Cursor) -> Cursor { in literal_suffix()
338 match ident_not_raw(input) { in literal_suffix()
339 Ok((input, _)) => input, in literal_suffix()
340 Err(Reject) => input, in literal_suffix()
344 fn string(input: Cursor) -> Result<Cursor, Reject> { in string()
345 if let Ok(input) = input.parse("\"") { in string()
346 cooked_string(input) in string()
347 } else if let Ok(input) = input.parse("r") { in string()
348 raw_string(input) in string()
354 fn cooked_string(input: Cursor) -> Result<Cursor, Reject> { in cooked_string()
355 let mut chars = input.char_indices().peekable(); in cooked_string()
360 let input = input.advance(i + 1); in cooked_string() localVariable
361 return Ok(literal_suffix(input)); in cooked_string()
403 fn byte_string(input: Cursor) -> Result<Cursor, Reject> { in byte_string()
404 if let Ok(input) = input.parse("b\"") { in byte_string()
405 cooked_byte_string(input) in byte_string()
406 } else if let Ok(input) = input.parse("br") { in byte_string()
407 raw_string(input) in byte_string()
413 fn cooked_byte_string(mut input: Cursor) -> Result<Cursor, Reject> { in cooked_byte_string()
414 let mut bytes = input.bytes().enumerate(); in cooked_byte_string()
418 let input = input.advance(offset + 1); in cooked_byte_string() localVariable
419 return Ok(literal_suffix(input)); in cooked_byte_string()
435 let rest = input.advance(newline + 1); in cooked_byte_string()
444 input = rest.advance(offset); in cooked_byte_string()
445 bytes = input.bytes().enumerate(); in cooked_byte_string()
461 fn raw_string(input: Cursor) -> Result<Cursor, Reject> { in raw_string()
462 let mut chars = input.char_indices(); in raw_string()
476 '"' if input.rest[i + 1..].starts_with(&input.rest[..n]) => { in raw_string()
477 let rest = input.advance(i + 1 + n); in raw_string()
490 fn byte(input: Cursor) -> Result<Cursor, Reject> { in byte()
491 let input = input.parse("b'")?; in byte() localVariable
492 let mut bytes = input.bytes().enumerate(); in byte()
506 if !input.chars().as_str().is_char_boundary(offset) { in byte()
509 let input = input.advance(offset).parse("'")?; in byte() localVariable
510 Ok(literal_suffix(input)) in byte()
513 fn character(input: Cursor) -> Result<Cursor, Reject> { in character()
514 let input = input.parse("'")?; in character() localVariable
515 let mut chars = input.char_indices(); in character()
531 let input = input.advance(idx).parse("'")?; in character() localVariable
532 Ok(literal_suffix(input)) in character()
591 fn float(input: Cursor) -> Result<Cursor, Reject> { in float()
592 let mut rest = float_digits(input)?; in float()
601 fn float_digits(input: Cursor) -> Result<Cursor, Reject> { in float_digits()
602 let mut chars = input.chars().peekable(); in float_digits()
647 Ok(input.advance(len - 1)) in float_digits()
683 Ok(input.advance(len)) in float_digits()
686 fn int(input: Cursor) -> Result<Cursor, Reject> { in int()
687 let mut rest = digits(input)?; in int()
696 fn digits(mut input: Cursor) -> Result<Cursor, Reject> { in digits()
697 let base = if input.starts_with("0x") { in digits()
698 input = input.advance(2); in digits()
700 } else if input.starts_with("0o") { in digits()
701 input = input.advance(2); in digits()
703 } else if input.starts_with("0b") { in digits()
704 input = input.advance(2); in digits()
712 for b in input.bytes() { in digits()
747 Ok(input.advance(len)) in digits()
751 fn punct(input: Cursor) -> PResult<Punct> { in punct()
752 let (rest, ch) = punct_char(input)?; in punct()
768 fn punct_char(input: Cursor) -> PResult<char> { in punct_char()
769 if input.starts_with("//") || input.starts_with("/*") { in punct_char()
774 let mut chars = input.chars(); in punct_char()
783 Ok((input.advance(first.len_utf8()), first)) in punct_char()
789 fn doc_comment(input: Cursor) -> PResult<Vec<TokenTree>> { in doc_comment()
791 let lo = input.off; in doc_comment()
792 let (rest, (comment, inner)) = doc_comment_contents(input)?; in doc_comment()
830 fn doc_comment_contents(input: Cursor) -> PResult<(&str, bool)> { in doc_comment_contents()
831 if input.starts_with("//!") { in doc_comment_contents()
832 let input = input.advance(3); in doc_comment_contents() localVariable
833 let (input, s) = take_until_newline_or_eof(input); in doc_comment_contents()
834 Ok((input, (s, true))) in doc_comment_contents()
835 } else if input.starts_with("/*!") { in doc_comment_contents()
836 let (input, s) = block_comment(input)?; in doc_comment_contents()
837 Ok((input, (&s[3..s.len() - 2], true))) in doc_comment_contents()
838 } else if input.starts_with("///") { in doc_comment_contents()
839 let input = input.advance(3); in doc_comment_contents() localVariable
840 if input.starts_with("/") { in doc_comment_contents()
843 let (input, s) = take_until_newline_or_eof(input); in doc_comment_contents()
844 Ok((input, (s, false))) in doc_comment_contents()
845 } else if input.starts_with("/**") && !input.rest[3..].starts_with('*') { in doc_comment_contents()
846 let (input, s) = block_comment(input)?; in doc_comment_contents()
847 Ok((input, (&s[3..s.len() - 2], false))) in doc_comment_contents()
853 fn take_until_newline_or_eof(input: Cursor) -> (Cursor, &str) { in take_until_newline_or_eof()
854 let chars = input.char_indices(); in take_until_newline_or_eof()
858 return (input.advance(i), &input.rest[..i]); in take_until_newline_or_eof()
859 } else if ch == '\r' && input.rest[i + 1..].starts_with('\n') { in take_until_newline_or_eof()
860 return (input.advance(i + 1), &input.rest[..i]); in take_until_newline_or_eof()
864 (input.advance(input.len()), input.rest) in take_until_newline_or_eof()