Apply replecement rules
186845
function applyReplacementRules(rulesset, content) {
  return rulesset.reduce((a,b) => {
    return a.replace(b[0], b[1]);
  }, content);
}
343456
private void paintRule(final Rule rule, final XmlStringBuilder xml) {
		if (rule.getCondition() == null) {
			throw new SystemException("Rule cannot be painted as it has no condition");
		}

		paintCondition(rule.getCondition(), xml);

		for (Action action : rule.getOnTrue()) {
			paintAction(action, "ui:onTrue", xml);
		}

		for (Action action : rule.getOnFalse()) {
			paintAction(action, "ui:onFalse", xml);
		}
	}
1036092
def do_allowrep(self, line):
        """"""
        self._split_args(line, 0, 0)
        self._command_processor.get_session().get_replication_policy().set_replication_allowed(
            True
        )
        self._print_info_if_verbose("Set replication policy to allow replication")
915708
def apply(self, snapshot):
        """"""

        for name in snapshot:
            setattr(self, name, snapshot[name])
1336916
def _compile_rules(self):
        """"""
        for state, table in self.RULES.items():
            patterns = list()
            actions = list()
            nextstates = list()
            for i, row in enumerate(table):
                if len(row) == 2:
                    pattern, _action = row
                    nextstate = None
                elif len(row) == 3:
                    pattern, _action, nextstate = row
                else:
                    fstr = "invalid RULES: state {}, row {}"
                    raise CompileError(fstr.format(state, i))
                patterns.append(pattern)
                actions.append(_action)
                nextstates.append(nextstate)
            reobj = re.compile('|'.join("(" + p + ")" for p in patterns))
            self._rules[state] = (reobj, actions, nextstates)
253727
def _process_rule(self, rule: dict, context: dict):
        
        if not rule or not self._shall_proceed(rule):
            return
        self.context.update(context)
        self.context.update(rule.get('context', {}))
        self.path = rule.get('path', None)
        self.source = rule.get('source', None)
        for entry in rule.get('documents', []):
            target, source = self._resolve_rule_document(entry)
            self.write(target, source)
        for entry in rule.get('preserve', []):
            target, source = self._resolve_rule_document(entry)
            self.write(target, source, preserve=True)
466654
def process_rule(self, m, dct, tpe):
        
        print('TODO - ' + tpe + ' + applying rule ' + str(m).replace('\n', '') )
145907
public function setupRules()
    {
        $this->rules->addMany([
            'call' => new Rule(new RegexMatcher(
                '/(?>(?<![^\\\]\\\)(?<=\n|\(|\)|\||;|`|^|do|if|then|else|fi|esac|done\$\(|^\$\s)\s*\b(\w+))(?!\s*=)/i'
            ), ['priority' => 1, 'context' => ['*none', '*expression']]),

            'comment' => new Rule(new CommentMatcher(['#'])),
            'string' => CommonFeatures::strings(['single' => '\'', 'double' => '"']),

            'keyword' => new Rule(new WordMatcher([
                'if', 'then', 'else', 'elif', 'fi', 'case', 'esac', 'for', 'select', 'while', 'until', 'do', 'done',
                'in', 'function', 'time', 'coproc'
            ]), ['priority' => 3]),

            'variable'  => [
                'assign' => new Rule(new RegexMatcher('/(\w+)[+-]?=/')),
                new Rule(new RegexMatcher('/(\$\w+)/i'), ['context' => ['*none', '*string.double']]),
                'special'  => new Rule(new RegexMatcher('/(\$[#@_])/i'), ['context' => ['*none', '*string.double']]),
                'argument' => new Rule(new RegexMatcher('/(\$\d+)/i'), ['context' => ['*none', '*string.double']]),
                new Rule(new RegexMatcher('/\$\{(\w+)(.*?)\}/i', [ 1 => Token::NAME, 2 => 'string' ]), ['context' => ['*none', '*string.double']])
            ],

            'number'    => new Rule(new RegexMatcher('/(-?(?:0[0-7]+|0[xX][0-9a-fA-F]+|0b[01]+|\d+))/')),
            'delimiter' => new Rule(new RegexMatcher('/^(\$)/m')),

            'symbol.parameter' => new Rule(new RegexMatcher('/[\s|](-{1,2}[\w-]+=?)\b/i'), [
                'priority' => 0,
                'context'  => ['!string', '!comment', '!call']
            ]),

            'expression' => [
                new Rule(new RegexMatcher('/(?=(\$\(((?>[^$()]+|(?1))+)\)))/x'), [
                    'context' => Validator::everywhere(),
                    'factory' => new TokenFactory(LanguageToken::class),
                    'inject'  => $this
                ]),
            ],

            'operator.escape' => new Rule(new RegexMatcher('/(\\\(?:x[0-9a-fA-F]{1,2}|u\{[0-9a-fA-F]{1,6}\}|[0-7]{1,3}|.))/i'), [
                'context' => ['*']
            ]),
        ]);
    }
