func parsePositionalValues()

in Sources/ArgumentParser/Parsing/ArgumentSet.swift [446:494]


  func parsePositionalValues(
    from unusedInput: SplitArguments,
    into result: inout ParsedValues
  ) throws {
    // Filter out the inputs that aren't "whole" arguments, like `-h` and `-i`
    // from the input `-hi`.
    var argumentStack = unusedInput.elements.filter {
      $0.index.subIndex == .complete
    }.map {
      (InputOrigin.Element.argumentIndex($0.index), $0)
    }[...]
    
    guard !argumentStack.isEmpty else { return }
    
    /// Pops arguments until reaching one that is a value (i.e., isn't dash-
    /// prefixed).
    func skipNonValues() {
      while argumentStack.first?.1.isValue == false {
        _ = argumentStack.popFirst()
      }
    }
    
    /// Pops the origin of the next argument to use.
    ///
    /// If `unconditional` is false, this skips over any non-"value" input.
    func next(unconditional: Bool) -> InputOrigin.Element? {
      if !unconditional {
        skipNonValues()
      }
      return argumentStack.popFirst()?.0
    }
    
    ArgumentLoop:
    for argumentDefinition in self {
      guard case .positional = argumentDefinition.kind else { continue }
      guard case let .unary(update) = argumentDefinition.update else {
        preconditionFailure("Shouldn't see a nullary positional argument.")
      }
      let allowOptionsAsInput = argumentDefinition.parsingStrategy == .allRemainingInput
      
      repeat {
        guard let origin = next(unconditional: allowOptionsAsInput) else {
          break ArgumentLoop
        }
        let value = unusedInput.originalInput(at: origin)!
        try update([origin], nil, value, &result)
      } while argumentDefinition.isRepeatingPositional
    }
  }