<commit_before>/* NSC -- new Scala compiler
 * Copyright 2005-2011 LAMP/EPFL
 * @author  <NAME>
 */
// $Id$

package scala.tools
package nsc
package settings

import io.{ AbstractFile, Path, PlainFile, VirtualDirectory }
import scala.tools.util.StringOps
import scala.collection.mutable.ListBuffer
import scala.io.Source

/** A mutable Settings object.
 */
class MutableSettings(val errorFn: String => Unit)
              extends scala.reflect.internal.settings.MutableSettings
                 with AbsSettings
                 with ScalaSettings
                 with Mutable {
  type ResultOfTryToSet = List[String]

  /** Iterates over the arguments applying them to settings where applicable.
   *  Then verifies setting dependencies are met.
   *
   *  This temporarily takes a boolean indicating whether to keep
   *  processing if an argument is seen which is not a command line option.
   *  This is an expedience for the moment so that you can say
   *
   *    scalac -d /tmp foo.scala -optimise
   *
   *  while also allowing
   *
   *    scala Program opt opt
   *
   *  to get their arguments.
   *
   *  Returns (success, List of unprocessed arguments)
   */
  def processArguments(arguments: List[String], processAll: Boolean): (Boolean, List[String]) = {
    def loop(args: List[String], residualArgs: List[String]): (Boolean, List[String]) = args match {
      case Nil        =>
        (checkDependencies, residualArgs)
      case "--" :: xs =>
        (checkDependencies, xs)
      case x :: xs  =>
        val isOpt = x startsWith "-"
        if (isOpt) {
          val newArgs = parseParams(args)
          if (args eq newArgs) {
            errorFn("bad option: '" + x + "'")
            (false, args)
          }
          else lookupSetting(x) match {
            case Some(s) if s.shouldStopProcessing  => (checkDependencies, newArgs)
            case _                                  => loop(newArgs, residualArgs)
          }
        }
        else {
          if (processAll) loop(xs, residualArgs :+ x)
          else (checkDependencies, args)
        }
    }
    loop(arguments filterNot (_ == ""), Nil)
  }
  def processArgumentString(params: String) = processArguments(splitParams(params), true)

  /** Create a new Settings object, copying all user-set values.
   */
  def copy(): Settings = {
    val s = new Settings()
    val xs = userSetSettings flatMap (_.unparse)
    s.processArguments(xs.toList, true)
    s
  }

  /** A list pairing source directories with their output directory.
   *  This option is not available on the command line, but can be set by<commit_msg>Discard empty strings in option position, but n...<commit_after>/* NSC -- new Scala compiler
 * Copyright 2005-2011 LAMP/EPFL
 * @author  <NAME>
 */
// $Id$

package scala.tools
package nsc
package settings

import io.{ AbstractFile, Path, PlainFile, VirtualDirectory }
import scala.tools.util.StringOps
import scala.collection.mutable.ListBuffer
import scala.io.Source

/** A mutable Settings object.
 */
class MutableSettings(val errorFn: String => Unit)
              extends scala.reflect.internal.settings.MutableSettings
                 with AbsSettings
                 with ScalaSettings
                 with Mutable {
  type ResultOfTryToSet = List[String]

  /** Iterates over the arguments applying them to settings where applicable.
   *  Then verifies setting dependencies are met.
   *
   *  This temporarily takes a boolean indicating whether to keep
   *  processing if an argument is seen which is not a command line option.
   *  This is an expedience for the moment so that you can say
   *
   *    scalac -d /tmp foo.scala -optimise
   *
   *  while also allowing
   *
   *    scala Program opt opt
   *
   *  to get their arguments.
   *
   *  Returns (success, List of unprocessed arguments)
   */
  def processArguments(arguments: List[String], processAll: Boolean): (Boolean, List[String]) = {
    def loop(args: List[String], residualArgs: List[String]): (Boolean, List[String]) = args match {
      case Nil        =>
        (checkDependencies, residualArgs)
      case "--" :: xs =>
        (checkDependencies, xs)
      case x :: xs  =>
        val isOpt = x startsWith "-"
        if (isOpt) {
          val newArgs = parseParams(args)
          if (args eq newArgs) {
            errorFn("bad option: '" + x + "'")
            (false, args)
          }
          // discard empties, sometimes they appear because of ant or etc.
          // but discard carefully, because an empty string is valid as an argument
          // to an option, e.g. -cp "" .  So we discard them only when they appear
          // in option position.
          else if (x == "") {
            loop(xs, residualArgs)
          }
          else lookupSetting(x) match {
            case Some(s) if s.shouldStopProcessing  => (checkDependencies, newArgs)
            case _                                  => loop(newArgs, residualArgs)
          }
        }
        else {
          if (processAll) loop(xs, residualArgs :+ x)
          else (checkDependencies, args)
        }
    }
    loop(arguments, Nil)
  }
  def processArgumentString(params: String) = processArguments(splitParams(params), true)

  /** Create a new Settings object, copying all user-set values.
   */
  def copy(): Settings = {
    val s = new Settings()
    val xs = userSetSettings flatMap (_.unparse)
    s.processArguments(xs.toList, true)
    s
  }

  /** A list pairing source directories with their output directory.
   *  This option is not available on the command line, but can be set by
{'fraction_non_alphanumeric': 0.09336433553925952, 'fraction_numerical': 0.0028617420854945446, 'mean_word_length': 2.2568433313919627, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2140540', 'n_tokens_mistral': 1580, 'n_tokens_neox': 1511, 'n_words': 532}