Get ids of repeating sections with fields which act as sources in a rule
@param rule
@returns {String[]}
333041
function getSourceRepeatingSections(rule) {
    return _.chain(rule.ruleConditionalStatements)
      .map(function(ruleConditionalStatement) {
        var sourceId = ruleConditionalStatement.sourceField.toString();
        return fieldSectionMapping[sourceId];
      })
      .filter(function(section) {
        return section && section.repeating;
      })
      .map(function(repeatingSection) {
        return repeatingSection._id.toString();
      })
      .uniq()
      .value();
  }
698930
function getChildRules(css, parent) {
  var result = [];
  var selectorRegExp = new RegExp(parent.selector);

  // Walk all rules to mach child selectors
  css.walkRules(selectorRegExp, function (rule) {
    var childRule = (0, _matchChild.matchChild)(parent, rule);
    if (childRule) {
      result.push(rule);
    }
  });

  // Walk all at-rules to match nested child selectors
  css.walkAtRules(function (atRule) {
    atRule.walkRules(selectorRegExp, function (rule) {
      var childRule = (0, _matchChild.matchChild)(parent, rule);
      // Create new at-rule to append only necessary selector to critical
      var criticalAtRule = _postcss2.default.atRule({
        name: atRule.name,
        params: atRule.params
      });
      /**
       * Should append even if parent selector, but make sure the two rules
       * aren't identical.
       */
      if ((rule.selector === parent.selector || childRule) && _postcss2.default.parse(rule).toString() !== _postcss2.default.parse(parent).toString()) {
        var clone = rule.clone();
        criticalAtRule.append(clone);
        result.push(criticalAtRule);
      }
    });
  });

  return result;
}
1352220
public static String getRuleName(AbstractRule rule) {
		RuleWithParameterValues parameterValues = RuleWithParameterValues.findInEmfObject(rule);
		if (parameterValues != null) {
			return rule.getName();
		}
		RuleNames ruleNames = RuleNames.getRuleNames(rule);
		return ruleNames.getAntlrRuleName(rule);
	}
344384
function(rule) {
    var strCss = '';
    strCss += rule.selectors.join(',\n') + ' {';
    rule.declarations.forEach(function(rules) {
      strCss += commentOrDeclaration(rules);
    });
    strCss += '\n}\n\n';
    return strCss;
  }
300522
function detachProps(rule) {
    var rs = {};
    var params = removeSpace(rule.params);
    var argsRE = /\(\S+\)/g;

    var name = detachCustomName(params);

    var args = detachCustomValues(params);

    var content = removeSpace(rule.nodes[0].params);

    rs.name = name;
    rs.args = args;
    rs.content = content;
    return rs;
}
1169104
function select(rule, prefix) {
 return rule.selectors && rule.selectors[0] && rule.selectors[0].indexOf(prefix) === 0;
}
923063
function getRuleReplacementMessage(ruleId) {
		if (ruleId in replacements.rules) {
			var newRules = replacements.rules[ruleId];

			return "Rule \'" + ruleId + "\' was removed and replaced by: " + newRules.join(", ");
		}

		return null;
	}
796234
def get_candidates(rules)
      candidates = []
      rules.each { |rule| candidates << rule if rule.ever_matched? && rule.time_to_report? }
      candidates
    end
237300
public PluralRules getRulesForRulesId(String rulesId) {
        // synchronize on the map.  release the lock temporarily while we build the rules.
        PluralRules rules = null;
        boolean hasRules;  // Separate boolean because stored rules can be null.
        synchronized (rulesIdToRules) {
            hasRules = rulesIdToRules.containsKey(rulesId);
            if (hasRules) {
                rules = rulesIdToRules.get(rulesId);  // can be null
            }
        }
        if (!hasRules) {
            try {
                UResourceBundle pluralb = getPluralBundle();
                UResourceBundle rulesb = pluralb.get("rules");
                UResourceBundle setb = rulesb.get(rulesId);

                StringBuilder sb = new StringBuilder();
                for (int i = 0; i < setb.getSize(); ++i) {
                    UResourceBundle b = setb.get(i);
                    if (i > 0) {
                        sb.append("; ");
                    }
                    sb.append(b.getKey());
                    sb.append(": ");
                    sb.append(b.getString());
                }
                rules = PluralRules.parseDescription(sb.toString());
            } catch (ParseException e) {
            } catch (MissingResourceException e) {
            }
            synchronized (rulesIdToRules) {
                if (rulesIdToRules.containsKey(rulesId)) {
                    rules = rulesIdToRules.get(rulesId);
                } else {
                    rulesIdToRules.put(rulesId, rules);  // can be null
                }
            }
        }
        return rules;
    }
