@brief Parses rules.

@param string $init_rule
@return array $rules
551498
private function _splitRule($init_rule)
    {
        $rules = array();
        $init_rule = str_replace("|", ";", $init_rule);
        $rules = explode(";", $init_rule);
        foreach($rules as $key => $rule)
        {
            $rules[$key] = trim($rule);
        }
        return $rules;
    }
491888
def init(self, rules):
        """"""
        # Initialize the option parser
        for dest in rules.keys():
            rule = rules[dest]

            # Assign defaults ourselves here, instead of in the option parser
            # itself in order to allow for multiple calls to parse (dont want
            # subsequent calls to override previous values with default vals).
            if 'default' in rule:
                self.result['kwargs'][dest] = rule['default']

            flags = rule['flags']
            kwargs = { 'action': rule.get('action', "store") }
            # NOTE: Don't provision the parser with defaults here, per above.
            for key in ['callback', 'help', 'metavar', 'type']:
                if key in rule: kwargs[key] = rule[key]
            self.add_option(*flags, dest=dest, **kwargs)

            # Remember the dest vars that we see, so that we can merge results
            self.dests.add(dest)
505941
public static void parseBinaryAndUnaryRules(Iterable<String> unfilteredRuleLines, 
      List<CcgBinaryRule> binaryRules, List<CcgUnaryRule> unaryRules) {
    for (String line : unfilteredRuleLines) {
      // System.out.println(line);
      if (!line.startsWith("#")) {
        try {
          binaryRules.add(CcgBinaryRule.parseFrom(line));
        } catch (IllegalArgumentException e) {
          unaryRules.add(CcgUnaryRule.parseFrom(line));
        }
      }
    }
  }
893592
protected function processRules()
	{
		$this->cache = !YII_DEBUG;
		// Generate the clientRules
		$this->rules = $this->cache ? Yii::app()->cache->get('CiiMS::Routes') : array();
		if ($this->rules == false || empty($this->rules))
		{
			$this->rules = array();
			$this->rules = $this->generateClientRules();
			$this->rules = CMap::mergearray($this->addRssRules(), $this->rules);
			$this->rules = CMap::mergeArray($this->addModuleRules(), $this->rules);

			Yii::app()->cache->set('CiiMS::Routes', $this->rules);
		}

		// Append our cache rules BEFORE we run the defaults
		$this->rules['<controller:\w+>/<action:\w+>/<id:\d+>'] = '<controller>/<action>';
		$this->rules['<controller:\w+>/<action:\w+>'] = '<controller>/<action>';

		return parent::processRules();
	}
549983
public static function init() {
		
		$found = false;
		$patternExtension = Config::getOption("patternExtension");
		self::loadRules();
		
		foreach (self::$rules as $rule) {
			if ($rule->test($patternExtension)) {
				self::$instance = $rule;
				$found = true;
				break;
			}
		}
		
		if (!$found) {
			Console::writeError("the supplied pattern extension didn't match a pattern loader rule. check your config...");
		}
		
	}
550690
public function getRules()
    {
        $rules = empty($this->rules) ? $this->rules($this->request, $this->params) : $this->rules;
        return $this->explodeRules($rules);
    }
577769
public function parse($rules)
    {
        $attributes = array();
        $rules = $rule = $this->getRulesAsArray($rules);

        foreach ($rules as $rule) {
            list($rule, $parameters) = $this->parseRule($rule);

            if ($rule && method_exists($this, $rule)) {
                $attributes += $this->$rule($parameters);
            }
        }

        return $attributes;
    }
72809
private function getRules($rules)
    {
        $rules = [];

        foreach($rules as $rule)
        {
            $rules[] = explode('/', $rule);
        }

        return $rules;
    }
1028064
public function getRulesWithSourceSpecification()
    {
        $rulesWithSource = [];

        foreach ($this->attributeRules as $name => $rules) {
            $rulesWithSource[$name] = array_filter(
                $rules,
                function ($rule) {
                    return isset($rule['source']);
                }
            );
        }

        return array_filter($rulesWithSource);
    }
