Commit ee638970 authored by Pietro Saccardi's avatar Pietro Saccardi

Bugfix: exception is thrown with no token knownledge.

parent 47bcc606
......@@ -54,22 +54,16 @@ class InvalidExpressionException extends Exception {
class NotEnoughArgumentsException extends Exception {
private $_elementDefinition = null;
private $_firstTokenInstance = null;
public function __construct($elementDefinition, $firstTokenInstance, $code = 0, Exception $previous = null) {
public function __construct($elementDefinition, $code = 0, Exception $previous = null) {
$this->_elementDefinition = $elementDefinition;
$this->_firstTokenInstance = $firstTokenInstance;
$message = 'Not enough arguments for operator ' . $elementDefinition->name()
. ' encountered at position ' . $firstTokenInstance->position() . ', around "'
. substr($firstTokenInstance->text(), max(0, $firstTokenInstance->position() - 3), $firstTokenInstance->length() + 3)
. '".';
$message = 'Not enough arguments for operator ' . $elementDefinition->name() . '.';
if ($elementDefinition->arity() > 0) {
$message .= ' Expected ' . $elementDefinition->arity() . ' arguments.';
}
parent::__construct($message, $code, $previous);
}
public function getFirstTokenInstance() { return $this->_firstTokenInstance; }
public function getElementDefinition() { return $this->_elementDefinition; }
public function __toString() {
......
......@@ -385,7 +385,7 @@ class ElementDefinition {
$elmArgs = self::_extractAlternateChain($args, $firstTokPosition + 1, $chainLength);
$elmInst = new ElementInstance($definition, $elmArgs);
if ($firstTokPosition + $chainLength * 2 > count($args)) {
throw new NotEnoughArgumentsException($definition, $args[$firstTokPosition]);
throw new NotEnoughArgumentsException($definition);
}
array_splice($args, $firstTokPosition, $chainLength * 2, array($elmInst));
return $firstTokPosition;
......@@ -398,9 +398,9 @@ class ElementDefinition {
$elmArgs = self::_extractAlternateChain($args, $firstTokPosition - 1, $chainLength);
$elmInst = new ElementInstance($definition, $elmArgs);
if ($firstTokPosition == 0) {
throw new NotEnoughArgumentsException($definition, $args[$firstTokPosition]);
throw new NotEnoughArgumentsException($definition);
} elseif ($firstTokPosition + $chainLength * 2 - 1 > count($args)) {
throw new NotEnoughArgumentsException($definition, $args[$firstTokPosition - 1]);
throw new NotEnoughArgumentsException($definition);
}
array_splice($args, $firstTokPosition - 1, $chainLength * 2, array($elmInst));
return $firstTokPosition - 1;
......@@ -413,9 +413,9 @@ class ElementDefinition {
$elmArgs = self::_extractAlternateChain($args, $firstTokPosition - 1, $chainLength + 1);
$elmInst = new ElementInstance($definition, $elmArgs);
if ($firstTokPosition == 0) {
throw new NotEnoughArgumentsException($definition, $args[$firstTokPosition]);
throw new NotEnoughArgumentsException($definition);
} elseif ($firstTokPosition + $chainLength * 2 > count($args)) {
throw new NotEnoughArgumentsException($definition, $args[$firstTokPosition - 1]);
throw new NotEnoughArgumentsException($definition);
}
array_splice($args, $firstTokPosition - 1, $chainLength * 2 + 1, array($elmInst));
return $firstTokPosition - 1;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment