Resolve recursion.
This is required to make linear sense of repeating/recursive rules which nest as a natural result of the grammar.
e.g. [ RULES ::= RULE | RULE,RULES ] resolves to [ RULES ::= RULE,RULE,RULE,... ].
@return void
16094
function resolve_recursion(){
		$copy = $this->children;
		foreach( $copy as $i => $Child ){
			// recurse.
			$Child->resolve_recursion();
			// if child node is same symbol as self, replace with it's contents
			if( $Child->t === $this->t ){
				$this->splice( $Child, $Child->children );
			}
		}
	}
1280337
protected function parse(): void
    {
        switch ($this->notation) {

            case self::NOTATION_DOT_DECIMAL:
                $this->fromDotDecimal($this->value);
                break;

            case self::NOTATION_BINARY:
                $this->fromBinary($this->value);
                break;

            case self::NOTATION_CIDR_SHORT:
                $this->fromCidrShort($this->value);
                break;

            case self::NOTATION_CIDR_LONG:
                $this->fromCidrLong($this->value);
                break;

            case self::NOTATION_CIDR_BINARY:
                $this->fromCidrBinary($this->value);
                break;

            default:
                $this->notation = self::NOTATION_INVALID;
        }
    }
864726
public function allowsRecursion(): bool
    {
        foreach ($this->resolvers as $resolver) {
            if ($resolver->allowsRecursion()) {
                return true;
            }
        }

        return false;
    }
846689
private function resolveHelpers()
    {

        if (count($helpers = Arr::get($this->getGeneral(), 'helpers', []))) {

            foreach ($helpers as $helper) {
                if (file_exists($helper)) {
                    include $helper;
                }
            }

        }

    }
1351668
def solve_repeat(expr, vars):
    """"""
    try:
        result = repeated.meld(*[solve(x, vars).value for x in expr.children])
        return Result(result, ())
    except TypeError:
        raise errors.EfilterTypeError(
            root=expr, query=expr.source,
            message="All values in a repeated value must be of the same type.")
833241
public function resolveParenthesis(NodeContract $node)
    {
        foreach ($node->getChildren() as $child) {
            $this->resolveParenthesis($child);
        }

        if (!$node instanceof Nodes\TextNode) {
            return;
        }

        $value = '';
        $positions = [];

        foreach ($this->regex as $class => $regex) {
            preg_match($regex, $node->getValue(), $match, PREG_OFFSET_CAPTURE);

            if ($match) {
                $new_node = new $class();
                $new_node->setValue($match[0][0]);

                $start = $match[0][1];
                $length = strlen($match[0][0]);

                $nodes = $this->splitNode(Nodes\TextNode::class, $node, $new_node, $start, $start + $length);

                $this->resolveParenthesis($nodes[count($nodes) - 1]);
            }
        }
    }
127294
private function resolveRulePrototype()
    {
        if (!isset($this->routeTypeRulePrototypeMap[$this->routeType])) {
            throw new RuntimeException("Unable to resolve rule for route type '$this->routeType'. Route type is not supported.");
        }

        $prototypeClass = $this->routeTypeRulePrototypeMap[$this->routeType];
        $prototype      = $this->dependencyManager->get($prototypeClass);

        if (!($prototype instanceof AbstractRule)) {
            $givenType = get_class($prototype);

            throw new RuntimeException("The resolved rule prototype must inherit from Web\Route\Rule. Rule of type '$givenType' is not valid.");
        }

        $this->rulePrototype = $prototype;
    }
203326
def _resolve_rule_refs(self, grammar_parser, model_parser):
        """"""

        def _resolve_rule(rule):
            """
            Recursively resolve peg rule references.

            Args:
                rule(ParsingExpression or RuleCrossRef)
            """
            if not isinstance(rule, RuleCrossRef) and rule in resolved_rules:
                return rule
            resolved_rules.add(rule)

            if grammar_parser.debug:
                grammar_parser.dprint("Resolving rule: {}".format(rule))

            if type(rule) is RuleCrossRef:
                rule_name = rule.rule_name
                suppress = rule.suppress
                if rule_name in model_parser.metamodel:
                    rule = model_parser.metamodel[rule_name]._tx_peg_rule
                    if type(rule) is RuleCrossRef:
                        rule = _resolve_rule(rule)
                        model_parser.metamodel[rule_name]._tx_peg_rule = rule
                    if suppress:
                        # Special case. Suppression on rule reference.
                        _tx_class = rule._tx_class
                        rule = Sequence(nodes=[rule],
                                        rule_name=rule_name,
                                        suppress=suppress)
                        rule._tx_class = _tx_class
                else:
                    line, col = grammar_parser.pos_to_linecol(rule.position)
                    raise TextXSemanticError(
                        'Unexisting rule "{}" at position {}.'
                        .format(rule.rule_name,
                                (line, col)), line, col)

            assert isinstance(rule, ParsingExpression),\
                "{}:{}".format(type(rule), text(rule))

            # Recurse into subrules, and resolve rules.
            for idx, child in enumerate(rule.nodes):
                if child not in resolved_rules:
                    child = _resolve_rule(child)
                    rule.nodes[idx] = child

            return rule

        # Two pass resolving
        for i in range(2):
            if grammar_parser.debug:
                grammar_parser.dprint("RESOLVING RULE CROSS-REFS - PASS {}"
                                      .format(i + 1))

            resolved_rules = set()
            _resolve_rule(model_parser.parser_model)

            # Resolve rules of all meta-classes to handle unreferenced
            # rules also.
            for cls in model_parser.metamodel:
                cls._tx_peg_rule = _resolve_rule(cls._tx_peg_rule)
