Browse Source

Changed namespace

main
Dustin Wilson 3 years ago
parent
commit
22c6614c76
  1. 50
      README.md
  2. 7
      composer.json
  3. 2
      lib/Data.php
  4. 2
      lib/FauxReadOnly.php
  5. 4
      lib/Grammar.php
  6. 2
      lib/Grammar/BaseReference.php
  7. 2
      lib/Grammar/Exception.php
  8. 4
      lib/Grammar/GrammarReference.php
  9. 2
      lib/Grammar/Pattern.php
  10. 4
      lib/Grammar/Reference.php
  11. 4
      lib/Grammar/RepositoryReference.php
  12. 4
      lib/Grammar/Rule.php
  13. 4
      lib/Grammar/SelfReference.php
  14. 6
      lib/GrammarRegistry.php
  15. 4
      lib/Highlight.php
  16. 2
      lib/Scope/Composite.php
  17. 2
      lib/Scope/Data.php
  18. 2
      lib/Scope/Expression.php
  19. 2
      lib/Scope/Filter.php
  20. 2
      lib/Scope/Group.php
  21. 4
      lib/Scope/Node.php
  22. 2
      lib/Scope/Parser.php
  23. 2
      lib/Scope/ParserException.php
  24. 2
      lib/Scope/Path.php
  25. 2
      lib/Scope/Scope.php
  26. 2
      lib/Scope/Selector.php
  27. 6
      lib/Tokenizer.php

50
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);
```

7
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/"
}
}
}

2
lib/Data.php

@ -4,7 +4,7 @@
* See LICENSE file for details */
declare(strict_types=1);
namespace dW\Lit;
namespace MensBeam\Lit;
class Data {

2
lib/FauxReadOnly.php

@ -4,7 +4,7 @@
* See LICENSE file for details */
declare(strict_types=1);
namespace dW\Lit;
namespace MensBeam\Lit;
trait FauxReadOnly {

4
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,

2
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

2
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;

4
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
};

2
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 */

4
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 */

4
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;
/**

4
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

4
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
};

6
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;

4
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 {

2
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 = [];

2
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

2
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;

2
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;

2
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;

4
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;

2
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 {

2
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;

2
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;

2
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;

2
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 = [];

6
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
};

Loading…
Cancel
Save