Lines Matching refs:input

79 fn skip_whitespace(input: Cursor) -> Cursor {  in skip_whitespace()
80 let mut s = input; in skip_whitespace()
127 fn block_comment(input: Cursor) -> PResult<&str> { in block_comment()
128 if !input.starts_with("/*") { in block_comment()
133 let bytes = input.as_bytes(); in block_comment()
144 return Ok((input.advance(i + 2), &input.rest[..i + 2])); in block_comment()
159 fn word_break(input: Cursor) -> Result<Cursor, Reject> { in word_break()
160 match input.chars().next() { in word_break()
162 Some(_) | None => Ok(input), in word_break()
170 pub(crate) fn token_stream(mut input: Cursor) -> Result<TokenStream, LexError> { in token_stream()
175 input = skip_whitespace(input); in token_stream()
177 if let Ok((rest, ())) = doc_comment(input, &mut trees) { in token_stream()
178 input = rest; in token_stream()
183 let lo = input.off; in token_stream()
185 let first = match input.bytes().next() { in token_stream()
201 b'(' if !input.starts_with(ERROR) => Some(Delimiter::Parenthesis), in token_stream()
206 input = input.advance(1); in token_stream()
220 None => return Err(lex_error(input)), in token_stream()
226 return Err(lex_error(input)); in token_stream()
228 input = input.advance(1); in token_stream()
234 hi: input.off, in token_stream()
239 let (rest, mut tt) = match leaf_token(input) { in token_stream()
241 Err(Reject) => return Err(lex_error(input)), in token_stream()
250 input = rest; in token_stream()
268 fn leaf_token(input: Cursor) -> PResult<TokenTree> { in leaf_token()
269 if let Ok((input, l)) = literal(input) { in leaf_token()
271 Ok((input, TokenTree::Literal(crate::Literal::_new_fallback(l)))) in leaf_token()
272 } else if let Ok((input, p)) = punct(input) { in leaf_token()
273 Ok((input, TokenTree::Punct(p))) in leaf_token()
274 } else if let Ok((input, i)) = ident(input) { in leaf_token()
275 Ok((input, TokenTree::Ident(i))) in leaf_token()
276 } else if input.starts_with(ERROR) { in leaf_token()
277 let rest = input.advance(ERROR.len()); in leaf_token()
285 fn ident(input: Cursor) -> PResult<crate::Ident> { in ident()
290 .any(|prefix| input.starts_with(prefix)) in ident()
294 ident_any(input) in ident()
298 fn ident_any(input: Cursor) -> PResult<crate::Ident> { in ident_any()
299 let raw = input.starts_with("r#"); in ident_any()
300 let rest = input.advance((raw as usize) << 1); in ident_any()
320 fn ident_not_raw(input: Cursor) -> PResult<&str> { in ident_not_raw()
321 let mut chars = input.char_indices(); in ident_not_raw()
328 let mut end = input.len(); in ident_not_raw()
336 Ok((input.advance(end), &input.rest[..end])) in ident_not_raw()
339 pub(crate) fn literal(input: Cursor) -> PResult<Literal> { in literal()
340 let rest = literal_nocapture(input)?; in literal()
341 let end = input.len() - rest.len(); in literal()
342 Ok((rest, Literal::_new(input.rest[..end].to_string()))) in literal()
345 fn literal_nocapture(input: Cursor) -> Result<Cursor, Reject> { in literal_nocapture()
346 if let Ok(ok) = string(input) { in literal_nocapture()
348 } else if let Ok(ok) = byte_string(input) { in literal_nocapture()
350 } else if let Ok(ok) = c_string(input) { in literal_nocapture()
352 } else if let Ok(ok) = byte(input) { in literal_nocapture()
354 } else if let Ok(ok) = character(input) { in literal_nocapture()
356 } else if let Ok(ok) = float(input) { in literal_nocapture()
358 } else if let Ok(ok) = int(input) { in literal_nocapture()
365 fn literal_suffix(input: Cursor) -> Cursor { in literal_suffix()
366 match ident_not_raw(input) { in literal_suffix()
367 Ok((input, _)) => input, in literal_suffix()
368 Err(Reject) => input, in literal_suffix()
372 fn string(input: Cursor) -> Result<Cursor, Reject> { in string()
373 if let Ok(input) = input.parse("\"") { in string()
374 cooked_string(input) in string()
375 } else if let Ok(input) = input.parse("r") { in string()
376 raw_string(input) in string()
382 fn cooked_string(mut input: Cursor) -> Result<Cursor, Reject> { in cooked_string()
383 let mut chars = input.char_indices(); in cooked_string()
388 let input = input.advance(i + 1); in cooked_string() localVariable
389 return Ok(literal_suffix(input)); in cooked_string()
404 input = input.advance(newline + 1); in cooked_string()
405 trailing_backslash(&mut input, ch as u8)?; in cooked_string()
406 chars = input.char_indices(); in cooked_string()
416 fn raw_string(input: Cursor) -> Result<Cursor, Reject> { in raw_string()
417 let (input, delimiter) = delimiter_of_raw_string(input)?; in raw_string()
418 let mut bytes = input.bytes().enumerate(); in raw_string()
421 b'"' if input.rest[i + 1..].starts_with(delimiter) => { in raw_string()
422 let rest = input.advance(i + 1 + delimiter.len()); in raw_string()
435 fn byte_string(input: Cursor) -> Result<Cursor, Reject> { in byte_string()
436 if let Ok(input) = input.parse("b\"") { in byte_string()
437 cooked_byte_string(input) in byte_string()
438 } else if let Ok(input) = input.parse("br") { in byte_string()
439 raw_byte_string(input) in byte_string()
445 fn cooked_byte_string(mut input: Cursor) -> Result<Cursor, Reject> { in cooked_byte_string()
446 let mut bytes = input.bytes().enumerate(); in cooked_byte_string()
450 let input = input.advance(offset + 1); in cooked_byte_string() localVariable
451 return Ok(literal_suffix(input)); in cooked_byte_string()
463 input = input.advance(newline + 1); in cooked_byte_string()
464 trailing_backslash(&mut input, b)?; in cooked_byte_string()
465 bytes = input.bytes().enumerate(); in cooked_byte_string()
476 fn delimiter_of_raw_string(input: Cursor) -> PResult<&str> { in delimiter_of_raw_string()
477 for (i, byte) in input.bytes().enumerate() { in delimiter_of_raw_string()
484 return Ok((input.advance(i + 1), &input.rest[..i])); in delimiter_of_raw_string()
493 fn raw_byte_string(input: Cursor) -> Result<Cursor, Reject> { in raw_byte_string()
494 let (input, delimiter) = delimiter_of_raw_string(input)?; in raw_byte_string()
495 let mut bytes = input.bytes().enumerate(); in raw_byte_string()
498 b'"' if input.rest[i + 1..].starts_with(delimiter) => { in raw_byte_string()
499 let rest = input.advance(i + 1 + delimiter.len()); in raw_byte_string()
516 fn c_string(input: Cursor) -> Result<Cursor, Reject> { in c_string()
517 if let Ok(input) = input.parse("c\"") { in c_string()
518 cooked_c_string(input) in c_string()
519 } else if let Ok(input) = input.parse("cr") { in c_string()
520 raw_c_string(input) in c_string()
526 fn raw_c_string(input: Cursor) -> Result<Cursor, Reject> { in raw_c_string()
527 let (input, delimiter) = delimiter_of_raw_string(input)?; in raw_c_string()
528 let mut bytes = input.bytes().enumerate(); in raw_c_string()
531 b'"' if input.rest[i + 1..].starts_with(delimiter) => { in raw_c_string()
532 let rest = input.advance(i + 1 + delimiter.len()); in raw_c_string()
546 fn cooked_c_string(mut input: Cursor) -> Result<Cursor, Reject> { in cooked_c_string()
547 let mut chars = input.char_indices(); in cooked_c_string()
552 let input = input.advance(i + 1); in cooked_c_string() localVariable
553 return Ok(literal_suffix(input)); in cooked_c_string()
570 input = input.advance(newline + 1); in cooked_c_string()
571 trailing_backslash(&mut input, ch as u8)?; in cooked_c_string()
572 chars = input.char_indices(); in cooked_c_string()
583 fn byte(input: Cursor) -> Result<Cursor, Reject> { in byte()
584 let input = input.parse("b'")?; in byte() localVariable
585 let mut bytes = input.bytes().enumerate(); in byte()
598 if !input.chars().as_str().is_char_boundary(offset) { in byte()
601 let input = input.advance(offset).parse("'")?; in byte() localVariable
602 Ok(literal_suffix(input)) in byte()
605 fn character(input: Cursor) -> Result<Cursor, Reject> { in character()
606 let input = input.parse("'")?; in character() localVariable
607 let mut chars = input.char_indices(); in character()
621 let input = input.advance(idx).parse("'")?; in character() localVariable
622 Ok(literal_suffix(input)) in character()
694 fn trailing_backslash(input: &mut Cursor, mut last: u8) -> Result<(), Reject> { in trailing_backslash()
695 let mut whitespace = input.bytes().enumerate(); in trailing_backslash()
705 *input = input.advance(offset); in trailing_backslash()
713 fn float(input: Cursor) -> Result<Cursor, Reject> { in float()
714 let mut rest = float_digits(input)?; in float()
723 fn float_digits(input: Cursor) -> Result<Cursor, Reject> { in float_digits()
724 let mut chars = input.chars().peekable(); in float_digits()
769 Ok(input.advance(len - 1)) in float_digits()
805 Ok(input.advance(len)) in float_digits()
808 fn int(input: Cursor) -> Result<Cursor, Reject> { in int()
809 let mut rest = digits(input)?; in int()
818 fn digits(mut input: Cursor) -> Result<Cursor, Reject> { in digits()
819 let base = if input.starts_with("0x") { in digits()
820 input = input.advance(2); in digits()
822 } else if input.starts_with("0o") { in digits()
823 input = input.advance(2); in digits()
825 } else if input.starts_with("0b") { in digits()
826 input = input.advance(2); in digits()
834 for b in input.bytes() { in digits()
869 Ok(input.advance(len)) in digits()
873 fn punct(input: Cursor) -> PResult<Punct> { in punct()
874 let (rest, ch) = punct_char(input)?; in punct()
893 fn punct_char(input: Cursor) -> PResult<char> { in punct_char()
894 if input.starts_with("//") || input.starts_with("/*") { in punct_char()
899 let mut chars = input.chars(); in punct_char()
908 Ok((input.advance(first.len_utf8()), first)) in punct_char()
914 fn doc_comment<'a>(input: Cursor<'a>, trees: &mut TokenStreamBuilder) -> PResult<'a, ()> { in doc_comment()
916 let lo = input.off; in doc_comment()
917 let (rest, (comment, inner)) = doc_comment_contents(input)?; in doc_comment()
962 fn doc_comment_contents(input: Cursor) -> PResult<(&str, bool)> { in doc_comment_contents()
963 if input.starts_with("//!") { in doc_comment_contents()
964 let input = input.advance(3); in doc_comment_contents() localVariable
965 let (input, s) = take_until_newline_or_eof(input); in doc_comment_contents()
966 Ok((input, (s, true))) in doc_comment_contents()
967 } else if input.starts_with("/*!") { in doc_comment_contents()
968 let (input, s) = block_comment(input)?; in doc_comment_contents()
969 Ok((input, (&s[3..s.len() - 2], true))) in doc_comment_contents()
970 } else if input.starts_with("///") { in doc_comment_contents()
971 let input = input.advance(3); in doc_comment_contents() localVariable
972 if input.starts_with_char('/') { in doc_comment_contents()
975 let (input, s) = take_until_newline_or_eof(input); in doc_comment_contents()
976 Ok((input, (s, false))) in doc_comment_contents()
977 } else if input.starts_with("/**") && !input.rest[3..].starts_with('*') { in doc_comment_contents()
978 let (input, s) = block_comment(input)?; in doc_comment_contents()
979 Ok((input, (&s[3..s.len() - 2], false))) in doc_comment_contents()
985 fn take_until_newline_or_eof(input: Cursor) -> (Cursor, &str) { in take_until_newline_or_eof()
986 let chars = input.char_indices(); in take_until_newline_or_eof()
990 return (input.advance(i), &input.rest[..i]); in take_until_newline_or_eof()
991 } else if ch == '\r' && input.rest[i + 1..].starts_with('\n') { in take_until_newline_or_eof()
992 return (input.advance(i + 1), &input.rest[..i]); in take_until_newline_or_eof()
996 (input.advance(input.len()), input.rest) in take_until_newline_or_eof()