1279840
private function resolveSubrules()
    {
        $subrules = new Subrules($this->inputs, $this->rules, $this->attributes, $this->filters, $this->messages);

        $this->rules = $subrules->rules();
        $this->attributes = $subrules->attributes();
        $this->filters = $subrules->filters();
        $this->messages = $subrules->messages();
        $this->inputs = $subrules->inputs();
    }
493668
public function fixRepeatingArguments() {
        $either = [];
        foreach (static::transform($this)->children as $child) {
            $either[] = $child->children;
        }

        foreach ($either as $case) {
            $counts = [];
            foreach ($case as $child) {
                $ser = serialize($child);
                if (!isset($counts[$ser])) {
                    $counts[$ser] = ['cnt'=>0, 'items'=>[]];
                }

                $counts[$ser]['cnt']++;
                $counts[$ser]['items'][] = $child;
            }

            $repeatedCases = [];
            foreach ($counts as $child) {
                if ($child['cnt'] > 1) {
                    $repeatedCases = array_merge($repeatedCases, $child['items']);
                }
            }

            foreach ($repeatedCases as $e) {
                if ($e instanceof Argument || ($e instanceof Option && $e->argcount)) {
                    if (!$e->value) {
                        $e->value = [];
                    }
                    elseif (!is_array($e->value) && !$e->value instanceof \Traversable) {
                        $e->value = preg_split('/\s+/', $e->value);
                    }
                }
                if ($e instanceof Command || ($e instanceof Option && !$e->argcount)) {
                    $e->value = 0;
                }
            }
        }
        return $this;
    }
855022
public function resolve(string $class, array $rules = [])
    {
        //reset tree;
        $this->tree = [];

        //merge rules passed as parameter with general rules
        $this->rules = \array_merge($this->rules, $rules);

        //build dependency tree
        $this->buildTree($class);

        //build objects
        $this->buildObjects();

        //return required class
        return $this->cache[$class] ?? null;
    }
262252
public function resolve_dependencies() {
        if ($this->group) {
            // Default for when a group is selected.
            if ($this->attempts === null || $this->attempts == quiz_attempts_report::ALL_WITH) {
                $this->attempts = quiz_attempts_report::ENROLLED_WITH;
            }

        } else if (!$this->group && $this->course->id == SITEID) {
            // Force report on front page to show all, unless a group is selected.
            $this->attempts = quiz_attempts_report::ALL_WITH;

        } else if (!in_array($this->attempts, array(quiz_attempts_report::ALL_WITH, quiz_attempts_report::ENROLLED_WITH,
                quiz_attempts_report::ENROLLED_WITHOUT, quiz_attempts_report::ENROLLED_ALL))) {
            $this->attempts = quiz_attempts_report::ENROLLED_WITH;
        }

        $cleanstates = array();
        foreach (self::$statefields as $state) {
            if (in_array($state, $this->states)) {
                $cleanstates[] = $state;
            }
        }
        $this->states = $cleanstates;
        if (count($this->states) == count(self::$statefields)) {
            // If all states have been selected, then there is no constraint
            // required in the SQL, so clear the array.
            $this->states = null;
        }

        if (!quiz_report_can_filter_only_graded($this->quiz)) {
            // A grading mode like 'average' has been selected, so we cannot do
            // the show the attempt that gave the final grade thing.
            $this->onlygraded = false;
        }

        if ($this->attempts == quiz_attempts_report::ENROLLED_WITHOUT) {
            $this->states = null;
            $this->onlygraded = false;
        }

        if (!$this->is_showing_finished_attempts()) {
            $this->onlygraded = false;
        }

        if ($this->pagesize < 1) {
            $this->pagesize = quiz_attempts_report::DEFAULT_PAGE_SIZE;
        }
    }
81087
public function resolve()
    {
        if (isset($this->resolved)) {
            return $this->resolved;
        }

        $pointer = new Pointer($this->schema);
        if (is_internal_ref($this->ref) && $pointer->has($this->ref)) {
            return $this->resolved = $pointer->get($this->ref);
        }

        return $this->dereferencer()->dereference(resolve_uri($this->ref, $this->scope));
    }