206448
function processRule ( rule , returnObj ) {
    // some additional properties
    //var selector_arr = rule.selector.split( " " );
    rule.name = getSelectorName( rule.selector );//selector_arr.pop();
    // give a shorter unique id to it
    //var cssString = ruleToCSSString( rule );
    // "-" causes Router to get confused
    // only want something unique, so replacing with an "n"
    rule.uuid = getRuleUUID( rule );
    rule.children = [];
    rule.total_child_rules = 0;// just simple rules, not everything
    rule.total_child_comps = 0;
    rule.is_duplicate = false;

    // find depth
    rule.depth = Math.min( 6 , rule.selector.split(" ").length-1 );
    if ( !returnObj.totals.depths[ rule.depth ] )
        returnObj.totals.depths[ rule.depth ] = 0;
    returnObj.totals.depths[ rule.depth ]++;
    if ( !returnObj.depths_all[ rule.depth ] )
        returnObj.depths_all[ rule.depth ] = [];
    returnObj.depths_all[ rule.depth ].push( rule.uuid );

    rule.metadata = {};
    rule.states = [];
    rule.pseudos = [];

    if ( rule.type == "rule" ) {
        returnObj.totals.rules++;
        returnObj.rules.push( rule );
        if ( !returnObj.totals.depths_rules[ rule.depth ] )
            returnObj.totals.depths_rules[ rule.depth ] = 0;
        returnObj.totals.depths_rules[ rule.depth ]++;
    }else if ( rule.type == "tagged_rule" ){
        processComponent( rule , returnObj );
    }

    returnObj.totals.overall++;

    // selector hash
    if ( !returnObj.selector_hash[rule.selector] ) {
        returnObj.selector_hash[rule.selector] = rule;
    }else{
        console.log("ERROR, selector not unique!" , rule.selector );
    }

    returnObj.uuid_hash[ rule.uuid ] = rule;

    //finish up...
    returnObj.selector_hash[rule.name] = rule;
    returnObj.selectors.push( rule );
}
890549
function createRuleListeners(rule, ruleContext) {
    try {
        return rule.create(ruleContext);
    } catch (ex) {
        ex.message = `Error while loading rule '${ruleContext.id}': ${ex.message}`;
        throw ex;
    }
}
1336585
function(rule) {
      var ans = arguments[1] !== undefined ? [arguments[1]] : [],
          state;
      while (true) {
        state = this.bt.current_state();
        try { ans.push(rule.call(this)) } 
        catch (f) {
          this.bt.catch_mismatch(f);
          this.bt.restore(state);
          break;
        }
      }
      return ans
    }
93648
function splitNext(source, cb, rules) { 
  
  var matchPos = source.search( makeRegExp( joinProperties( rules ) ) );
  if (matchPos != -1) {
    var match = source.substr( 0, matchPos + 1 )
    for (property in rules) {
      var rule = rules[property]
        , re = makeRegExp( rule );
      if (source.search(re) == matchPos) {
        var token = source.match( re )
          , response = {
              lhs: source.substr( 0, matchPos ), 
              rhs: source.substr( matchPos + token[0].length ),
              token: token[0]
            };
        cb( property, response );
        return;
      }
    }
  }
  cb( 'end', { lhs: source } );
  
  function makeRegExp( rules ) {
    return new RegExp( '(' + rules + ')' ); 
  }

  function joinProperties(properties) {
    var result = [];
    for(property in properties) {
      result.push( properties[property] );
    }
    return result.join( '|' );
  }
}
1151271
function getMetadataFromRules (rulesData) {
  var metadata = [];

  rulesData.forEach(function (ruleData) {
    var rule = new Rule(ruleData);

    if (_isBucketsMetadata(rule)) {
      metadata.push(new BucketsMetadata(rule));
    } else if (_isCategoriesMetadata(rule)) {
      metadata.push(new CategoriesMetadata(rule));
    }
  });

  return metadata;
}
1010204
public List<AbstractPatternRule> getPatternRulesByIdAndSubId(String Id, String subId) {
    List<Rule> rules = getAllRules();
    List<AbstractPatternRule> rulesById = new ArrayList<>();   
    for (Rule rule : rules) {
      if (rule instanceof AbstractPatternRule &&
          rule.getId().equals(Id) && ((AbstractPatternRule) rule).getSubId().equals(subId)) {
        rulesById.add((AbstractPatternRule) rule);
      }
    }    
    return rulesById;
  }
1271148
function checkByAll ( rules, value, fieldMeta ) {
        return (rules || [])
            .map(function ( rule ) { 
                return checkByRule( rule, value, fieldMeta );
            })
            .filter(function ( el ) { return null !== el; });
    }
147064
@SneakyThrows
    public SQLStatement fill(final Collection<SQLSegment> sqlSegments, final SQLStatementRule rule) {
        SQLStatement result = rule.getSqlStatementClass().newInstance();
        result.setLogicSQL(sql);
        for (SQLSegment each : sqlSegments) {
            Optional<SQLSegmentFiller> filler = parsingRuleRegistry.findSQLSegmentFiller(databaseType, each.getClass());
            if (filler.isPresent()) {
                doFill(each, result, filler.get());
            }
        }
        return result;
    }