@class Rule
@extends Tools

@param {String} ruleString
@param {Object} [params]
@param {Object} [data]
970220
function Rule(ruleString, params, data) {
    Tools.call(this, ruleString);

    /**
     * @public
     * @memberOf {Rule}
     * @property
     * @type {Object}
     * */
    this.params = _.extend({
        basePath: '',
        queryEq: '=',
        querySep: '&'
    }, params);

    /**
     * @public
     * @memberOf {Rule}
     * @property
     * @type {Object}
     * */
    this.data = _.extend({
        name: uniqueId()
    }, data);

    /**
     * @protected
     * @memberOf {Rule}
     * @property
     * @type {Array<String>}
     * */
    this._pathParams = this._findPathParams();

    /**
     * @protected
     * @memberOf {Rule}
     * @property
     * @type {Object}
     * */
    this._queryParams = this._compileQueryParams();

    /**
     * @protected
     * @memberOf {Rule}
     * @property
     * @type {Array}
     * */
    this._queryParamsNames = _.keys(this._queryParams);

    this.params.types = _.extend({}, commonTypes, this.params.types);

    /**
     * @protected
     * @memberOf {Rule}
     * @property
     * @type {Object}
     * */
    this._kinds = _.mapValues(this.params.types, function (regex, kind) {
        return new Kind(kind, regex);
    });

    _.forEach([{
        rules: this._pathParams,
        defaultKind: 'Segment'
    }, {
        rules: this._pathRule.query,
        defaultKind: 'String'
    }], function (setup) {
        _.forEach(setup.rules, function (rule) {
            if (!rule.kind) {
                if (rule.regex) {
                    rule.setUniqueKindName();
                    this._kinds[rule.kind] = new Kind(rule.kind, rule.regex);
                } else {
                    rule.kind = setup.defaultKind;
                }
            }

            if (!_.has(this._kinds, rule.kind)) {
                throw new TypeError(f('Unknown %j parameter type %j', rule.name, rule.kind));
            }
        }, this);
    }, this);

    /**
     * @protected
     * @memberOf {Rule}
     * @property
     * @type {Object}
     * */
    this._paramsCount = this._compileParamsCount();

    /**
     * @protected
     * @memberOf {Rule}
     * @property
     * @type {RegExp}
     * */
    this._matchRegExp = this._compileMatchRegExp();
}
451956
function (data, regex, {
	multiple = false
} = {}) {
	let result = data
	let extracted
	if (regex) {
		try {
			let rgx = regex
			if (_.isString(regex)) {
				rgx = new RegExp(regex, 'gim')
			}
			extracted = rgx.exec(data)
			if (multiple) {
				result = extracted
				// result = data.match(rgx)
			} else {
				if (extracted[1]) {
					result = extracted[1]
				} else {
					result = extracted[0]
				}
				// result = data.match(rgx)[0]
			}
		} catch (error) {
			// console.log("Regex error: ", error)
		}
	}
	return result
}
302283
function validateRule(rule, value) {
    // For a given rule, get the first letter of the string name of its
    // constructor function. "R" -> RegExp, "F" -> Function (these shouldn't
    // conflict with any other types one might specify). Note: instead of
    // getting .toString from a new object {} or Object.prototype, I'm assuming
    // that exports will always be an object, and using its .toString method.
    // Bad idea? Let me know by filing an issue
    var type = exports.toString.call(rule).charAt(8);
    // If regexp, match. If function, invoke. Otherwise, compare. Note that ==
    // is used because type coercion is needed, as `value` will always be a
    // string, but `rule` might not.
    return type === "R" ? rule.test(value) : type === "F" ? rule(value) : rule == value;
  }
779627
function RuleSet(language) {
  var data = englishRuleSet;
  DEBUG && console.log(data);
  switch (language) {
    case 'EN':
      data = englishRuleSet;
      break;
    case 'DU':
      data = dutchRuleSet;
      break;
  }
  if (data.rules) {
    this.rules = {};
    var that = this;
    data.rules.forEach(function(ruleString) {
      that.addRule(TF_Parser.parse(ruleString));
    })
  }
  DEBUG && console.log(this.rules);
  DEBUG && console.log('Brill_POS_Tagger.read_transformation_rules: number of transformation rules read: ' + Object.keys(this.rules).length);
}
598269
public function applyRules(array $rules = [], array $data = []): array
    {
        $data  = $data ?: $this->_data;
        $rules = $rules ?: $this->_rules;
        // save clean data
        $filtered = [];

        foreach ($rules as $rule) {
            if (!isset($rule[0], $rule[1])) {
                continue;
            }

            if (!$fields = $rule[0]) {
                continue;
            }

            $fields = \is_string($fields) ? Filters::explode($fields) : (array)$fields;

            foreach ($fields as $field) {
                if (!isset($data[$field])) {
                    $filtered[$field] = $rule['default'] ?? null;
                } else {
                    $filtered[$field] = $this->valueFiltering($data[$field], $rule[1]);
                }
            }
        }

        return $filtered;
    }
750193
function() {
      rulesArray = _explodeRules(_rules);

      for (var attribute in rulesArray) {

        var rules = rulesArray[attribute];
        for (var i in rules) {
          if (_errors[attribute]) {
            continue;
          };
          var ruleString  = rules[i];
          var parsedRule  = _parseRule(ruleString);
          var rule        = parsedRule.rule;
          var parameters  = parsedRule.parameters;
          var value       = _input[attribute] || null;
          var validatable = is_function(_resolvers[rule]);

          if (validatable && ! _resolvers[rule](attribute, value, parameters)) {
            _addFailure(attribute, rule, parameters);
          }
        }
      }

      return isEmptyObject(_errors);
    }
