diff --git a/README.md b/README.md index 34e7125..a55289a 100644 --- a/README.md +++ b/README.md @@ -10,17 +10,17 @@ Lit is a multilanguage syntax highlighter written in PHP. It takes code as input ## Documentation ## -### dW\\Lit\\Grammar::__construct ### +### MensBeam\\Lit\\Grammar::__construct ### -Creates a new `dW\Lit\Grammar` object. +Creates a new `MensBeam\Lit\Grammar` object. ```php -public function dW\Lit\Grammar::__construct(?string $scopeName = null, ?array $patterns = null, ?string $name = null, ?array $injections = null, ?array $repository = null) +public function MensBeam\Lit\Grammar::__construct(?string $scopeName = null, ?array $patterns = null, ?string $name = null, ?array $injections = null, ?array $repository = null) ``` #### Parameters #### -In normal usage of the library the parameters won't be used (see `dW\Lit\Grammar::loadJSON` and examples below for more information), but they are listed below for completeness' sake. +In normal usage of the library the parameters won't be used (see `MensBeam\Lit\Grammar::loadJSON` and examples below for more information), but they are listed below for completeness' sake. ***scopeName*** - The scope name of the grammar ***patterns*** - The list of patterns in the grammar @@ -29,12 +29,12 @@ In normal usage of the library the parameters won't be used (see `dW\Lit\Grammar ***repository*** - The list of repository items in the grammar -### dW\\Lit\\Grammar::loadJSON ### +### MensBeam\\Lit\\Grammar::loadJSON ### -Imports an Atom JSON grammar into the `dW\Lit\Grammar` object. +Imports an Atom JSON grammar into the `MensBeam\Lit\Grammar` object. ```php -public function dW\Lit\Grammar::loadJSON(string $filename) +public function MensBeam\Lit\Grammar::loadJSON(string $filename) ``` #### Parameters #### @@ -42,21 +42,21 @@ public function dW\Lit\Grammar::loadJSON(string $filename) ***filename*** - The JSON file to be imported -### dW\\Lit\\GrammarRegistry::clear ### +### MensBeam\\Lit\\GrammarRegistry::clear ### Clears all grammars from the registry ```php -public static function dW\Lit\GrammarRegistry::clear() +public static function MensBeam\Lit\GrammarRegistry::clear() ``` -### dW\\Lit\\GrammarRegistry::get ### +### MensBeam\\Lit\\GrammarRegistry::get ### Retrieves a grammar from the registry ```php -public static function dW\Lit\GrammarRegistry::get(string $scopeName): Grammar|false +public static function MensBeam\Lit\GrammarRegistry::get(string $scopeName): Grammar|false ``` #### Parameters #### @@ -65,15 +65,15 @@ public static function dW\Lit\GrammarRegistry::get(string $scopeName): Grammar|f #### Return Values #### -Returns a `dW\Lit\Grammar` object on success and `false` on failure. +Returns a `MensBeam\Lit\Grammar` object on success and `false` on failure. -### dW\\Lit\\GrammarRegistry::set ### +### MensBeam\\Lit\\GrammarRegistry::set ### Retrieves a grammar from the registry ```php -public static function dW\Lit\GrammarRegistry::set(string $scopeName, dW\Lit\Grammar $grammar): bool +public static function MensBeam\Lit\GrammarRegistry::set(string $scopeName, MensBeam\Lit\Grammar $grammar): bool ``` #### Parameters #### @@ -86,12 +86,12 @@ public static function dW\Lit\GrammarRegistry::set(string $scopeName, dW\Lit\Gra Returns `true` on success and `false` on failure. -### dW\\Lit\\Highlight::toElement ### +### MensBeam\\Lit\\Highlight::toElement ### Highlights incoming string data and outputs a PHP `DOMElement`. ```php -public static dW\Lit\Highlight::toElement(string $data, string $scopeName, ?\DOMDocument $document = null, string $encoding = 'windows-1252'): \DOMElement +public static MensBeam\Lit\Highlight::toElement(string $data, string $scopeName, ?\DOMDocument $document = null, string $encoding = 'windows-1252'): \DOMElement ``` #### Parameters #### @@ -106,12 +106,12 @@ public static dW\Lit\Highlight::toElement(string $data, string $scopeName, ?\DOM Returns a `pre` `DOMElement`. -### dW\\Lit\\Highlight::toString ### +### MensBeam\\Lit\\Highlight::toString ### Highlights incoming string data and outputs a string containing serialized HTML. ```php -public static dW\Lit\Highlight::toString(string $data, string $scopeName, string $encoding = 'windows-1252'): string +public static MensBeam\Lit\Highlight::toString(string $data, string $scopeName, string $encoding = 'windows-1252'): string ``` #### Parameters #### @@ -137,7 +137,7 @@ echo "🐵 OOK! 🐵"; CODE; // Use UTF-8 as the encoding to preserve the emojis. -$element = dW\Lit\Highlight::toElement($code, 'text.html.php', null, 'UTF-8'); +$element = MensBeam\Lit\Highlight::toElement($code, 'text.html.php', null, 'UTF-8'); $element->setAttribute('class', 'highlighted'); // Use PHP DOM's DOMDocument::saveHTML method to print the highlighted markup @@ -159,7 +159,7 @@ An already existing `DOMDocument` may be used as the owner document of the retur ... $document = new DOMDocument(); // $element will be owned by $document. -$element = dW\Lit\Highlight::toElement($code, 'text.html.php', $document); +$element = MensBeam\Lit\Highlight::toElement($code, 'text.html.php', $document); ``` Other DOM libraries which inherit from PHP's DOM such as [`MensBeam\HTML`][d] may also be used: @@ -168,7 +168,7 @@ Other DOM libraries which inherit from PHP's DOM such as [`MensBeam\HTML`][d] ma ... $document = new MensBeam\HTML\Document(); // $element will be owned by $document. -$element = dW\Lit\Highlight::toElement($code, 'text.html.php', $document); +$element = MensBeam\Lit\Highlight::toElement($code, 'text.html.php', $document); // MensBeam\HTML\Element can simply be cast to a string to serialize. $string = (string)$element; ``` @@ -177,7 +177,7 @@ Of course Lit can simply output a string, too: ```php ... -$string = dW\Lit\Highlight::toString($code, 'text.html.php'); +$string = MensBeam\Lit\Highlight::toString($code, 'text.html.php'); ``` Lit has quite a long list of out-of-the-bag supported languages, but sometimes other languages need to be highlighted: @@ -186,12 +186,12 @@ Lit has quite a long list of out-of-the-bag supported languages, but sometimes o ... // Import a hypothetical Ook Atom JSON language grammar into a Grammar object // and add it to the registry. -$grammar = new dW\Lit\Grammar; +$grammar = new MensBeam\Lit\Grammar; $grammar->loadJSON('/path/to/source.ook.json'); -dW\Lit\GrammarRegistry::set($grammar->scopeName, $grammar); +MensBeam\Lit\GrammarRegistry::set($grammar->scopeName, $grammar); // Now the grammar can be used to highlight code -$element = dW\Lit\Highlight::toElement($code, $grammar->scopeName); +$element = MensBeam\Lit\Highlight::toElement($code, $grammar->scopeName); ``` diff --git a/composer.json b/composer.json index e5f10c2..55f5278 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "dw/lit", + "name": "mensbeam/lit", "type": "library", "description": "TextMate-like syntax highlighting in PHP", "license": "MIT", @@ -19,12 +19,11 @@ "require": { "php": "^7.4 || ^8.0", "ext-dom": "*", - "ext-json": "*", - "mensbeam/html": "dev-master" + "ext-json": "*" }, "autoload": { "psr-4": { - "dW\\Lit\\": "lib/" + "MensBeam\\Lit\\": "lib/" } } } diff --git a/lib/Data.php b/lib/Data.php index ab2dbc7..c40e200 100644 --- a/lib/Data.php +++ b/lib/Data.php @@ -4,7 +4,7 @@ * See LICENSE file for details */ declare(strict_types=1); -namespace dW\Lit; +namespace MensBeam\Lit; class Data { diff --git a/lib/FauxReadOnly.php b/lib/FauxReadOnly.php index abf5ace..4024a8a 100644 --- a/lib/FauxReadOnly.php +++ b/lib/FauxReadOnly.php @@ -4,7 +4,7 @@ * See LICENSE file for details */ declare(strict_types=1); -namespace dW\Lit; +namespace MensBeam\Lit; trait FauxReadOnly { diff --git a/lib/Grammar.php b/lib/Grammar.php index acccf90..e2fdcc2 100644 --- a/lib/Grammar.php +++ b/lib/Grammar.php @@ -4,8 +4,8 @@ * See LICENSE file for details */ declare(strict_types=1); -namespace dW\Lit; -use dW\Lit\Grammar\{ +namespace MensBeam\Lit; +use MensBeam\Lit\Grammar\{ BaseReference, Exception, GrammarReference, diff --git a/lib/Grammar/BaseReference.php b/lib/Grammar/BaseReference.php index c48b3b0..a41196b 100644 --- a/lib/Grammar/BaseReference.php +++ b/lib/Grammar/BaseReference.php @@ -4,7 +4,7 @@ * See LICENSE file for details */ declare(strict_types=1); -namespace dW\Lit\Grammar; +namespace MensBeam\Lit\Grammar; /** * Base references in this implementation are simply used as a type. The diff --git a/lib/Grammar/Exception.php b/lib/Grammar/Exception.php index e43d662..59c2a04 100644 --- a/lib/Grammar/Exception.php +++ b/lib/Grammar/Exception.php @@ -4,7 +4,7 @@ * See LICENSE and AUTHORS files for details */ declare(strict_types=1); -namespace dW\Lit\Grammar; +namespace MensBeam\Lit\Grammar; class Exception extends \Exception { const INVALID_CODE = 100; diff --git a/lib/Grammar/GrammarReference.php b/lib/Grammar/GrammarReference.php index d066da2..e93a1f3 100644 --- a/lib/Grammar/GrammarReference.php +++ b/lib/Grammar/GrammarReference.php @@ -4,8 +4,8 @@ * See LICENSE file for details */ declare(strict_types=1); -namespace dW\Lit\Grammar; -use dW\Lit\{ +namespace MensBeam\Lit\Grammar; +use MensBeam\Lit\{ Grammar, GrammarRegistry }; diff --git a/lib/Grammar/Pattern.php b/lib/Grammar/Pattern.php index d54ea23..60eac22 100644 --- a/lib/Grammar/Pattern.php +++ b/lib/Grammar/Pattern.php @@ -4,7 +4,7 @@ * See LICENSE file for details */ declare(strict_types=1); -namespace dW\Lit\Grammar; +namespace MensBeam\Lit\Grammar; /** Contains patterns responsible for matching a portion of the document */ diff --git a/lib/Grammar/Reference.php b/lib/Grammar/Reference.php index 09c5c70..2208bed 100644 --- a/lib/Grammar/Reference.php +++ b/lib/Grammar/Reference.php @@ -4,8 +4,8 @@ * See LICENSE file for details */ declare(strict_types=1); -namespace dW\Lit\Grammar; -use dW\Lit\FauxReadOnly; +namespace MensBeam\Lit\Grammar; +use MensBeam\Lit\FauxReadOnly; /** Acts as a catch-all type for references */ diff --git a/lib/Grammar/RepositoryReference.php b/lib/Grammar/RepositoryReference.php index f967004..911a548 100644 --- a/lib/Grammar/RepositoryReference.php +++ b/lib/Grammar/RepositoryReference.php @@ -4,8 +4,8 @@ * See LICENSE file for details */ declare(strict_types=1); -namespace dW\Lit\Grammar; -use dW\Lit\GrammarRegistry; +namespace MensBeam\Lit\Grammar; +use MensBeam\Lit\GrammarRegistry; /** diff --git a/lib/Grammar/Rule.php b/lib/Grammar/Rule.php index 94e9acd..59632d6 100644 --- a/lib/Grammar/Rule.php +++ b/lib/Grammar/Rule.php @@ -4,8 +4,8 @@ * See LICENSE file for details */ declare(strict_types=1); -namespace dW\Lit\Grammar; -use dW\Lit\FauxReadOnly; +namespace MensBeam\Lit\Grammar; +use MensBeam\Lit\FauxReadOnly; /** * Abstract class used as a base class for Pattern and Reference classes diff --git a/lib/Grammar/SelfReference.php b/lib/Grammar/SelfReference.php index f808b1f..8440440 100644 --- a/lib/Grammar/SelfReference.php +++ b/lib/Grammar/SelfReference.php @@ -4,8 +4,8 @@ * See LICENSE file for details */ declare(strict_types=1); -namespace dW\Lit\Grammar; -use dW\Lit\{ +namespace MensBeam\Lit\Grammar; +use MensBeam\Lit\{ Grammar, GrammarRegistry }; diff --git a/lib/GrammarRegistry.php b/lib/GrammarRegistry.php index 1f4da8d..2013666 100644 --- a/lib/GrammarRegistry.php +++ b/lib/GrammarRegistry.php @@ -4,7 +4,7 @@ * See LICENSE file for details */ declare(strict_types=1); -namespace dW\Lit; +namespace MensBeam\Lit; /** Static storage for grammars; a map of a scope string and a Grammar object */ @@ -21,7 +21,7 @@ class GrammarRegistry { * Retrieves a grammar from the registry * * @param string $scopeName - The scope name (eg: text.html.php) of the grammar that is being requested - * @return dW\Lit\Grammar|false + * @return MensBeam\Lit\Grammar|false */ public static function get(string $scopeName): Grammar|false { if (array_key_exists($scopeName, self::$storage)) { @@ -43,7 +43,7 @@ class GrammarRegistry { * Sets a grammar in the registry. * * @param string $scopeName - The scope name (eg: text.html.php) of the grammar that is being set - * @param dW\Lit\Grammar - The grammar to be put into the registry + * @param MensBeam\Lit\Grammar - The grammar to be put into the registry */ public static function set(string $scopeName, Grammar $grammar) { self::$storage[$scopeName] = $grammar; diff --git a/lib/Highlight.php b/lib/Highlight.php index a3194f6..b7dc30d 100644 --- a/lib/Highlight.php +++ b/lib/Highlight.php @@ -4,8 +4,8 @@ * See LICENSE file for details */ declare(strict_types=1); -namespace dW\Lit; -use dW\Lit\Grammar\Exception; +namespace MensBeam\Lit; +use MensBeam\Lit\Grammar\Exception; class Highlight { diff --git a/lib/Scope/Composite.php b/lib/Scope/Composite.php index 8514698..504e3e2 100644 --- a/lib/Scope/Composite.php +++ b/lib/Scope/Composite.php @@ -4,7 +4,7 @@ * See LICENSE file for details */ declare(strict_types=1); -namespace dW\Lit\Scope; +namespace MensBeam\Lit\Scope; class Composite extends Node { protected array $_expressions = []; diff --git a/lib/Scope/Data.php b/lib/Scope/Data.php index 81a082c..9dc33fe 100644 --- a/lib/Scope/Data.php +++ b/lib/Scope/Data.php @@ -4,7 +4,7 @@ * See LICENSE file for details */ declare(strict_types=1); -namespace dW\Lit\Scope; +namespace MensBeam\Lit\Scope; /** * Tokenizes scope strings into an array of segments of the original string and diff --git a/lib/Scope/Expression.php b/lib/Scope/Expression.php index 95eb1eb..249d474 100644 --- a/lib/Scope/Expression.php +++ b/lib/Scope/Expression.php @@ -4,7 +4,7 @@ * See LICENSE file for details */ declare(strict_types=1); -namespace dW\Lit\Scope; +namespace MensBeam\Lit\Scope; class Expression extends Node { protected Filter|Group|Path $_child; diff --git a/lib/Scope/Filter.php b/lib/Scope/Filter.php index 97f95db..4683daf 100644 --- a/lib/Scope/Filter.php +++ b/lib/Scope/Filter.php @@ -4,7 +4,7 @@ * See LICENSE file for details */ declare(strict_types=1); -namespace dW\Lit\Scope; +namespace MensBeam\Lit\Scope; class Filter extends Node { protected Group|Path $_child; diff --git a/lib/Scope/Group.php b/lib/Scope/Group.php index 24fe0e9..d410452 100644 --- a/lib/Scope/Group.php +++ b/lib/Scope/Group.php @@ -4,7 +4,7 @@ * See LICENSE file for details */ declare(strict_types=1); -namespace dW\Lit\Scope; +namespace MensBeam\Lit\Scope; class Group extends Node { protected Selector $_child; diff --git a/lib/Scope/Node.php b/lib/Scope/Node.php index adc69cc..f7c8c77 100644 --- a/lib/Scope/Node.php +++ b/lib/Scope/Node.php @@ -4,8 +4,8 @@ * See LICENSE file for details */ declare(strict_types=1); -namespace dW\Lit\Scope; -use dW\Lit\FauxReadOnly; +namespace MensBeam\Lit\Scope; +use MensBeam\Lit\FauxReadOnly; class Node { use FauxReadOnly; diff --git a/lib/Scope/Parser.php b/lib/Scope/Parser.php index fc816d4..d26068a 100644 --- a/lib/Scope/Parser.php +++ b/lib/Scope/Parser.php @@ -4,7 +4,7 @@ * See LICENSE file for details */ declare(strict_types=1); -namespace dW\Lit\Scope; +namespace MensBeam\Lit\Scope; /** Parses strings into a scope selector */ class Parser { diff --git a/lib/Scope/ParserException.php b/lib/Scope/ParserException.php index e903b7a..6589afb 100644 --- a/lib/Scope/ParserException.php +++ b/lib/Scope/ParserException.php @@ -4,7 +4,7 @@ * See LICENSE file for details */ declare(strict_types=1); -namespace dW\Lit\Scope; +namespace MensBeam\Lit\Scope; class ParserException extends \Exception { const MESSAGE = '%s expected; found %s at offset %s'.\PHP_EOL; diff --git a/lib/Scope/Path.php b/lib/Scope/Path.php index 06ff378..f9ca751 100644 --- a/lib/Scope/Path.php +++ b/lib/Scope/Path.php @@ -4,7 +4,7 @@ * See LICENSE file for details */ declare(strict_types=1); -namespace dW\Lit\Scope; +namespace MensBeam\Lit\Scope; class Path extends Node { protected int $_anchor; diff --git a/lib/Scope/Scope.php b/lib/Scope/Scope.php index dbe901c..7cc85c0 100644 --- a/lib/Scope/Scope.php +++ b/lib/Scope/Scope.php @@ -4,7 +4,7 @@ * See LICENSE file for details */ declare(strict_types=1); -namespace dW\Lit\Scope; +namespace MensBeam\Lit\Scope; class Scope extends Node { protected bool $_anchorToPrevious; diff --git a/lib/Scope/Selector.php b/lib/Scope/Selector.php index 2120d6c..07d2489 100644 --- a/lib/Scope/Selector.php +++ b/lib/Scope/Selector.php @@ -4,7 +4,7 @@ * See LICENSE file for details */ declare(strict_types=1); -namespace dW\Lit\Scope; +namespace MensBeam\Lit\Scope; class Selector extends Node { protected array $_composites = []; diff --git a/lib/Tokenizer.php b/lib/Tokenizer.php index 221fc6a..ba62e25 100644 --- a/lib/Tokenizer.php +++ b/lib/Tokenizer.php @@ -4,14 +4,14 @@ * See LICENSE file for details */ declare(strict_types=1); -namespace dW\Lit; -use dW\Lit\Grammar\{ +namespace MensBeam\Lit; +use MensBeam\Lit\Grammar\{ BaseReference, Pattern, Reference, RepositoryReference }; -use dW\Lit\Scope\{ +use MensBeam\Lit\Scope\{ Filter, Parser as ScopeParser };