Prepare rule before connecting

@param \ViKon\Parser\Lexer\Lexer $lexer lexer instance

@return $this
189152
public function prepare(Lexer $lexer) {
        $this->acceptedRuleNames = array_merge([
            CodeBlockRule::NAME,
            FencedCodeBlockRule::NAME,
            EolRule::NAME,
        ], $this->set->getRuleNamesByCategory(AbstractRuleSet::CATEGORY_FORMAT));
    }
41057
protected function _prepareRouter($router)
    {
        // Wrap Route That Make it usable for Route Stack Wrapper
        if (!$router instanceof iRouterStack)
            $router = new RouteStackChainWrapper($router);

        $router->setParent($this);


        $routeName = $this->getName().self::SEPARATOR.$router->getName();

        $router->setName($routeName);

        ## check if router name exists
        if (array_key_exists($routeName, $this->_routes_strict_override))
            throw new \RuntimeException(sprintf(
                'Router with name (%s) exists and not Allowed Override.'
                , $routeName
            ));

        return $router;
    }
1023326
public function setupRules()
    {
        $this->rules->addMany([
            'keyword' => new Rule(new WordMatcher([
                'auto', 'break', 'case', 'const', 'continue', 'default', 'do', 'else', 'enum', 'extern', 'for', 'goto',
                'if', 'register', 'return', 'sizeof', 'static', 'struct', 'switch', 'typedef', 'union', 'volatile',
                'while',
            ])),

            'meta.newline' => new CloseRule(new RegexMatcher('/()\R/m'), [
                'factory' => new TokenFactory(TerminatorToken::class),
                'context' => ['!operator.escape', '*string', '*call.preprocessor'],
                'closes'  => ['string.double', 'preprocessor'],
            ]),

            'preprocessor' => new OpenRule(new RegexMatcher('/^(#)/m'), [
                'context' => Validator::everywhere(),
                'priority' => -1
            ]),

            'call' => [
                'preprocessor' => new Rule(new RegexMatcher('/^#\s*(\w+)\b/m'), [
                    'context' => ['preprocessor']
                ]),
                new Rule(new RegexMatcher('/([a-z_]\w*)\s*\(/i'), ['priority' => -1]),
            ],

            'operator.escape' => new Rule(new RegexMatcher('/(\\\(?:\R|.|[0-7]{3}|x\x{2}))/s'), [
                'context' => Validator::everywhere()
            ]),

            'keyword.format' => new Rule(
                new RegexMatcher('/(%[diuoxXfFeEgGaAcspn%][-+#0]?(?:[0-9]+|\*)?(?:\.(?:[0-9]+|\*))?)/'), [
                    'context' => ['string']
                ]
            ),

            'string' => array_merge([
                new Rule(new RegexMatcher('/(<.*?>)/'), [
                    'context' => ['preprocessor']
                ])
            ], CommonFeatures::strings(['single' => '\'', 'double' => '"'], [
                'context' => ['!operator.escape', '!comment', '!string'],
            ])),

            'symbol.type' => [
                new Rule(new RegexMatcher('/(\w+)(?:\s+|\s*\*\s*)\w+\s*[=();,]/'), ['name' => 'universal']),
                new Rule(new WordMatcher(['int', 'float', 'double', 'char', 'void', 'long', 'short', 'signed', 'unsigned']), ['name' => 'builtin'])
            ],

            'comment' => [
                new Rule(new CommentMatcher(['//'], [['/*', '*/']]), ['priority' => 2])
            ],

            'variable.property' => new Rule(new RegexMatcher('/(?=(?:\w|\)|\])\s*(?:->|\.)\s*([a-z_]\w*))/'), ['priority' => 0]),

            'number' => new Rule(new RegexMatcher('/\b(-?(?:0x[\da-f]+|\d*\.?\d+(?:e[+-]?\d+)?)[ful]*)\b/i')),
            'operator' => [
                'punctuation' => new Rule(new RegexMatcher('/([;,])/'), ['priority' => 0]),
                new Rule(new RegexMatcher('/([*&])/'), ['priority' => 0]),
                new Rule(new RegexMatcher('/([!+\-\/*&|^<>=]{1,2}=?)/'), ['priority' => 0])
            ],

            'language.c' => [
                new Rule(new RegexMatcher('/^#define\s+\w+(.*?)(?>[^\\\]\r\n|[^\\\\\r]\n|\Z)/sim'), [
                    'factory' => new TokenFactory(LanguageToken::class),
                    'inject'  => $this,
                    'context' => ['preprocessor'],
                    'priority' => 10
                ]),
            ]
        ]);
    }
838677
public void configureContentAssistLexer(Binder binder) {
		binder.bind(Lexer.class)
			.annotatedWith(Names.named(LexerIdeBindings.CONTENT_ASSIST))
			.to(InternalPureXbaseLexer.class);
	}