427114
public static function resolve(){

        $aArgs = func_get_args();

        $aDebug = debug_backtrace(1);

        if(isset($aDebug[1])){

            $oDebug = $aDebug[1];

            $function = $oDebug['function'];
            $class = $oDebug['class'];

            if(!empty($aArgs)){
                $args = $aArgs;
            } else {
                $args = $oDebug['args'];
            }

            $app = $class::getFacadeApplication();

            return call_user_func_array( array($app[$class::getFacadeAccessor()], $function), $args);
        } else {
            Throw new \Exception('Cannot resolve this function');
        }
    }
1027993
protected function resolveLoops()
    {
        $LOOP_VAR_PATT = '~\#\( \s* (?<arg>[a-zA-Z][\.a-zA-Z0-9-_]*) \s* \)~x';
        $LOOP_PATT = Regex::make('~
            (?<expression>
                @for \s+ (?<var>{{ident}}) \s+ in \s+ (?<list>[^{]+)
            ) \s*
            {{ block }}
        ~xiS');

        $apply_scope = function ($str, $context) use ($LOOP_VAR_PATT, $LOOP_PATT) {
            // Need to temporarily hide child block scopes.
            $child_scopes = [];
            $str = preg_replace_callback($LOOP_PATT, function ($m) use (&$child_scopes) {
                $label = '?B' . count($child_scopes) . '?';
                $child_scopes[$label] = $m['block'];
                return $m['expression'] . $label;
            }, $str);

            $str = preg_replace_callback($LOOP_VAR_PATT, function ($m) use ($context) {
                // Normalize casing of built-in loop variables.
                // User variables are case-sensitive.
                $arg = preg_replace_callback('~^loop\.(parent\.)?counter0?$~i', function ($m) {
                    return strtolower($m[0]);
                }, $m['arg']);

                return isset($context[$arg]) ? $context[$arg] : '';
            }, $str);

            return str_replace(array_keys($child_scopes), array_values($child_scopes), $str);
        };

        $resolve_list = function ($list) {
            // Resolve the list of items for iteration.
            // Either a generator function or a plain list.
            $items = [];
            $this->placeVars($list);
            $list = $this->functions->apply($list);
            if (preg_match(Regex::make('~(?<func>range){{ parens }}~ix'), $list, $m)) {
                $func = strtolower($m['func']);
                $args = Functions::parseArgs($m['parens_content']);
                switch ($func) {
                    case 'range':
                        $items = range(...$args);
                        break;
                }
            }
            else {
                $items = Util::splitDelimList($list);
            }

            return $items;
        };

        $unroll = function ($str, $context = []) use (&$unroll, $LOOP_PATT, $apply_scope, $resolve_list) {
            $str = $apply_scope($str, $context);
            while (preg_match($LOOP_PATT, $str, $m, PREG_OFFSET_CAPTURE)) {
                $str = substr_replace($str, '', $m[0][1], strlen($m[0][0]));
                $context['loop.parent.counter'] = isset($context['loop.counter']) ? $context['loop.counter'] : -1;
                $context['loop.parent.counter0'] = isset($context['loop.counter0']) ? $context['loop.counter0'] : -1;
                foreach ($resolve_list($m['list'][0]) as $index => $value) {
                    $str .= $unroll($m['block_content'][0], [
                        $m['var'][0] => $value,
                        'loop.counter' => $index + 1,
                        'loop.counter0' => $index,
                    ] + $context);
                }
            }

            return $str;
        };

        $this->string->pregReplaceCallback($LOOP_PATT, function ($m) use ($unroll) {
            return Template::tokenize($unroll(Template::unTokenize($m[0])));
        });
    }
1250363
protected function resolveXmlBase()
    {
        $stack = $this->getXmlBaseStack();
        $stack->rewind();

        $resolvedBase = '';

        while ($stack->valid() === true) {

            if (($currentBase = $stack->current()) !== '') {
                if ($resolvedBase === '') {
                    $resolvedBase = $currentBase;
                } else {
                    $resolvedBase = Url::rtrim($currentBase) . '/' . Url::ltrim($resolvedBase);
                }
            }

            $stack->next();
        }

        if ($stack->count() > 0) {
            $stack->pop();
        }

        return $resolvedBase;
    }
1024802
public function addRules($rules)
    {
        // The primary purpose of this parser is to expand any "*" rules to the all
        // of the explicit rules needed for the given data. For example the rule
        // names.* would get expanded to names.0, names.1, etc. for this data.
        $response = (new ValidationRuleParser($this->data))
                            ->explode($rules);

        $this->rules = array_merge_recursive(
            $this->rules, $response->rules
        );

        $this->implicitAttributes = array_merge(
            $this->implicitAttributes, $response->implicitAttributes
        );
    }