727838
public function list_rules()
    {
        $result = array();
        $i      = 1;

        foreach ($this->script as $idx => $filter) {
            if (empty($filter['actions'])) {
                continue;
            }
            $fname = $filter['name'] ?: "#$i";
            $result[] = array(
                'id'    => $idx,
                'name'  => $fname,
                'class' => $filter['disabled'] ? 'disabled' : '',
            );
            $i++;
        }

        return $result;
    }
890558
public function rules() {

		$rules = [
			[ [ 'widgetId', 'htmlOptions', 'icon', 'order' ], 'safe' ],
			[ 'widget', 'boolean' ],
			[ 'order', 'number', 'integerOnly' => true ]
		];

		if( Yii::$app->core->trimFieldValue ) {

			$trim[] = [ [ 'htmlOptions', 'icon' ], 'filter', 'filter' => 'trim', 'skipOnArray' => true ];

			return ArrayHelper::merge( $trim, $rules );
		}

		return $rules;
	}
1232010
protected function parseValidationRule($rule)
	{
		$ruleArray = ['name' => '', 'parameters' => []];

		$explodedRule = explode(':', $rule);
		$ruleArray['name'] = array_shift($explodedRule);
		$ruleArray['parameters'] = explode(',', array_shift($explodedRule));

		return $ruleArray;
	}
1293440
public function getRules($ruleset)
    {
        if ($ruleset == self::YANDEX) {

            $russianRules = parent::getRules('russian');
            /**
             * @see http://translit-online.ru/yandex.html
             */
            return array_merge($russianRules, [
                //kh после букв c,s,e,h ; в остальных случаях - h
                /*'цх' => 'ckh',
                'ЦХ' => 'CKh',
                'Цх' => 'Ckh',
                'цХ' => 'cKh',

                'сх'  => 'skh',
                'СХ'  => 'SKh',
                'Сх'  => 'Skh',
                'сХ'  => 'sKh',

                //TODO: доделать комбинации больших маленьких букв
                'ех'  => 'еkh',
                'ёх'  => 'еkh',
                'эх'  => 'еkh',

                'чх' => 'chkh',
                'хх' => 'khkh',
                'шх' => 'shkh',
                'щх' => 'shchkh',
                'жх' => 'zhkh',

                'хх' => 'hkh',

                'hх' => 'hkh',*/

                'ё' => 'yo',
                'Ё' => 'Yo',

                'й' => 'j',
                'Й' => 'J',

                /*'х' => 'h',
                'Х' => 'H',*/

                'х' => 'х',
                'Х' => 'Х',

                'ц' => 'c',
                'Ц' => 'C',

                'щ' => 'shch',
                'Щ' => 'Shch',

                'э' => 'eh',
                'Э' => 'Eh',
            ]);
        }

        return parent::getRules($ruleset);
    }
827692
public function parse($rules): Rule\Set
    {
        $isArray = is_array($rules);
        $isAssoc = $isArray && self::isAssociative($rules);
        $set = null;
        if (is_string($rules) || is_object($rules) || $isAssoc) {
            $set = $this->getRule($rules);
        } elseif ($isArray) {
            foreach ($rules as $v) {
                $toAdd = $this->getRule($v);
                $set = $set === null ? $toAdd : $set->merge($toAdd);
            }
        }
        return $set ?? new Rule\Set();
    }
226220
def get_loaded_rules(rules_paths):
    
    for path in rules_paths:
        if path.name != '__init__.py':
            rule = Rule.from_path(path)
            if rule.is_enabled:
                yield rule
915888
protected function getRules()
    {
        if ($this->compiledRules === null) {
            $rules = array();

            foreach ($this->ruleFiles as $file) {
                $rules += require $file;
            }

            $this->compiledRules = $this->compiler->compile($rules);
        }

        return $this->compiledRules;
    }
699514
private function parseRule($rule)
	{
		if (!is_array($rule) || (count($rule) < 2)) {
			throw new ValidatorException('Invalid declaration of validation rule');
		}

		is_array($rule[0]) || $rule[0] = [$rule[0]];

		if (!is_string($rule[1])) {
			throw new ValidatorException('Validator name: Expected string');
		}

		if (isset($rule[2])) {
			if(!is_array($rule[2])) {
				throw new ValidatorException('Validator options: Expected array');
			}
		} else {
			$rule[2] = [];
		}
		$rule[2] = new ArrayWrapper($rule[2]);

		return $rule;
	}