Parse and/or compile given rule into rule tree.

        :param rule: Filtering grammar rule.
        :return: Parsed and/or compiled rule.
191031
def prepare(self, rule):
        
        if self.parser:
            rule = self.parser.parse(rule)
        if self.compiler:
            rule = self.compiler.compile(rule)
        return rule
486885
def instructions(self):
        

        if self._instructions is None:
            # Compile the rule into an Instructions instance; we do
            # this lazily to amortize the cost of the compilation,
            # then cache that result for efficiency...
            self._instructions = parser.parse_rule(self.name, self.text)

        return self._instructions
281636
protected function parseRule( $rule )
	{
		$parameters = [];

		// example: {rule}:{parameters}
		if( strpos( $rule, ':' ) !== false ) {
			list( $rule, $parameter ) = explode( ':', $rule, 2 );

			// example: {parameter1,parameter2,...}
			$parameters = $this->parseParameters( $rule, $parameter );
		}

		$rule = ucwords( str_replace( ['-', '_'], ' ', trim( $rule )));
		$rule = str_replace( ' ', '', $rule );

		return [ $rule, $parameters ];
	}
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;


  }
371602
def parse_rule(cls, txt):
        
        types = {"glob": GlobRule,
                 "regex": RegexRule,
                 "range": RangeRule,
                 "before": TimestampRule,
                 "after": TimestampRule}

        # parse form 'x(y)' into x, y
        label, txt = Rule._parse_label(txt)
        if label is None:
            if '*' in txt:
                label = "glob"
            else:
                label = "range"
        elif label not in types:
            raise ConfigurationError(
                "'%s' is not a valid package filter type" % label)

        rule_cls = types[label]
        txt_ = "%s(%s)" % (label, txt)

        try:
            rule = rule_cls._parse(txt_)
        except Exception as e:
            raise ConfigurationError("Error parsing package filter '%s': %s: %s"
                                     % (txt_, e.__class__.__name__, str(e)))
        return rule
616663
function(grammar, ruleName) {
      grammar  = this._apply("anything");
      ruleName = this._apply("anything");

      var foreign = inherit(grammar, {
        bt: this.bt.borrow()
      });

      var ans = foreign._apply(ruleName);
      this.bt.take_back(); // return the borrowed input stream
      return ans;
    }
1279565
private function parseRule($rule, &$fields)
    {
        if(!isset($this->rulesCache[$rule]))
        {
            $fields = [];
            $rule = str_replace(['/', '\{', '\}'], ['\/', '{', '}'], preg_quote($rule));
            $this->rulesCache[$rule] = '/^' . preg_replace_callback(
                '/{([^}]+)}/i',
                function($matches)use(&$fields){
                    $fields[] = $matches[1];
                    return '(.+)';
                },
                $rule
            ) . '\/?$/';
        }
        return $this->rulesCache[$rule];
    }
1328294
def add_rule(self, rule):
        """"""
        parsed_rule = None

        if rule.count('->') == 1 and rule.count('=>') == 0:
            parsed_rule = tuple(''.join(part.split()) for part in rule.split('->')) + (0,)
        elif rule.count('->') == 0 and rule.count('=>') == 1:
            parsed_rule = tuple(''.join(part.split()) for part in rule.split('=>')) + (1,)

        if parsed_rule is None:
            raise SyntaxError('Wrong format: ' + rule)
        else:
            self.rules.append(parsed_rule)
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);
            }
        }
    }
75698
public final void ruleOpAnd() throws RecognitionException {

        		int stackSize = keepStackSize();
        	
        try {
            // InternalXbase.g:246:2: ( ( '&&' ) )
            // InternalXbase.g:247:2: ( '&&' )
            {
            // InternalXbase.g:247:2: ( '&&' )
            // InternalXbase.g:248:3: '&&'
            {
            if ( state.backtracking==0 ) {
               before(grammarAccess.getOpAndAccess().getAmpersandAmpersandKeyword()); 
            }
            match(input,15,FOLLOW_2); if (state.failed) return ;
            if ( state.backtracking==0 ) {
               after(grammarAccess.getOpAndAccess().getAmpersandAmpersandKeyword()); 
            }

            }


            }

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {

            	restoreStackSize(stackSize);

        }
        return ;
    }
698812
public static void processRuleElement(ParserContext context, ConfigurationRuleBuilder rule, Element element)
    {
        String id = $(element).attr("id");

        List<Element> children = $(element).children().get();
        for (Element child : children)
        {
            Object result = context.processElement(child);

            switch ($(child).tag())
            {
            case "when":
                rule.when(((Condition) result));
                break;

            case "perform":
                rule.perform(((Operation) result));
                break;

            case "otherwise":
                rule.otherwise(((Operation) result));
                break;

            case "where":
                break;
            }
        }

        if (StringUtils.isNotBlank(id))
        {
            rule.withId(id);
        }

    }
1062707
def on_rule(node, compiled_grammar)
      name = process(node.children[0], compiled_grammar)

      if compiled_grammar.has_terminal?(name)
        compiled_grammar.add_error(
          "the rule name #{name.inspect} is already used as a terminal name",
          node.source_line
        )
      end

      if compiled_grammar.has_rule_with_branches?(name)
        compiled_grammar.add_error(
          "the rule #{name.inspect} has already been defined",
          node.source_line
        )

        return
      end

      branches = node.children[1..-1].map do |child|
        process(child, compiled_grammar)
      end

      rule = compiled_grammar.lookup_rule(name)

      rule.branches.concat(branches)
    end
367243
async def parse_target(self, runtime, target_str):
        ''''''
        pipeline_parts = target_str.split(RULE_SEPARATOR)
        module = await self.resolve_module(runtime, pipeline_parts[0],
                                           target_str)
        rules = []
        for part in pipeline_parts[1:]:
            rule = await self.resolve_rule(runtime, part)
            rules.append(rule)
        return module, tuple(rules)
764171
function (rule, context) {
        return _.find(this.members, _.isFunction(rule) && _.isObject(context) ? rule.bind(context) : rule);
    }
266181
def rule_str2rule(rule_str, prob):
    # type: (str, float) -> Rule
    
    if rule_str == "default":
        return Rule([], prob)

    raw_rules = rule_str[1:-1].split(",")
    clauses = []
    for raw_rule in raw_rules:
        idx = raw_rule.find("=")
        if idx == -1:
            raise ValueError("No \"=\" find in the rule!")
        clauses.append(Clause(int(raw_rule[1:idx]), int(raw_rule[(idx + 1):])))
    return Rule(clauses, prob)
1000045
public void add(Rule rule) {
		List<Token> tokens = rule.getTokens();
		for (Token token : tokens) {
			for (String str : token.getTerms()) {
				if (str.charAt(0) != ':') {
					Library.insertWord(forest, new Value(str, "rule", "10000"));
				}
			}
		}


		for (String str : tokens.get(0).getTerms()) {
			Set<Rule> rules = ruleIndex.get(str);
			if(rules==null){
				rules = new HashSet<>() ;
				ruleIndex.put(str,rules) ;
			}
			rules.add(rule) ;
		}
	}
1179626
def compile_ip_v4(rule):
    
    if isinstance(rule.value, ipranges.Range):
        return rule
    return IPV4Rule(ipranges.from_str_v4(rule.value))