Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
665 changes: 661 additions & 4 deletions README.md

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions src/V2/Exceptions/EmptyStreamException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace Smoren\FormulaTools\V2\Exceptions;

class EmptyStreamException extends UnexpectedEofException
{
public function __construct()
{
parent::__construct('Cannot parse an empty stream', null);
}
}
13 changes: 13 additions & 0 deletions src/V2/Exceptions/MissingOperandException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace Smoren\FormulaTools\V2\Exceptions;

class MissingOperandException extends UnexpectedEofException
{
public function __construct()
{
parent::__construct('Unexpected end of input; expecting a value', null);
}
}
24 changes: 24 additions & 0 deletions src/V2/Exceptions/MissingOperatorException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

namespace Smoren\FormulaTools\V2\Exceptions;

class MissingOperatorException extends SyntaxException
{
/**
* @readonly
* @var mixed
*/
public $found;

/**
* @param mixed $token
* @param int $position
*/
public function __construct($token, int $position)
{
parent::__construct("Expected an operator, found {$this->stringify($token)}", $position);
$this->found = $token;
}
}
19 changes: 19 additions & 0 deletions src/V2/Exceptions/OpAssociationException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

declare(strict_types=1);

namespace Smoren\FormulaTools\V2\Exceptions;

use Smoren\FormulaTools\V2\Interfaces\IOpDefinition;

class OpAssociationException extends SyntaxException
{
/** @readonly */
public IOpDefinition $op;

public function __construct(IOpDefinition $op, int $position)
{
parent::__construct('Operator `' . get_class($op) . '` is non-associative', $position);
$this->op = $op;
}
}
34 changes: 34 additions & 0 deletions src/V2/Exceptions/SyntaxException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

declare(strict_types=1);

namespace Smoren\FormulaTools\V2\Exceptions;

class SyntaxException extends \ErrorException
{
/** @readonly */
public ?int $position;

public function __construct(string $msg, ?int $position)
{
$this->position = $position;
if ($position !== null) {
$position++;
$msg = "Token #$position: $msg";
}
parent::__construct($msg);
}

/**
* @param mixed $x
* @return string
*/
protected function stringify($x): string
{
return json_encode(
$x,
JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE |
JSON_INVALID_UTF8_SUBSTITUTE | JSON_THROW_ON_ERROR,
);
}
}
13 changes: 13 additions & 0 deletions src/V2/Exceptions/UnclosedBracketException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace Smoren\FormulaTools\V2\Exceptions;

class UnclosedBracketException extends UnexpectedEofException
{
public function __construct()
{
parent::__construct('Unexpected end of input; a bracket is not closed', null);
}
}
9 changes: 9 additions & 0 deletions src/V2/Exceptions/UnexpectedEofException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

declare(strict_types=1);

namespace Smoren\FormulaTools\V2\Exceptions;

class UnexpectedEofException extends SyntaxException
{
}
Loading