replace all rules that we want to enable classy on
320072
function replaceRenderer(md, renderer) {
  var openMethodName = renderer.fullName + "_open";
  replacedMethods[openMethodName] = md.renderer.rules[openMethodName];

  md.renderer.rules[openMethodName] = function (tokens, idx) {
    var classy, result;

    // first get the result as per the original method we replaced
    result = replacedMethods[openMethodName].apply(null, arguments).trim();

    if (renderer.inline) {
      classy = getClassyFromInlineElement(tokens, idx, renderer.fullName);
    } else {
      classy = getClassyFromBlockElement(tokens, idx, renderer.fullName);
    }

    if (classy) {
      result = result.replace(new RegExp("<" + renderer.pattern), "$& class=\"" + classy.content + "\"");
    }

    return result;
  };
}
1175035
def _rules_attr(cls):
        """"""
        from qnet.algebra.core.algebraic_properties import (
            match_replace, match_replace_binary)
        if match_replace in cls.simplifications:
            return '_rules'
        elif match_replace_binary in cls.simplifications:
            return '_binary_rules'
        else:
            raise TypeError(
                "class %s does not have match_replace or "
                "match_replace_binary in its simplifications" % cls.__name__)
412682
function(rule, fn) {
      if (is_object(rule)) {
        _replacers = extend({}, _replacers, rule);
      } else if (is_string(rule)) {
        _replacers[rule] = fn;
      }
    }
186845
function applyReplacementRules(rulesset, content) {
  return rulesset.reduce((a,b) => {
    return a.replace(b[0], b[1]);
  }, content);
}
145153
def replace(self, **kwargs):
        
        if 'usage_key' in kwargs:
            for attr in self.USAGE_KEY_ATTRS:
                kwargs.pop(attr, None)
        else:
            kwargs['usage_key'] = self.usage_key.replace(**{
                key: kwargs.pop(key)
                for key
                in self.USAGE_KEY_ATTRS
                if key in kwargs
            })
        return super(AsideUsageKeyV2, self).replace(**kwargs)
347342
def replace(self):
        

        replacement = self._tw.tasks.filter(' '.join(self._uuids))
        self.__class__ = replacement.__class__
        self.__dict__ = replacement.__dict__
38159
public function setupRules()
    {
        $this->rules->addMany([
            'tag.open'  => [
                new OpenRule(new RegexMatcher('/(<[\w\.-]+)[:\/>:\s]/')),
                new CloseRule(new SubStringMatcher('>'), ['context' => ['!string', '!comment']]),
            ],
            'tag.close' => new Rule(new RegexMatcher('/(<\/' . self::IDENTIFIER . '>)/')),

            'symbol.tag' => new Rule(new RegexMatcher('/<\\/?' . self::IDENTIFIER . '/', [
                'name'      => Token::NAME,
                'namespace' => '$.namespace',
            ]), ['context' => ['tag', '!string']]),

            'number'  => new Rule(new RegexMatcher('/\s(-?(?:0[0-7]+|0[xX][0-9a-fA-F]+|0b[01]+|\d+(?:\.\d+)?))/')),
            'comment' => new Rule(new CommentMatcher(['#'])),
            'string'  => [
                CommonFeatures::strings(['single' => '\'', 'double' => '"'], ['context' => ['!comment', '!operator.escape']]),
                'path' => new Rule(new RegexMatcher('/\B(\/[^\s\)\(]*)/'))
            ],

            'call'    => new Rule(new RegexMatcher('/^\s*(\w+)/mi')),
            'variable'   => new Rule(new RegexMatcher('/%\{([\w-]+)\}/i'), ['context' => ['expression']]),

            'expression' => new Rule(new RegexMatcher('/(%\{.*?\})/i'), ['context' => ['string']]),
            'expression.regex' => [
                new Rule(new RegexMatcher('/(\[(?>[^\[\]]+|(?1))*\])/'), ['context' => ['string']]),
            ],

            'number.ip' => [
                new Rule(new RegexMatcher('/(\d{1,3}(\.\d{1,3}){3})/i'), ['context' => ['!string']])
            ],
            'constant' => new Rule(new WordMatcher(['On', 'Off', 'None', 'All', 'Any'])),

            'operator.escape' => new Rule(new RegexMatcher('/(\\\(?:\R|.|[0-7]{3}|x\x{2}))/s'), [
                'context' => ['!comment'],
                'priority' => 10
            ]),
            'operator.punctuation' => new Rule(new RegexMatcher('/([\(\){},;])/i')),
            'keyword.format' => new Rule(
                new RegexMatcher('/(%[\w%][-+#0]?(?:[0-9]+|\*)?(?:\.(?:[0-9]+|\*))?)/'), [
                    'context' => ['string']
                ]
            ),
        ]);
    }
