fn parse_positional_argument(
    idx: usize,
    lite_cmd: &LiteCommand,
    positional_type: &PositionalType,
    remaining_positionals: usize,
    registry: &dyn SignatureRegistry,
) -> (usize, SpannedExpression, Option<ParseError>) {
    let mut idx = idx;
    let mut error = None;
    let arg = match positional_type {
        PositionalType::Mandatory(_, SyntaxShape::Math)
        | PositionalType::Optional(_, SyntaxShape::Math) => {
            // A condition can take up multiple arguments, as we build the operation as <arg> <operator> <arg>
            // We need to do this here because in parse_arg, we have access to only one arg at a time

            if idx < lite_cmd.parts.len() {
                if lite_cmd.parts[idx].item.starts_with('{') {
                    // It's an explicit math expression, so parse it deeper in
                    let (arg, err) = parse_arg(SyntaxShape::Math, registry, &lite_cmd.parts[idx]);
                    if error.is_none() {
                        error = err;
                    }
                    arg
                } else {
                    let end_idx = if (lite_cmd.parts.len() - 1) > remaining_positionals {
                        lite_cmd.parts.len() - remaining_positionals
                    } else {
                        lite_cmd.parts.len()
                    };

                    let (new_idx, arg, err) =
                        parse_math_expression(idx, &lite_cmd.parts[idx..end_idx], registry, true);

                    let span = arg.span;
                    let mut commands = hir::Commands::new(span);
                    commands.push(ClassifiedCommand::Expr(Box::new(arg)));

                    let block = hir::Block::new(vec![], vec![commands], span);

                    let arg = SpannedExpression::new(Expression::Block(block), span);

                    idx = new_idx - 1;
                    if error.is_none() {
                        error = err;
                    }
                    arg
                }
            } else {
                if error.is_none() {
                    error = Some(ParseError::argument_error(
                        lite_cmd.parts[0].clone(),
                        ArgumentError::MissingMandatoryPositional("condition".into()),
                    ))
                }
                garbage(lite_cmd.span())
            }
        }
        PositionalType::Mandatory(_, shape) | PositionalType::Optional(_, shape) => {
            let (arg, err) = parse_arg(*shape, registry, &lite_cmd.parts[idx]);
            if error.is_none() {
                error = err;
            }
            arg
        }
    };

    (idx, arg, error)
}
/// Handles parsing the positional arguments as a batch
/// This allows us to check for times where multiple arguments are treated as one shape, as is the case with SyntaxShape::Math
Handles parsing the positional arguments as a batch
This allows us to check for times where multiple arguments are treated as one shape, as is the case with SyntaxShape::Math
Handles parsing the positional arguments as a batch This allows us to check for times where multiple arguments are treated as one shape as is the case with SyntaxShape :: Math
fn parse_positional_argument(
    idx: usize,
    lite_cmd: &LiteCommand,
    positional_type: &PositionalType,
    remaining_positionals: usize,
    registry: &dyn SignatureRegistry,
) -> (usize, SpannedExpression, Option<ParseError>) {
    let mut idx = idx;
    let mut error = None;
    let arg = match positional_type {
        PositionalType::Mandatory(_, SyntaxShape::Math)
        | PositionalType::Optional(_, SyntaxShape::Math) => {
            // A condition can take up multiple arguments, as we build the operation as <arg> <operator> <arg>
            // We need to do this here because in parse_arg, we have access to only one arg at a time
            if idx < lite_cmd.parts.len() {
                if lite_cmd.parts[idx].item.starts_with('{') {
                    // It's an explicit math expression, so parse it deeper in
                    let (arg, err) = parse_arg(SyntaxShape::Math, registry, &lite_cmd.parts[idx]);
                    if error.is_none() {
                        error = err;
                    }
                    arg
                } else {
                    let end_idx = if (lite_cmd.parts.len() - 1) > remaining_positionals {
                        lite_cmd.parts.len() - remaining_positionals
                    } else {
                        lite_cmd.parts.len()
                    };
                    let (new_idx, arg, err) =
                        parse_math_expression(idx, &lite_cmd.parts[idx..end_idx], registry, true);
                    let span = arg.span;
                    let mut commands = hir::Commands::new(span);
                    commands.push(ClassifiedCommand::Expr(Box::new(arg)));
                    let block = hir::Block::new(vec![], vec![commands], span);
                    let arg = SpannedExpression::new(Expression::Block(block), span);
                    idx = new_idx - 1;
                    if error.is_none() {
                        error = err;
                    }
                    arg
                }
            } else {
                if error.is_none() {
                    error = Some(ParseError::argument_error(
                        lite_cmd.parts[0].clone(),
                        ArgumentError::MissingMandatoryPositional("condition".into()),
                    ))
                }
                garbage(lite_cmd.span())
            }
        }
        PositionalType::Mandatory(_, shape) | PositionalType::Optional(_, shape) => {
            let (arg, err) = parse_arg(*shape, registry, &lite_cmd.parts[idx]);
            if error.is_none() {
                error = err;
            }
            arg
        }
    };
    (idx, arg, error)
}
fn parse_positional_argument ( idx : usize , lite_cmd : & LiteCommand , positional_type : & PositionalType , remaining_positionals : usize , registry : & dyn SignatureRegistry , ) -> ( usize , SpannedExpression , Option < ParseError > ) { let mut idx = idx ; let mut error = None ; let arg = match positional_type { PositionalType :: Mandatory ( _ , SyntaxShape :: Math ) | PositionalType :: Optional ( _ , SyntaxShape :: Math ) => { // A condition can take up multiple arguments, as we build the operation as <arg> <operator> <arg> // We need to do this here because in parse_arg, we have access to only one arg at a time if idx < lite_cmd . parts . len ( ) { if lite_cmd . parts [ idx ] . item . starts_with ( '{' ) { // It's an explicit math expression, so parse it deeper in let ( arg , err ) = parse_arg ( SyntaxShape :: Math , registry , & lite_cmd . parts [ idx ] ) ; if error . is_none ( ) { error = err ; } arg } else { let end_idx = if ( lite_cmd . parts . len ( ) - 1 ) > remaining_positionals { lite_cmd . parts . len ( ) - remaining_positionals } else { lite_cmd . parts . len ( ) } ; let ( new_idx , arg , err ) = parse_math_expression ( idx , & lite_cmd . parts [ idx .. end_idx ] , registry , true ) ; let span = arg . span ; let mut commands = hir :: Commands :: new ( span ) ; commands . push ( ClassifiedCommand :: Expr ( Box :: new ( arg ) ) ) ; let block = hir :: Block :: new ( vec ! [ ] , vec ! [ commands ] , span ) ; let arg = SpannedExpression :: new ( Expression :: Block ( block ) , span ) ; idx = new_idx - 1 ; if error . is_none ( ) { error = err ; } arg } } else { if error . is_none ( ) { error = Some ( ParseError :: argument_error ( lite_cmd . parts [ 0 ] . clone ( ) , ArgumentError :: MissingMandatoryPositional ( " " . into ( ) ) , ) ) } garbage ( lite_cmd . span ( ) ) } } PositionalType :: Mandatory ( _ , shape ) | PositionalType :: Optional ( _ , shape ) => { let ( arg , err ) = parse_arg ( * shape , registry , & lite_cmd . parts [ idx ] ) ; if error . is_none ( ) { error = err ; } arg } } ; ( idx , arg , error ) }
Handles parsing the positional arguments as a batch
This allows us to check for times where multiple arguments are treated as one shape, as is the case with SyntaxShape::Math
Handles parsing the positional arguments as a batch This allows us to check for times where multiple arguments are treated as one shape as is the case with SyntaxShape :: Math
idx
usize
lite_cmd
&LiteCommand
positional_type
&PositionalType
remaining_positionals
usize
registry
&dyn SignatureRegistry
idx
usize
lite_cmd
&LiteCommand
positional_type
&PositionalType
remaining_positionals
usize
registry
&dyn SignatureRegistry