@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | $result = new Result($tokens->getSource(), $tokens->current()); |
| 98 | 98 | |
| 99 | 99 | for ($tokens->next(); $tokens->valid(); $tokens->next()) { |
| 100 | - if(!$tokens->current()->process($context, $this, $result, $tokens)) { |
|
| 100 | + if (!$tokens->current()->process($context, $this, $result, $tokens)) { |
|
| 101 | 101 | break; |
| 102 | 102 | } |
| 103 | 103 | } |
@@ -147,7 +147,7 @@ discard block |
||
| 147 | 147 | private function _rules($embedded = false) |
| 148 | 148 | { |
| 149 | 149 | $rules = clone $this->rules; |
| 150 | - if(is_bool($embedded)) { |
|
| 150 | + if (is_bool($embedded)) { |
|
| 151 | 151 | $rules->addMany(['language.'.$this->getIdentifier() => $this->getEnds($embedded)]); |
| 152 | 152 | } |
| 153 | 153 | |
@@ -88,7 +88,7 @@ |
||
| 88 | 88 | |
| 89 | 89 | public final function getFQN($class = false) |
| 90 | 90 | { |
| 91 | - $embedded =$this->getEmbedded(); |
|
| 91 | + $embedded = $this->getEmbedded(); |
|
| 92 | 92 | return ($class ? get_class($this) : $this->getIdentifier()).( |
| 93 | 93 | !empty($embedded) |
| 94 | 94 | ? ' + '.implode(', ', array_map($class ? 'get_class' : function(Language $e) { return $e->getIdentifier(); }, $embedded)) |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | protected function getCommandName(InputInterface $input) |
| 35 | 35 | { |
| 36 | 36 | $command = $input->getFirstArgument(); |
| 37 | - if(!$command && !$input->hasParameterOption('--help')) { |
|
| 37 | + if (!$command && !$input->hasParameterOption('--help')) { |
|
| 38 | 38 | return 'list'; |
| 39 | 39 | } elseif ($this->has($command)) { |
| 40 | 40 | return $command; |
@@ -56,7 +56,7 @@ discard block |
||
| 56 | 56 | protected function getDefaultInputDefinition() |
| 57 | 57 | { |
| 58 | 58 | $input = parent::getDefaultInputDefinition(); |
| 59 | - $input->setOptions(array_filter($input->getOptions(), function (InputOption $option) { |
|
| 59 | + $input->setOptions(array_filter($input->getOptions(), function(InputOption $option) { |
|
| 60 | 60 | return $option->getShortcut() != 'q'; |
| 61 | 61 | })); |
| 62 | 62 | $input->addOption(new InputOption('no-output', 's', InputOption::VALUE_NONE, 'Disables output, useful for debug')); |
@@ -40,7 +40,7 @@ |
||
| 40 | 40 | $formatters = KeyLighter::get()->registeredFormatters(); |
| 41 | 41 | $table = new Table($output); |
| 42 | 42 | |
| 43 | - if(!$input->getOption('headerless')) { |
|
| 43 | + if (!$input->getOption('headerless')) { |
|
| 44 | 44 | $table->setHeaders(['Name', 'Formatter']); |
| 45 | 45 | } |
| 46 | 46 | |
@@ -46,13 +46,13 @@ discard block |
||
| 46 | 46 | |
| 47 | 47 | $table = new Table($output); |
| 48 | 48 | |
| 49 | - if(!$input->getOption('headerless')) { |
|
| 49 | + if (!$input->getOption('headerless')) { |
|
| 50 | 50 | $table->setHeaders([ucfirst($input->getArgument('by')), $input->getOption('classes') ? 'Class name' : 'Language']); |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | $table->setRows(array_map(function($language) { |
| 54 | 54 | return [ |
| 55 | - implode(', ', array_map(function ($f) { return "<comment>{$f}</comment>"; }, $language['aliases'])), |
|
| 55 | + implode(', ', array_map(function($f) { return "<comment>{$f}</comment>"; }, $language['aliases'])), |
|
| 56 | 56 | $language['class'] |
| 57 | 57 | ]; |
| 58 | 58 | }, $input->getOption('no-group') ? $this->processNonGrouped($languages) : $this->processGrouped($languages))); |
@@ -63,8 +63,8 @@ discard block |
||
| 63 | 63 | |
| 64 | 64 | protected function processGrouped($languages) { |
| 65 | 65 | $result = []; |
| 66 | - foreach($languages as $alias => $class) { |
|
| 67 | - if(!isset($result[$class])) { |
|
| 66 | + foreach ($languages as $alias => $class) { |
|
| 67 | + if (!isset($result[$class])) { |
|
| 68 | 68 | $result[$class] = ['aliases' => [], 'class' => $class]; |
| 69 | 69 | } |
| 70 | 70 | |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | |
| 77 | 77 | protected function processNonGrouped($languages) { |
| 78 | 78 | $result = []; |
| 79 | - foreach($languages as $alias => $class) { |
|
| 79 | + foreach ($languages as $alias => $class) { |
|
| 80 | 80 | $result[] = ['aliases' => [$alias], 'class' => $class]; |
| 81 | 81 | } |
| 82 | 82 | |
@@ -68,14 +68,14 @@ discard block |
||
| 68 | 68 | $parsed = $this->parse($tokenized); |
| 69 | 69 | $formatted = $this->format($parsed); |
| 70 | 70 | |
| 71 | - if($this->wants('time')) { |
|
| 71 | + if ($this->wants('time')) { |
|
| 72 | 72 | $this->_output->writeln(sprintf( |
| 73 | 73 | '<info>Overall:</info> %.4fs, %s chars/s', |
| 74 | 74 | array_sum($this->_times), number_format(strlen($this->_source) / array_sum($this->_times)) |
| 75 | 75 | )); |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | - if($this->wants('detailed-time')) { |
|
| 78 | + if ($this->wants('detailed-time')) { |
|
| 79 | 79 | $this->_slashed('Times [s]', array_map(function($t) { |
| 80 | 80 | return number_format($t, 5); |
| 81 | 81 | }, $this->_times)); |
@@ -84,11 +84,11 @@ discard block |
||
| 84 | 84 | }, $this->_times)); |
| 85 | 85 | } |
| 86 | 86 | |
| 87 | - if($this->wants('count')) { |
|
| 87 | + if ($this->wants('count')) { |
|
| 88 | 88 | $this->_slashed('Token count', array_map('number_format', $this->_counts)); |
| 89 | 89 | } |
| 90 | 90 | |
| 91 | - if($this->wants('density')) { |
|
| 91 | + if ($this->wants('density')) { |
|
| 92 | 92 | $this->_slashed('Token density [tokens/kB]', array_map(function($c) { |
| 93 | 93 | return number_format($c / strlen($this->_source) * 1024, 1); |
| 94 | 94 | }, $this->_counts)); |
@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | |
| 105 | 105 | protected function tokenize() |
| 106 | 106 | { |
| 107 | - $tokens = $this->benchmark(function () { |
|
| 107 | + $tokens = $this->benchmark(function() { |
|
| 108 | 108 | return $this->_language->tokenize($this->_source); |
| 109 | 109 | }, $this->_times['tokenization']); |
| 110 | 110 | |
@@ -133,7 +133,7 @@ discard block |
||
| 133 | 133 | |
| 134 | 134 | protected function parse(Tokens $tokens) |
| 135 | 135 | { |
| 136 | - $tokens = $this->benchmark(function () use ($tokens) { |
|
| 136 | + $tokens = $this->benchmark(function() use ($tokens) { |
|
| 137 | 137 | return $this->_language->parse($tokens); |
| 138 | 138 | }, $this->_times['parsing']); |
| 139 | 139 | |
@@ -147,7 +147,7 @@ discard block |
||
| 147 | 147 | |
| 148 | 148 | protected function format(Tokens $tokens) |
| 149 | 149 | { |
| 150 | - return $this->benchmark(function () use ($tokens) { |
|
| 150 | + return $this->benchmark(function() use ($tokens) { |
|
| 151 | 151 | return $this->_formatter->format($tokens); |
| 152 | 152 | }, $this->_times['formatting']); |
| 153 | 153 | } |
@@ -156,10 +156,10 @@ discard block |
||
| 156 | 156 | { |
| 157 | 157 | $this->_output->writeln(sprintf( |
| 158 | 158 | "$message %s: %s", |
| 159 | - implode(' / ', array_map(function ($f) { |
|
| 159 | + implode(' / ', array_map(function($f) { |
|
| 160 | 160 | return "<comment>{$f}</comment>"; |
| 161 | 161 | }, array_keys($data))), |
| 162 | - implode(' / ', array_map(function ($f) { |
|
| 162 | + implode(' / ', array_map(function($f) { |
|
| 163 | 163 | return "<info>{$f}</info>"; |
| 164 | 164 | }, array_values($data))) |
| 165 | 165 | )); |
@@ -26,11 +26,11 @@ discard block |
||
| 26 | 26 | { |
| 27 | 27 | protected function execute(InputInterface $input, OutputInterface $output) |
| 28 | 28 | { |
| 29 | - if($input->getOption('dry')) { |
|
| 29 | + if ($input->getOption('dry')) { |
|
| 30 | 30 | $output->writeln($this->generate($output)); |
| 31 | 31 | } else { |
| 32 | 32 | file_put_contents( |
| 33 | - __DIR__ . '/../../../Config/metadata.php', |
|
| 33 | + __DIR__.'/../../../Config/metadata.php', |
|
| 34 | 34 | '<?php return '.$this->generate($output).';' |
| 35 | 35 | ); |
| 36 | 36 | } |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | |
| 48 | 48 | protected function generate(OutputInterface $output) |
| 49 | 49 | { |
| 50 | - $dir = __DIR__ . '/../../../Language'.DIRECTORY_SEPARATOR; |
|
| 50 | + $dir = __DIR__.'/../../../Language'.DIRECTORY_SEPARATOR; |
|
| 51 | 51 | $iterator = new \RecursiveIteratorIterator( |
| 52 | 52 | new \RecursiveDirectoryIterator($dir, \RecursiveDirectoryIterator::SKIP_DOTS), |
| 53 | 53 | \RecursiveIteratorIterator::LEAVES_ONLY |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | ), OutputInterface::VERBOSITY_VERBOSE); |
| 66 | 66 | |
| 67 | 67 | |
| 68 | - if($metadata = $this->process($output, $class)) { |
|
| 68 | + if ($metadata = $this->process($output, $class)) { |
|
| 69 | 69 | $result[] = $metadata; |
| 70 | 70 | } |
| 71 | 71 | } |
@@ -70,21 +70,19 @@ discard block |
||
| 70 | 70 | public function languageByName($name, $params = []) |
| 71 | 71 | { |
| 72 | 72 | return isset($this->_languages['name'][$name]) ? |
| 73 | - $this->_languages['name'][$name]($params) : |
|
| 74 | - new PlainText($params); |
|
| 73 | + $this->_languages['name'][$name]($params) : new PlainText($params); |
|
| 75 | 74 | } |
| 76 | 75 | |
| 77 | 76 | public function languageByMime($mime, $params = []) |
| 78 | 77 | { |
| 79 | 78 | return isset($this->_languages['mime'][$mime]) ? |
| 80 | - $this->_languages['mime'][$mime]($params) : |
|
| 81 | - new PlainText($params); |
|
| 79 | + $this->_languages['mime'][$mime]($params) : new PlainText($params); |
|
| 82 | 80 | } |
| 83 | 81 | |
| 84 | 82 | public function languageByExt($filename, $params = []) |
| 85 | 83 | { |
| 86 | - foreach($this->_languages['extension'] as $mask => $class) { |
|
| 87 | - if(fnmatch($mask, $filename)) { |
|
| 84 | + foreach ($this->_languages['extension'] as $mask => $class) { |
|
| 85 | + if (fnmatch($mask, $filename)) { |
|
| 88 | 86 | return $class($params); |
| 89 | 87 | } |
| 90 | 88 | } |
@@ -110,7 +108,7 @@ discard block |
||
| 110 | 108 | |
| 111 | 109 | public function registeredLanguages($by = 'name', $class = false) |
| 112 | 110 | { |
| 113 | - return array_map(function ($e) use($class) { |
|
| 111 | + return array_map(function($e) use($class) { |
|
| 114 | 112 | return $e([])->getFQN($class); |
| 115 | 113 | }, $this->_languages[$by]); |
| 116 | 114 | } |
@@ -150,7 +148,7 @@ discard block |
||
| 150 | 148 | |
| 151 | 149 | public function init() |
| 152 | 150 | { |
| 153 | - foreach(include __DIR__.'/Config/metadata.php' as $alias) { |
|
| 151 | + foreach (include __DIR__.'/Config/metadata.php' as $alias) { |
|
| 154 | 152 | $class = $alias[0]; |
| 155 | 153 | unset($alias[0]); |
| 156 | 154 | |
@@ -166,13 +164,13 @@ discard block |
||
| 166 | 164 | */ |
| 167 | 165 | public function register($class, array $options) |
| 168 | 166 | { |
| 169 | - if(!is_callable($class) && is_subclass_of($class, Language::class)) { |
|
| 167 | + if (!is_callable($class) && is_subclass_of($class, Language::class)) { |
|
| 170 | 168 | $class = function($arguments = []) use ($class) { |
| 171 | 169 | return new $class($arguments); |
| 172 | 170 | }; |
| 173 | 171 | } |
| 174 | 172 | |
| 175 | - foreach(array_intersect_key($options, array_flip(['name', 'mime', 'extension'])) as $name => $values) { |
|
| 173 | + foreach (array_intersect_key($options, array_flip(['name', 'mime', 'extension'])) as $name => $values) { |
|
| 176 | 174 | $this->_languages[$name] = array_merge($this->_languages[$name], array_fill_keys($values, $class)); |
| 177 | 175 | } |
| 178 | 176 | } |
@@ -135,6 +135,9 @@ |
||
| 135 | 135 | return $this->_formatters; |
| 136 | 136 | } |
| 137 | 137 | |
| 138 | + /** |
|
| 139 | + * @return string |
|
| 140 | + */ |
|
| 138 | 141 | public function highlight($source, Language $language, FormatterInterface $formatter = null) |
| 139 | 142 | { |
| 140 | 143 | $formatter = $formatter ?: $this->getDefaultFormatter(); |
@@ -36,14 +36,14 @@ |
||
| 36 | 36 | new OpenRule(new RegexMatcher('/(<[\w\.-]+)[:\/>:\s]/')), |
| 37 | 37 | new CloseRule(new SubStringMatcher('>'), ['context' => ['!string', '!comment']]) |
| 38 | 38 | ], |
| 39 | - 'tag.close' => new Rule(new RegexMatcher('/(<\/' . self::IDENTIFIER . '>)/')), |
|
| 39 | + 'tag.close' => new Rule(new RegexMatcher('/(<\/'.self::IDENTIFIER.'>)/')), |
|
| 40 | 40 | |
| 41 | - 'symbol.tag' => new Rule(new RegexMatcher('/<\\/?' . self::IDENTIFIER . '/', [ |
|
| 41 | + 'symbol.tag' => new Rule(new RegexMatcher('/<\\/?'.self::IDENTIFIER.'/', [ |
|
| 42 | 42 | 'name' => Token::NAME, |
| 43 | 43 | 'namespace' => '$.namespace' |
| 44 | 44 | ]), ['context' => ['tag', '!string']]), |
| 45 | 45 | |
| 46 | - 'symbol.attribute' => new Rule(new RegexMatcher('/' . self::IDENTIFIER . '=/', [ |
|
| 46 | + 'symbol.attribute' => new Rule(new RegexMatcher('/'.self::IDENTIFIER.'=/', [ |
|
| 47 | 47 | 'name' => Token::NAME, |
| 48 | 48 | 'namespace' => '$.namespace' |
| 49 | 49 | ]), ['context' => ['tag', '!string']]), |