1128665
function flattenRules(rules) {
  var out = {};

  rules.forEach(function(rule) {
    // Ignore anything that doesn't look like a CSS rule
    if (rule.type !== 'rule') return;
    rule.selectors.forEach(function(sel) {
      if (!out[sel]) out[sel] = {};

      rule.declarations.forEach(function(decl) {
        out[sel][decl.property] = decl.value;
      });
    });
  });

  return out;
}
1101270
def append_rules(self, an_iterable):
        """"""
        self.rules.extend(
            TransformRule(*x, config=self.config) for x in an_iterable
        )
383114
public function setupRules()
    {
        $function = '[a-z]\w*[!?]?';
        $this->rules->addMany([
            'comment' => [
                new Rule(new CommentMatcher(['#']), ['context' => ['!string.regex', '!string']]),
                'doc' => [
                    new OpenRule(new RegexMatcher('/^(=begin)/m')),
                    new CloseRule(new RegexMatcher('/^(=end)/m')),
                ]
            ],
            'keyword' => new Rule(new WordMatcher([
                'BEGIN', 'class', 'ensure', 'when', 'END', 'def', 'not', 'super', 'while',
                'alias', 'defined', 'for', 'or', 'then', 'yield', 'and', 'do', 'if', 'redo', 'begin', 'else',
                'in', 'rescue', 'undef', 'break', 'elsif', 'module', 'retry', 'unless', 'case', 'end', 'next', 'return',
                'until',
            ], ['case-sensitivity' => true])),
            'string' => [
                CommonFeatures::strings(
                    ['single' => '\'', 'double' => '"'],
                    ['context' => ['!operator.escape', '!comment', '!string', '!expression']]
                ),
                'generalized' => [
                    // TODO: Generalized strings
                ]
            ],
            'operator.escape' => new Rule(new RegexMatcher('/(\\\.)/'), [
                'context' => ['string']
            ]),
            'constant' => [
                new Rule(new RegexMatcher('/(?:[a-z_])?::([a-z_]\w*)/i')),
                'special' => new Rule(new WordMatcher(['self', 'nil', 'true', 'false', '__FILE__', '__LINE__']))
            ],
            'variable' => [
                'global'   => new Rule(new RegexMatcher('/(?:[^\\\]|^)(\$\w*)/i')),
                'property' => new Rule(new RegexMatcher('/(?:[^\\\]|^)(@{1,2}\w*)/i')),
            ],
            // JS + Perl = Ruby?
            'string.regex' => [
                new OpenRule(new RegexMatcher('#(?>[\[=(?:+,!~]|^|return|=>|&&|\|\|)\s*(/).*?/#sm'), [
                    'context' => ['!comment']
                ]),
                new Rule(new RegexMatcher('#(?=\/.*?(/[mixounse]*))#sm'), [
                    'priority' => 2,
                    'factory'  => new TokenFactory(ContextualToken::class),
                    'context'  => ['!operator.escape', 'string.regex']
                ])
            ],
            'call' => [
                new Rule(new RegexMatcher("/($function)\\s*\\(/i"), ['priority' => 2]),
                new Rule(new RegexMatcher(
                    // fixme: expression handling smth[blah].func
                    "/(?<![^\\\\]\\\\)(?<=\\n|\\{|\\(|\\}|\\|\\||or|&&|and|=|;)\\s*(?:\\w+(?:::|\\.))?($function)(?:[\\h\r]*\$|\\h+['\":\\w])/im"
                ), ['priority' => 0]),
            ],
            'symbol' => [
                'symbol'   => new Rule(new RegexMatcher('/[^\B:](:[a-z_]\w*)/i')),
                'class'    => new Rule(new RegexMatcher('/class\s+([a-z_]\w*)/i')),
                'function' => new Rule(new RegexMatcher('/def\s+(?:\[\]\s*|\*\s*|\w+\.){0,2}([a-z_]\w*)/i')),
            ],
            'expression.in-string' => new Rule(new RegexMatcher('/(?=(\#\{((?>[^\#{}]+|(?1))+)\}))/x'), [
                'context' => ['string.double'],
                'factory' => new TokenFactory(LanguageToken::class),
                'inject'  => $this
            ]),

            'number'    => new Rule(new RegexMatcher('/((?:-|\b)(?:0[0-7]+|0[xX][0-9a-fA-F]+|0b[01]+|\d+))/')),
        ]);
    }
