Browse Source

Changed Project name to Fukkus

main
Dustin Wilson 3 years ago
parent
commit
e2dcac2bf4
  1. 7
      README
  2. 27
      lib/Grammar/Data.php
  3. 4
      lib/Grammar/Registry.php
  4. 9
      lib/Grammar/Tokenizer.php
  5. 14
      lib/Highlighter.php
  6. 2
      lib/Scope/Data.php
  7. 6
      lib/Scope/Exception.php
  8. 2
      lib/Scope/Matcher.php
  9. 2
      lib/Scope/Matchers/AndMatcher.php
  10. 2
      lib/Scope/Matchers/GroupMatcher.php
  11. 2
      lib/Scope/Matchers/NegateMatcher.php
  12. 2
      lib/Scope/Matchers/OrMatcher.php
  13. 2
      lib/Scope/Matchers/PathMatcher.php
  14. 2
      lib/Scope/Matchers/ScopeMatcher.php
  15. 2
      lib/Scope/Parser.php

7
README

@ -0,0 +1,7 @@
[a]: https://atom.io
[b]: https://github.com/atom/highlights
[c]: https://macromates.com
# Fukkus #
Fukkus is a multilanguage syntax highlighter written in PHP. It takes code as input and returns HTML with classes based upon tokens in the code. It is loosely based upon [Atom][a]'s [Highlights][b] which is used in the Atom text editor to syntax highlight code. Atom's Highlights is in turn based upon [TextMate][c]'s syntax highlighting using its concepts of scope selectors and common classes for components of programming languages.

27
lib/Grammar/Data.php

@ -0,0 +1,27 @@
<?php
/** @license MIT
* Copyright 2021 Dustin Wilson et al.
* See LICENSE and AUTHORS files for details */
declare(strict_types=1);
namespace dW\Fukkus\Grammar;
class Data {
public static function withFile(string $filepath): \Generator {
$fp = fopen($filepath, 'r');
try {
while ($line = fgets($fp)) {
yield $line;
}
} finally {
fclose($fp);
}
}
public static function withString(string $data): \Generator {
$data = explode("\n", $data);
foreach ($data as $d) {
yield $d;
}
}
}

4
lib/Grammar/Registry.php

@ -4,7 +4,7 @@
* See LICENSE and AUTHORS files for details */
declare(strict_types=1);
namespace dW\Highlighter\Grammar;
namespace dW\Fukkus\Grammar;
class Registry {
protected static array $grammars = [];
@ -49,7 +49,7 @@ class Registry {
}
if (!$force && isset(self::$grammars[$grammar['scopeName']])) {
throw new \Exception("Grammar \"{$grammar['scopeName']}\" already exists.");
throw new \Exception("Grammar with the \"{$grammar['scopeName']}\" scope already exists.");
}
self::$grammars[$grammar['scopeName']] = $grammar;

9
lib/Grammar/Tokenizer.php

@ -0,0 +1,9 @@
<?php
/** @license MIT
* Copyright 2021 Dustin Wilson et al.
* See LICENSE and AUTHORS files for details */
declare(strict_types=1);
namespace dW\Fukkus\Grammar;
class Tokenizer {}

14
lib/Highlighter.php

@ -0,0 +1,14 @@
<?php
/** @license MIT
* Copyright 2021 Dustin Wilson et al.
* See LICENSE and AUTHORS files for details */
declare(strict_types=1);
namespace dW\Fukkus;
class Highlighter {
public static function highlightString(string $string): string {
$data = Grammar\Data::fromString($string);
}
}

2
lib/Scope/Data.php

@ -4,7 +4,7 @@
* See LICENSE and AUTHORS files for details */
declare(strict_types=1);
namespace dW\Highlighter\Scope;
namespace dW\Fukkus\Scope;
/**
* Tokenizes scope strings into an array of segments of the original string and

6
lib/Scope/Exception.php

@ -4,10 +4,10 @@
* See LICENSE and AUTHORS files for details */
declare(strict_types=1);
namespace dW\Highlighter\Scope;
namespace dW\Fukkus\Scope;
class Exception extends \Exception {
const MESSAGE = '%s expected; found %s at offset %s';
const MESSAGE = "%s expected; found %s at offset %s\n";
public function __construct(array|string $expected, string|bool $found, int $offset) {
if (!is_string($expected)) {
@ -28,6 +28,8 @@ class Exception extends \Exception {
$expected = implode(' or ', $expected);
}
}
} else {
$expected = ($expected !== false) ? $expected : 'end of input';
}
$found = ($found !== false) ? "\"$found\"" : 'end of input';

2
lib/Scope/Matcher.php

@ -4,6 +4,6 @@
* See LICENSE and AUTHORS files for details */
declare(strict_types=1);
namespace dW\Highlighter\Scope;
namespace dW\Fukkus\Scope;
abstract class Matcher {}

2
lib/Scope/Matchers/AndMatcher.php

@ -4,7 +4,7 @@
* See LICENSE and AUTHORS files for details */
declare(strict_types=1);
namespace dW\Highlighter\Scope;
namespace dW\Fukkus\Scope;
class AndMatcher extends Matcher {
protected array $matchers = [];

2
lib/Scope/Matchers/GroupMatcher.php

@ -4,7 +4,7 @@
* See LICENSE and AUTHORS files for details */
declare(strict_types=1);
namespace dW\Highlighter\Scope;
namespace dW\Fukkus\Scope;
class GroupMatcher extends Matcher {
protected string|null $prefix;

2
lib/Scope/Matchers/NegateMatcher.php

@ -4,7 +4,7 @@
* See LICENSE and AUTHORS files for details */
declare(strict_types=1);
namespace dW\Highlighter\Scope;
namespace dW\Fukkus\Scope;
class NegateMatcher extends Matcher {
protected Matcher $matcher;

2
lib/Scope/Matchers/OrMatcher.php

@ -4,7 +4,7 @@
* See LICENSE and AUTHORS files for details */
declare(strict_types=1);
namespace dW\Highlighter\Scope;
namespace dW\Fukkus\Scope;
class OrMatcher extends Matcher {
protected array $matchers = [];

2
lib/Scope/Matchers/PathMatcher.php

@ -4,7 +4,7 @@
* See LICENSE and AUTHORS files for details */
declare(strict_types=1);
namespace dW\Highlighter\Scope;
namespace dW\Fukkus\Scope;
class PathMatcher extends Matcher {
protected string|null $prefix;

2
lib/Scope/Matchers/ScopeMatcher.php

@ -4,7 +4,7 @@
* See LICENSE and AUTHORS files for details */
declare(strict_types=1);
namespace dW\Highlighter\Scope;
namespace dW\Fukkus\Scope;
class ScopeMatcher extends Matcher {
protected array $segments;

2
lib/Scope/Parser.php

@ -4,7 +4,7 @@
* See LICENSE and AUTHORS files for details */
declare(strict_types=1);
namespace dW\Highlighter\Scope;
namespace dW\Fukkus\Scope;
/** Parses scope strings into a matcher tree */
class Parser {

Loading…
Cancel
Save