pub fn bare(src: &mut Input, span_offset: usize) -> (Spanned<String>, Option<ParseError>) {
    let mut bare = String::new();
    let start_offset = if let Some((pos, _)) = src.peek() {
        *pos
    } else {
        0
    };

    let mut inside_quote: Option<char> = None;
    let mut block_level: Vec<BlockKind> = vec![];

    while let Some((_, c)) = src.peek() {
        let c = *c;
        if inside_quote.is_some() {
            if Some(c) == inside_quote {
                inside_quote = None;
            }
        } else if c == '\'' || c == '"' || c == '`' {
            inside_quote = Some(c);
        } else if c == '[' {
            block_level.push(BlockKind::SquareBracket);
        } else if c == ']' {
            if let Some(BlockKind::SquareBracket) = block_level.last() {
                let _ = block_level.pop();
            }
        } else if c == '{' {
            block_level.push(BlockKind::CurlyBracket);
        } else if c == '}' {
            if let Some(BlockKind::CurlyBracket) = block_level.last() {
                let _ = block_level.pop();
            }
        } else if c == '(' {
            block_level.push(BlockKind::Paren);
        } else if c == ')' {
            if let Some(BlockKind::Paren) = block_level.last() {
                let _ = block_level.pop();
            }
        } else if block_level.is_empty() && (c.is_whitespace() || c == '|' || c == ';') {
            break;
        }
        bare.push(c);
        let _ = src.next();
    }

    let span = Span::new(
        start_offset + span_offset,
        start_offset + span_offset + bare.len(),
    );

    if let Some(block) = block_level.last() {
        let delim: char = (*block).into();
        let cause = ParseError::unexpected_eof(delim.to_string(), span);

        while let Some(bk) = block_level.pop() {
            bare.push(bk.into());
        }

        return (bare.spanned(span), Some(cause));
    }

    if let Some(delimiter) = inside_quote {
        // The non-lite parse trims quotes on both sides, so we add the expected quote so that
        // anyone wanting to consume this partial parse (e.g., completions) will be able to get
        // correct information from the non-lite parse.
        bare.push(delimiter);

        return (
            bare.spanned(span),
            Some(ParseError::unexpected_eof(delimiter.to_string(), span)),
        );
    }

    if bare.is_empty() {
        return (
            bare.spanned(span),
            Some(ParseError::unexpected_eof("command".to_string(), span)),
        );
    }

    (bare.spanned(span), None)
}
/// Finds the extents of a bare (un-classified) token, returning the string with its associated span,
/// along with any parse error that was discovered along the way.
/// Bare tokens are unparsed content separated by spaces or a command separator (like pipe or semicolon)
/// Bare tokens may be surrounded by quotes (single, double, or backtick) or braces (square, paren, curly)
Finds the extents of a bare (un-classified) token, returning the string with its associated span,
along with any parse error that was discovered along the way.
Bare tokens are unparsed content separated by spaces or a command separator (like pipe or semicolon)
Bare tokens may be surrounded by quotes (single, double, or backtick) or braces (square, paren, curly)
Finds the extents of a bare ( un - classified ) token returning the string with its associated span along with any parse error that was discovered along the way . Bare tokens are unparsed content separated by spaces or a command separator ( like pipe or semicolon ) Bare tokens may be surrounded by quotes ( single double or backtick ) or braces ( square paren curly )
pub fn bare(src: &mut Input, span_offset: usize) -> (Spanned<String>, Option<ParseError>) {
    let mut bare = String::new();
    let start_offset = if let Some((pos, _)) = src.peek() {
        *pos
    } else {
        0
    };
    let mut inside_quote: Option<char> = None;
    let mut block_level: Vec<BlockKind> = vec![];
    while let Some((_, c)) = src.peek() {
        let c = *c;
        if inside_quote.is_some() {
            if Some(c) == inside_quote {
                inside_quote = None;
            }
        } else if c == '\'' || c == '"' || c == '`' {
            inside_quote = Some(c);
        } else if c == '[' {
            block_level.push(BlockKind::SquareBracket);
        } else if c == ']' {
            if let Some(BlockKind::SquareBracket) = block_level.last() {
                let _ = block_level.pop();
            }
        } else if c == '{' {
            block_level.push(BlockKind::CurlyBracket);
        } else if c == '}' {
            if let Some(BlockKind::CurlyBracket) = block_level.last() {
                let _ = block_level.pop();
            }
        } else if c == '(' {
            block_level.push(BlockKind::Paren);
        } else if c == ')' {
            if let Some(BlockKind::Paren) = block_level.last() {
                let _ = block_level.pop();
            }
        } else if block_level.is_empty() && (c.is_whitespace() || c == '|' || c == ';') {
            break;
        }
        bare.push(c);
        let _ = src.next();
    }
    let span = Span::new(
        start_offset + span_offset,
        start_offset + span_offset + bare.len(),
    );
    if let Some(block) = block_level.last() {
        let delim: char = (*block).into();
        let cause = ParseError::unexpected_eof(delim.to_string(), span);
        while let Some(bk) = block_level.pop() {
            bare.push(bk.into());
        }
        return (bare.spanned(span), Some(cause));
    }
    if let Some(delimiter) = inside_quote {
        // The non-lite parse trims quotes on both sides, so we add the expected quote so that
        // anyone wanting to consume this partial parse (e.g., completions) will be able to get
        // correct information from the non-lite parse.
        bare.push(delimiter);
        return (
            bare.spanned(span),
            Some(ParseError::unexpected_eof(delimiter.to_string(), span)),
        );
    }
    if bare.is_empty() {
        return (
            bare.spanned(span),
            Some(ParseError::unexpected_eof("command".to_string(), span)),
        );
    }
    (bare.spanned(span), None)
}
pub fn bare ( src : & mut Input , span_offset : usize ) -> ( Spanned < String > , Option < ParseError > ) { let mut bare = String :: new ( ) ; let start_offset = if let Some ( ( pos , _ ) ) = src . peek ( ) { * pos } else { 0 } ; let mut inside_quote : Option < char > = None ; let mut block_level : Vec < BlockKind > = vec ! [ ] ; while let Some ( ( _ , c ) ) = src . peek ( ) { let c = * c ; if inside_quote . is_some ( ) { if Some ( c ) == inside_quote { inside_quote = None ; } } else if c == '\'' || c == '"' || c == '`' { inside_quote = Some ( c ) ; } else if c == '[' { block_level . push ( BlockKind :: SquareBracket ) ; } else if c == ']' { if let Some ( BlockKind :: SquareBracket ) = block_level . last ( ) { let _ = block_level . pop ( ) ; } } else if c == '{' { block_level . push ( BlockKind :: CurlyBracket ) ; } else if c == '}' { if let Some ( BlockKind :: CurlyBracket ) = block_level . last ( ) { let _ = block_level . pop ( ) ; } } else if c == '(' { block_level . push ( BlockKind :: Paren ) ; } else if c == ')' { if let Some ( BlockKind :: Paren ) = block_level . last ( ) { let _ = block_level . pop ( ) ; } } else if block_level . is_empty ( ) && ( c . is_whitespace ( ) || c == '|' || c == ';' ) { break ; } bare . push ( c ) ; let _ = src . next ( ) ; } let span = Span :: new ( start_offset + span_offset , start_offset + span_offset + bare . len ( ) , ) ; if let Some ( block ) = block_level . last ( ) { let delim : char = ( * block ) . into ( ) ; let cause = ParseError :: unexpected_eof ( delim . to_string ( ) , span ) ; while let Some ( bk ) = block_level . pop ( ) { bare . push ( bk . into ( ) ) ; } return ( bare . spanned ( span ) , Some ( cause ) ) ; } if let Some ( delimiter ) = inside_quote { // The non-lite parse trims quotes on both sides, so we add the expected quote so that // anyone wanting to consume this partial parse (e.g., completions) will be able to get // correct information from the non-lite parse. bare . push ( delimiter ) ; return ( bare . spanned ( span ) , Some ( ParseError :: unexpected_eof ( delimiter . to_string ( ) , span ) ) , ) ; } if bare . is_empty ( ) { return ( bare . spanned ( span ) , Some ( ParseError :: unexpected_eof ( " " . to_string ( ) , span ) ) , ) ; } ( bare . spanned ( span ) , None ) }
Finds the extents of a bare (un-classified) token, returning the string with its associated span,
along with any parse error that was discovered along the way.
Finds the extents of a bare ( un - classified ) token returning the string with its associated span along with any parse error that was discovered along the way .
src
&mut Input
span_offset
usize
src
&mut Input
span_offset
usize