94383
def _set_rules(self, rules: dict, overwrite=True):
        """"""

        if not isinstance(rules, dict):
            raise TypeError('rules must be an instance of dict or Rules,'
                            'got %r instead' % type(rules))

        if overwrite:
            self.rules = Rules(rules, self.default_rule)
        else:
            self.rules.update(rules)
1148088
function flushDynamicCssRules() {
        var rules = layoutStyleElem.sheet.cssRules,
            classCount = staleClassNames.length,
            i,
            j,
            ruleSuffix;

        for (i = 0; i < classCount; i++) {
            ruleSuffix = "." + staleClassNames[i] + " ";
            for (j = rules.length - 1; j >= 0; j--) {
                if (rules[j].selectorText.indexOf(ruleSuffix) !== -1) {
                    layoutStyleElem.sheet.deleteRule(j);
                }
            }
        }
        staleClassNames = [];
    }
657802
def flatten_rules(root)
      root.children.each do |child|
        case child
        when Tree::RuleNode
          flatten_rule(child)
        when Tree::DirectiveNode
          flatten_rules(child)
        end
      end
    end
86974
def __regrab(changes):
    
    for wid, mods, kc in __keybinds.keys():
        if kc in changes:
            ungrab_key(wid, mods, kc)
            grab_key(wid, mods, changes[kc])

            old = (wid, mods, kc)
            new = (wid, mods, changes[kc])
            __keybinds[new] = __keybinds[old]
            del __keybinds[old]
1134757
async function disableRules(rules) {
  return Object.keys(rules)
    .reduce((collection, rule) => ({
      ...collection,
      [rule]: OFF,
    }), {});
}
480754
public function setupRules()
    {
        $this->rules->addMany([
            'keyword'     => new Rule(new WordMatcher($this->_keywords, ['escape' => false])),
            'symbol.type' => new Rule(new WordMatcher($this->_types, ['escape' => false])),

            'constant' => new Rule(new WordMatcher(['FALSE', 'TRUE', 'NULL'])),
            'comment'  => new Rule(new CommentMatcher(['#', '--'], [['/*', '*/']])),
            
            'string'   => CommonFeatures::strings(['single' => '\'', 'double' => '"']),

            'number'          => new Rule(new RegexMatcher('/\b(-?\d+)\b/i')),
            'call'            => new Rule(new RegexMatcher('/([a-z_]\w*)\s*\(/i'), ['priority' => -1]),
            'operator.escape' => new Rule(new RegexMatcher('/(\\[\\0\'|bnrtZ%_])/'), ['context' => ['string']])
        ]);
    }
969869
def remove_useless(self):
        """"""
        if not self.is_contextfree():
            raise ValueError("grammar must be context-free")
        by_lhs = collections.defaultdict(list)
        by_rhs = collections.defaultdict(list)
        for [lhs], rhs in self.rules:
            by_lhs[lhs].append((lhs, rhs))
            for y in rhs:
                if y in self.nonterminals:
                    by_rhs[y].append((lhs, rhs))
            
        agenda = collections.deque([self.start])
        reachable = set()
        while len(agenda) > 0:
            x = agenda.popleft()
            if x in reachable: continue
            reachable.add(x)
            for _, rhs in by_lhs[x]:
                for y in rhs:
                    if y in by_lhs:
                        agenda.append(y)

        agenda = collections.deque()
        productive = set()
        for [lhs], rhs in self.rules:
            if all(y not in self.nonterminals for y in rhs):
                agenda.append(lhs)
        while len(agenda) > 0:
            y = agenda.popleft()
            if y in productive: continue
            productive.add(y)
            for lhs, rhs in by_rhs[y]:
                if all(y not in self.nonterminals or y in productive for y in rhs):
                    agenda.append(lhs)

        g = Grammar()
        g.set_start(self.start)

        for [lhs], rhs in self.rules:
            if (lhs in reachable & productive and
                all(y not in self.nonterminals or y in reachable & productive for y in rhs)):
                g.add_rule([lhs], rhs)
        return g