public function testPreprocessors() { $m = new PluginManager($this->getParserMock()); $r = $m->addPreProcessor($preprocessor1 = new myTestPreProcessor('first')); $this->assertInstanceOf('ILess\\PluginManager', $r, 'fluent interface works'); $preprocessors = $m->getPreProcessors(); $this->assertEquals([$preprocessor1], $preprocessors, 'getPreProcessors returns an array of preprocessors'); // add second but with higher priority $m->addPreProcessor($preprocessor2 = new myTestPreProcessor('second'), 200); $preprocessors = $m->getPreProcessors(); $this->assertEquals([$preprocessor2, $preprocessor1], $preprocessors, 'getPreProcessors returns an array of preprocessors'); }
/** * Parse a Less string into nodes. * * @param string $string The string to parse * * @return array * * @throws ParserException If there was an error in parsing the string */ protected function parse($string) { $string = Util::normalizeString($string); if ($this->pluginManager) { $preProcessors = $this->pluginManager->getPreProcessors(); foreach ($preProcessors as $preProcessor) { /* @var $preProcessor PreProcessorInterface */ $string = $preProcessor->process($string, ['context' => $this->context, 'file_info' => $this->context->currentFileInfo, 'importer' => $this->importer]); } } $this->input = new ParserInput(); $this->input->start($string); $rules = $this->parsePrimary(); $endInfo = $this->input->end(); $error = null; if (!$endInfo->isFinished) { $message = $endInfo->furthestPossibleErrorMessage; if (!$message) { $message = 'Unrecognised input'; if ($endInfo->furthestChar === '}') { $message .= '. Possibly missing opening \'{\''; } elseif ($endInfo->furthestChar === ')') { $message .= '. Possibly missing opening \'(\''; } elseif ($endInfo->furthestReachedEnd) { $message .= '. Possibly missing something'; } } $error = new ParserException($message, $endInfo->furthest, $this->context->currentFileInfo); } if ($error) { throw $error; } return $rules; }