Skip to content

Commit 0aa2a82

Browse files
committed
- Updated to phug/util:0.3.5
1 parent 95113d4 commit 0aa2a82

3 files changed

Lines changed: 30 additions & 27 deletions

File tree

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
},
2626
"require-dev": {
2727
"phug/dev-tool": "^0.1.0",
28-
"phug/util": "^0.2.0"
28+
"phug/util": "^0.3.5"
2929
},
3030
"autoload": {
3131
"psr-4": {

src/Phug/Reader.php

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Phug;
44

5+
use Phug\Util\SourceLocation;
6+
57
/**
68
* A string reading utility that searches strings byte by byte.
79
*/
@@ -17,7 +19,7 @@ class Reader
1719
PREG_INTERNAL_ERROR => 'An internal error occured',
1820
PREG_BACKTRACK_LIMIT_ERROR => 'The backtrack limit was exhausted (Increase pcre.backtrack_limit in php.ini)',
1921
PREG_RECURSION_LIMIT_ERROR => 'Recursion limit was exhausted (Increase pcre.recursion_limit in php.ini)',
20-
PREG_BAD_UTF8_ERROR => 'Bad UTF8 error!',
22+
PREG_BAD_UTF8_ERROR => 'Bad UTF8 error',
2123
PREG_BAD_UTF8_OFFSET_ERROR => 'Bad UTF8 offset error',
2224
];
2325

@@ -274,7 +276,7 @@ public function peek($length = null, $start = null)
274276
$this->nextConsumeLength = null;
275277

276278
if (!$this->hasLength()) {
277-
return;
279+
return null;
278280
}
279281

280282
$length = $length !== null ? $length : 1;
@@ -451,7 +453,7 @@ public function readWhile($callback, $peekLength = null)
451453
}
452454

453455
if (!$this->hasLength()) {
454-
return;
456+
return null;
455457
}
456458

457459
if ($peekLength === null) {
@@ -635,7 +637,7 @@ public function peekIdentifier(array $allowedChars = null)
635637
public function readIndentation()
636638
{
637639
if (!$this->peekIndentation()) {
638-
return;
640+
return null;
639641
}
640642

641643
return $this->readWhile([$this, 'peekIndentation']);
@@ -659,7 +661,7 @@ public function readUntilNewLine()
659661
public function readSpaces()
660662
{
661663
if (!$this->peekSpace()) {
662-
return;
664+
return null;
663665
}
664666

665667
return $this->readWhile('ctype_space');
@@ -673,7 +675,7 @@ public function readSpaces()
673675
public function readDigits()
674676
{
675677
if (!$this->peekDigit()) {
676-
return;
678+
return null;
677679
}
678680

679681
return $this->readWhile('ctype_digit');
@@ -687,7 +689,7 @@ public function readDigits()
687689
public function readAlpha()
688690
{
689691
if (!$this->peekAlpha()) {
690-
return;
692+
return null;
691693
}
692694

693695
return $this->readWhile('ctype_alpha');
@@ -701,7 +703,7 @@ public function readAlpha()
701703
public function readAlphaNumeric()
702704
{
703705
if (!$this->peekAlphaNumeric()) {
704-
return;
706+
return null;
705707
}
706708

707709
return $this->readWhile('ctype_alnum');
@@ -721,12 +723,12 @@ public function readIdentifier($prefix = null, $allowedChars = null)
721723
{
722724
if ($prefix) {
723725
if ($this->peek(mb_strlen($prefix)) !== $prefix) {
724-
return;
726+
return null;
725727
}
726728

727729
$this->consume();
728730
} elseif (!$this->peekAlphaIdentifier($allowedChars)) {
729-
return;
731+
return null;
730732
}
731733

732734
return $this->readWhile(function () use ($allowedChars) {
@@ -750,7 +752,7 @@ public function readIdentifier($prefix = null, $allowedChars = null)
750752
public function readString(array $escapeSequences = null, $raw = false)
751753
{
752754
if (!$this->peekQuote()) {
753-
return;
755+
return null;
754756
}
755757

756758
$quoteStyle = $this->consume();
@@ -813,7 +815,7 @@ public function readString(array $escapeSequences = null, $raw = false)
813815
public function readExpression(array $breaks = null, array $brackets = null)
814816
{
815817
if (!$this->hasLength()) {
816-
return;
818+
return null;
817819
}
818820

819821
$breaks = $breaks ?: [];
@@ -898,19 +900,22 @@ protected function getPregErrorText($code = null)
898900
* Throws an exception that contains useful debugging information.
899901
*
900902
* @param string $message the message to pass to the exception.
903+
*
904+
* @throws ReaderException
901905
*/
902906
protected function throwException($message)
903907
{
904-
$exception = new ReaderException(sprintf(
905-
"Failed to read: %s \nNear: %s \nLine: %s \nOffset: %s \nPosition: %s",
906-
$message,
907-
$this->peek(20),
908-
$this->line,
909-
$this->offset,
910-
$this->position
911-
));
912-
$exception->setPugLine($this->line);
913-
$exception->setPugOffset($this->offset);
908+
$exception = new ReaderException(
909+
new SourceLocation(null, $this->line, $this->offset),
910+
sprintf(
911+
"Failed to read: %s \nNear: %s \nLine: %s \nOffset: %s \nPosition: %s",
912+
$message,
913+
$this->peek(20),
914+
$this->line,
915+
$this->offset,
916+
$this->position
917+
)
918+
);
914919

915920
throw $exception;
916921
}

src/Phug/ReaderException.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@
22

33
namespace Phug;
44

5-
use Phug\Util\Partial\PugFileLocationTrait;
6-
use Phug\Util\PugFileLocationInterface;
5+
use Phug\Util\Exception\LocatedException;
76

87
/**
98
* An exception thrown by the pug reader.
109
*/
11-
class ReaderException extends \RuntimeException implements PugFileLocationInterface
10+
class ReaderException extends LocatedException
1211
{
13-
use PugFileLocationTrait;
1412
}

0 commit comments

Comments
 (0)