-
-
Notifications
You must be signed in to change notification settings - Fork 466
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial implementation of inclusive ranges and exclusive ranges
- Loading branch information
1 parent
7835713
commit a1d1fea
Showing
17 changed files
with
330 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
|
||
/* | ||
+--------------------------------------------------------------------------+ | ||
| Zephir Language | | ||
+--------------------------------------------------------------------------+ | ||
| Copyright (c) 2013-2014 Zephir Team and contributors | | ||
+--------------------------------------------------------------------------+ | ||
| This source file is subject the MIT license, that is bundled with | | ||
| this package in the file LICENSE, and is available through the | | ||
| world-wide-web at the following url: | | ||
| http://zephir-lang.com/license.html | | ||
| | | ||
| If you did not receive a copy of the MIT license and are unable | | ||
| to obtain it through the world-wide-web, please send a note to | | ||
| [email protected] so we can mail you a copy immediately. | | ||
+--------------------------------------------------------------------------+ | ||
*/ | ||
|
||
namespace Zephir\Builder\Operators; | ||
|
||
use Zephir\Builder\Operators\AbstractOperatorBuilder; | ||
|
||
/** | ||
* CastOperatorBuilder | ||
* | ||
* Allows to manually build a 'cast' operator AST node | ||
*/ | ||
class CastOperatorBuilder extends AbstractOperatorBuilder | ||
{ | ||
protected $leftOperand; | ||
|
||
protected $rightOperand; | ||
|
||
/** | ||
* @param $left | ||
* @param $right | ||
* @param null $file | ||
* @param int $line | ||
* @param int $char | ||
*/ | ||
public function __construct($left, $right, $file = null, $line = 0, $char = 0) | ||
{ | ||
$this->leftOperand = $left; | ||
$this->rightOperand = $right; | ||
$this->file = $file; | ||
$this->line = $line; | ||
$this->char = $char; | ||
} | ||
|
||
/** | ||
* Returns a builder definition | ||
* | ||
* @return array | ||
*/ | ||
public function get() | ||
{ | ||
return array( | ||
'type' => 'cast', | ||
'left' => $this->leftOperand, | ||
'right' => $this->rightOperand->get(), | ||
'file' => $this->file, | ||
'line' => $this->line, | ||
'char' => $this->char | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
|
||
/* | ||
+--------------------------------------------------------------------------+ | ||
| Zephir Language | | ||
+--------------------------------------------------------------------------+ | ||
| Copyright (c) 2013-2014 Zephir Team and contributors | | ||
+--------------------------------------------------------------------------+ | ||
| This source file is subject the MIT license, that is bundled with | | ||
| this package in the file LICENSE, and is available through the | | ||
| world-wide-web at the following url: | | ||
| http://zephir-lang.com/license.html | | ||
| | | ||
| If you did not receive a copy of the MIT license and are unable | | ||
| to obtain it through the world-wide-web, please send a note to | | ||
| [email protected] so we can mail you a copy immediately. | | ||
+--------------------------------------------------------------------------+ | ||
*/ | ||
|
||
namespace Zephir\Operators\Other; | ||
|
||
use Zephir\Operators\BaseOperator; | ||
use Zephir\CompilationContext; | ||
use Zephir\Expression; | ||
use Zephir\CompilerException; | ||
use Zephir\CompiledExpression; | ||
use Zephir\Builder\FunctionCallBuilder; | ||
use Zephir\Builder\Operators\CastOperatorBuilder; | ||
|
||
/** | ||
* RangeInclusive | ||
* | ||
* Inclusive range operator | ||
*/ | ||
class RangeInclusiveOperator extends BaseOperator | ||
{ | ||
/** | ||
* @param array $expression | ||
* @param CompilationContext $compilationContext | ||
* @return CompiledExpression | ||
* @throws CompilerException | ||
*/ | ||
public function compile(array $expression, CompilationContext $compilationContext) | ||
{ | ||
|
||
if (!isset($expression['left'])) { | ||
throw new CompilerException("Invalid 'left' operand for 'irange' expression", $expression['left']); | ||
} | ||
|
||
if (!isset($expression['right'])) { | ||
throw new CompilerException("Invalid 'right' operand for 'irange' expression", $expression['right']); | ||
} | ||
|
||
$builder = new FunctionCallBuilder('range', array( | ||
array('parameter' => $expression['left']), | ||
array('parameter' => $expression['right']) | ||
)); | ||
|
||
/** | ||
* Implicit type coercing | ||
*/ | ||
$castBuilder = new CastOperatorBuilder('array', $builder); | ||
|
||
$expression = new Expression($castBuilder->get()); | ||
$expression->setReadOnly($this->_readOnly); | ||
return $expression->compile($compilationContext); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.