54896
protected function ()
    {
        if (!($this->lexer->token['type'] === EmailLexer::INVALID
            || $this->lexer->token['type'] === EmailLexer::C_DEL)) {
            throw new ExpectedQPair();
        }

        $this->warnings[QuotedPart::CODE] =
            new QuotedPart($this->lexer->getPrevious()['type'], $this->lexer->token['type']);
    }
76214
public function prepare(
        ExampleNode $example,
        Specification $context,
        MatcherManager $matchers,
        CollaboratorManager $collaborators
    ) {
        if ($example->getSpecification()->getClassReflection()->hasMethod('let')) {
            $this->parameterValidator->validate($example->getSpecification()->getClassReflection()->getMethod('let'));
        }
        $this->parameterValidator->validate($example->getFunctionReflection());
        return $this;
    }
785900
public void addRuleParserBefore(IRuleParser parser, Class<? extends IRuleParser> beforeParser) {
        int index = getIndexOfClass(ruleParsers, beforeParser);
        if (index == -1) {
            throw new ParserAddException("parser " + beforeParser.getSimpleName() + " has not been added");
        }
        ruleParsers.add(index, parser);
    }
272691
def visitLexerAtom(self, ctx: jsgParser.LexerAtomContext):
        
        if ctx.LEXER_CHAR_SET() or ctx.ANY():
            self._rulePattern += str(ctx.getText())
        else:
            self.visitChildren(ctx)
1074817
public function createParser($kind = null)
    {
        if ($this->hasKindsSupport()) {
            $originalFactory = new OriginalParserFactory();

            $kind = $kind ?: $this->getDefaultKind();

            if (!\in_array($kind, static::getPossibleKinds())) {
                throw new \InvalidArgumentException('Unknown parser kind');
            }

            $parser = $originalFactory->create(\constant('PhpParser\ParserFactory::' . $kind));
        } else {
            if ($kind !== null) {
                throw new \InvalidArgumentException('Install PHP Parser v2.x to specify parser kind');
            }

            $parser = new Parser(new Lexer());
        }

        return $parser;
    }
406577
public function validator($validator, $condition = true)
    {
        if (!$condition) {
            return $this;
        }

        if ($validator instanceof \Closure) {
            $this->validators[] = $validator;
        } else {
            $this->rule($validator);
        }

        return $this;
    }
1309498
public function setValidator(Validator $validator)
    {
        if ($validator) {
            $this->validator = $validator;
            $this->validator->setForm($this);
        }
        return $this;
    }
1113234
protected function prepareParser()
    {
        return function (InlineParserInterface $stack, AbstractInlineParser $parser) {
            $parser->setNextParser($stack);
            $parser->setContext($this);

            return $parser;
        };
    }
86774
public function setHeader($aHeader = null)
    {
        if (is_null($aHeader) && $this->getMethod() == "POST") {
            $sHost = $this->getHost();

            $aHeader = array();
            $aHeader[] = 'POST /cgi-bin/webscr HTTP/1.1';
            $aHeader[] = 'Content-Type: multipart/form-data';
            if (isset($sHost)) {
                $aHeader[] = 'Host: ' . $sHost;
            }
            $aHeader[] = 'Connection: close';
        }
        $this->_aHeader = $aHeader;
    }
1318582
public function init($parts, $parser = LinkUtil::class)
    {

        if (is_string($parts) && filter_var($parts, FILTER_VALIDATE_URL)) {
            $parts = $parser::parse($parts);
        }

        /**@var $Property \ReflectionProperty */
        foreach((new \ReflectionObject($this))->getProperties(\ReflectionProperty::IS_PUBLIC) as $Property) {
            if ((!$Property->getValue($this)) && isset($parts[$Property->getName()])) {
                $Property->setValue($this, $parts[$Property->getName()]);
            }
        }

        return $this;
    }
902261
public function init(Parser $parser, Renderer $renderer) {
        foreach ($this->ruleRenderers as $ruleRenderer) {
            $renderer->registerRenderer($ruleRenderer, $this->name);
        }

        $parser->setRenderer($renderer);

        return $this;
    }
412746
public function tokenize(Cursor $cursor)
    {
        while ($cursor->hasNext()) {
            foreach ($this->skips as $skip) {
                if ($token = $skip->match($cursor->src())) {
                    $cursor->consume($token);

                    continue 2;
                }
            }

            foreach ($this->rules as $rule) {
                if ($token = $rule->match($cursor->src())) {
                    $cursor->consume($token);
                    $cursor->add($rule->getType(), $rule->format($token));

                    continue 2;
                }
            }

            throw new LexerException(sprintf('Can\'t tokenize the following expression: "%s".', $cursor->src()));
        }

        $cursor->add(Token::TYPE_EOF);

        return $cursor->getTokens();
    }
635910
public function prependTwigLoader(\Twig_LoaderInterface $twig_loader)
    {
      // Give precedence to the passed in loader
        $this->twig_loader = new \Twig_Loader_Chain(array($twig_loader, $this->twig_loader));
        return $this;
    }