378235
def _execute_rules(self, matches, context):
        
        if not self.disabled(context):
            rules = self.effective_rules(context)
            rules.execute_all_rules(matches, context)
1147767
public function setupRules()
    {
        $this->rules->addMany([
            'comment'     => new Rule(new CommentMatcher([], [['{#', '#}']]), ['priority' => 0]),
            'delimiter'   => new Rule(new RegexMatcher('/((\{[{%]|[%}]\}))/')),
            'variable'    => new Rule(new RegexMatcher('/\{\{\s*([a-z]\w*)/')),
            'call'        => new Rule(new RegexMatcher('/\{\{.*?\|([a-z]\w*)/')),
            'call.template-tag' => new Rule(new RegexMatcher('/{%\s*([a-z]\w*)/')),
            'string' => CommonFeatures::strings(['single' => '\'', 'double' => '"'], [
                'context' => ['!string', '!comment']
            ]),
        ]);
    }
261819
public void copyFrom(Rule rule) {
        setPolicy(rule.getPolicy());
        setCaptureStart(rule.getCaptureStart());
        setCaptureEnd(rule.getCaptureEnd());
        setPrivateComment(rule.getPrivateComment());
        setPublicComment(rule.getPublicComment());
        setRetrievalStart(rule.getRetrievalStart());
        setRetrievalEnd(rule.getRetrievalEnd());
        setSecondsSinceCapture(rule.getSecondsSinceCapture());
        setSurt(rule.getSurt());
        setWho(rule.getWho());
        setEnabled(rule.getEnabled());
        setExactMatch(rule.isExactMatch());
    }
954429
def _apply_rules_no_recurse(expr, rules):
    """"""
    try:
        # `rules` is an OrderedDict key => (pattern, replacement)
        items = rules.items()
    except AttributeError:
        # `rules` is a list of (pattern, replacement) tuples
        items = enumerate(rules)
    for key, (pat, replacement) in items:
        matched = pat.match(expr)
        if matched:
            try:
                return replacement(**matched)
            except CannotSimplify:
                pass
    return expr
1060117
def apply(self, binding_type, **args):
        """"""
        rule = self.find_rule(binding_type, **args)
        if rule is None:
            error = BindingError('Binding rule is not found')
            error.add_info('Binding type', binding_type)
            error.add_info('args', args)
            raise error
        binding = rule.apply(**args)
        if binding:
            args['node'].add_binding(rule.apply(**args))
408408
def apply_rules(json, type, rules)
      rules.each do |rule|
        next unless rule.function.call(json)
        rule.metadata = json
        rule.type = type

        case rule.modifier
        when :warning
          warnings << rule
        when :error
          errors << rule
        end
      end
    end
1222134
def process_rule(self,rule,pa,tuple):
        ''' 
        '''
        for i,v in enumerate(tuple):
            rule = rule.replace(pa[i],str(v))
        return eval(rule)
627634
public function applyRulesets()
    {
        // List of fields which actually need validation at this time.
        $fields = $this->getActualFields();

        foreach ($fields as $field) {
            $rulesets = $this->getRules($field);
            $this->active_field = $field;
            $this->prefix = '';
            $this->caption = '';
            foreach ($rulesets as $rules) {
                $this->applyRules($field, $rules);
            }
        }

        return $this;
    }
856216
function applyAllowedRule( rule, element, status, skipRequired ) {
		// This rule doesn't match this element - skip it.
		if ( rule.match && !rule.match( element ) )
			return;

		// If element doesn't have all required styles/attrs/classes
		// this rule doesn't match it.
		if ( !skipRequired && !hasAllRequired( rule, element ) )
			return;

		// If this rule doesn't validate properties only mark element as valid.
		if ( !rule.propertiesOnly )
			status.valid = true;

		// Apply rule only when all attrs/styles/classes haven't been marked as valid.
		if ( !status.allAttributes )
			status.allAttributes = applyAllowedRuleToHash( rule.attributes, element.attributes, status.validAttributes );

		if ( !status.allStyles )
			status.allStyles = applyAllowedRuleToHash( rule.styles, element.styles, status.validStyles );

		if ( !status.allClasses )
			status.allClasses = applyAllowedRuleToArray( rule.classes, element.classes, status.validClasses );
	}