409317
def rule(pattern, *dependencies, &block)
      if block.nil?
        Rule.new(pattern, *dependencies)
      else
        Rule.new(pattern, *dependencies) do |rule|
          rule.define(&block)
        end
      end
    end
1230104
function(){
            _.each(this.rules, function(rule){
                rule.regex = eval(rule.regex.toString().replace(/^\//,'/^'));
            });
        }
1041900
function _parseRule(rule) {
    var parameters = [];

    // The format for specifying validation rules and parameters follows an
    // easy {rule}:{parameters} formatting convention. For instance the
    // rule "Max:3" states that the value may only be three letters.
    if (rule.indexOf(':')) {
      var ruleInfo  = rule.split(':');
      parameters = _parseParameters(ruleInfo[0], ruleInfo[1]);
    }

    return { parameters: parameters, rule: ruleInfo[0]};
  }
476894
def method_rules
      [
        Rule.new(:error, 40..41, "Description", "You should include a description for your method.", proc do |json|
          json[:body_md] && json[:body_md].empty?
        end),
        Rule.new(:warning, 43..45, "Params", "You should give a 'type' for the param, yes, ruby is duck-typey but it's useful for newbies to the language, use `@param [Type] name`.", proc do |json|
          json[:param_couplets] && json[:param_couplets].flat_map(&:values).include?(nil)
        end),
        Rule.new(:warning, 43..45, "Unknown Param", "You should give a 'type' for the param, yes, ruby is duck-typey but it's useful for newbies to the language, use `@param [Type] name`.", proc do |json|
          json[:param_couplets] && json[:param_couplets].flat_map(&:values).include?("Unknown")
        end),
        Rule.new(:warning, 46, "Return Type", "If the function has no useful return value, use ` @return  [void]` - this will be ignored by documentation generators.", proc do |json|
          return_hash = json[:tags].find { |tag| tag[:name] == "return" }
          !(return_hash && return_hash[:types] && !return_hash[:types].first.empty?)
        end)
      ]
    end
150474
function reportUndefinedRules( ast, session, options ) {

    const check = session.buildVisitor( {
        rule_ref( node ) {

            if ( ! ast.findRule( node.name ) ) {

                session.error(
                    `Rule "${ node.name }" is not defined.`,
                    node.location
                );

            }

        }
    } );

    check( ast );

    options.allowedStartRules.forEach( rule => {

        if ( ! ast.findRule( rule ) ) {

            session.error( `Start rule "${ rule }" is not defined.` );

        }

    } );

}
55748
function Rule(rules) {
            this.rules = rules;
            // Identifies individual rule
            this.name = "";
            // Identifies the grammar that this rule belongs to 
            this.grammarName = "";
            // Identifies types of rules. Rules can have "types" that are different than the class name
            this.type = "";
            // Used to provide access to the name of the class 
            this.className = "Rule";
            // Indicates whether generated nodes should be added to the abstract syntax tree
            this._createAstNode = false;
            // A parser function, computed in a rule's constructor. If successful returns either the original or a new 
            // ParseState object. If it fails it returns null.
            this.parser = null;
            // A lexer function, computed in a rule's constructor. The lexer may update the ParseState if successful.
            // If it fails it is required that the lexer restore the ParseState index to the previous state. 
            // Lexers should only update the index. 
            this.lexer = null;
        }
999967
function (rules) {

    var parsedRules = {};
    rules = this._flattenObject(rules);

    for (var attribute in rules) {

      var rulesArray = rules[attribute];

      this._parseRulesCheck(attribute, rulesArray, parsedRules);
    }
    return parsedRules;


  }
1076606
function _explodeRules(rules) {
    for (var i in rules) {
      if (is_string(rules[i])) {
        rules[i] = rules[i].split('|');
      }
    }
    return rules;
  }
490757
public function addRules($rules, $method = '*', $option = [], $pattern = [])
    {
        foreach ($rules as $key => $val) {
            if (is_numeric($key)) {
                $key = array_shift($val);
            }

            if (is_array($val)) {
                $route = array_shift($val);
                $option = $val ? array_shift($val) : [];
                $pattern = $val ? array_shift($val) : [];
            } else {
                $route = $val;
            }

            $this->addRule($key, $route, $method, $option, $pattern);
        }
    }
104497
private void extractRules(RuleSource ruleSource, Collection<?> blocks, RuleSetBuilder builder) throws RuleException {
        for (Object element : blocks) {
            if (element instanceof AbstractBlock) {
                AbstractBlock block = (AbstractBlock) element;
                if (EXECUTABLE_RULE_TYPES.contains(block.getRole())) {
                    extractExecutableRule(ruleSource, block, builder);
                } else if (GROUP.equals(block.getRole())) {
                    extractGroup(ruleSource, block, builder);
                }
                extractRules(ruleSource, block.getBlocks(), builder);
            } else if (element instanceof Collection<?>) {
                extractRules(ruleSource, (Collection<?>) element, builder);
            }
        }
    }
141280
function(rule, callback){
        var res = [];
        callback = callback || function(){};
        this.eachGroup(function(item){
            if(rule.group == item.name){
                callback.call(item, item);
                res.push(item);
            }
        });
        return res;
    }