Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added Variable node support.

  • Loading branch information...
commit afd2223ea725dbc797df7787051e86ae0301bb05 1 parent bb7982f
@jmalloc jmalloc authored
View
4 composer.lock
@@ -8,8 +8,8 @@
{
"package": "icecave/pasta-ast",
"version": "dev-master",
- "source-reference": "905385f758726fdf2a6db8e894e9de4cfc0b0427",
- "commit-date": "1344332929"
+ "source-reference": "f5a4553bb1f10c9b9dc893cb9cea9bc1ed7fa78e",
+ "commit-date": "1344340362"
},
{
"package": "icecave/visita",
View
10 lib/Icecave/Rasta/Generator.php
@@ -10,10 +10,10 @@
use Icecave\Pasta\AST\FunctionDefinition;
use Icecave\Pasta\AST\FunctionInterface;
use Icecave\Pasta\AST\FunctionParameter;
+use Icecave\Pasta\AST\IStatement;
use Icecave\Pasta\AST\IVisitor;
use Icecave\Pasta\AST\IfStatement;
use Icecave\Pasta\AST\InterfaceDefinition;
-use Icecave\Pasta\AST\IStatement;
use Icecave\Pasta\AST\Literal;
use Icecave\Pasta\AST\Node;
use Icecave\Pasta\AST\Operator\BinaryOperator;
@@ -29,8 +29,9 @@
use Icecave\Pasta\AST\PhpBlock;
use Icecave\Pasta\AST\QualifiedName;
use Icecave\Pasta\AST\ReturnStatement;
-use Icecave\Pasta\AST\StatementBlock;
use Icecave\Pasta\AST\Root;
+use Icecave\Pasta\AST\StatementBlock;
+use Icecave\Pasta\AST\Variable;
class Generator implements IVisitor
{
@@ -234,6 +235,11 @@ public function visitStatementBlock(StatementBlock $node)
return $code;
}
+ public function visitVariable(Variable $node)
+ {
+ return '$' . $node->name();
+ }
+
// Operators ...
public function visitEquals(Equals $node)
View
13 test/suite/Icecave/Rasta/GeneratorTest.php
@@ -23,8 +23,10 @@
use Icecave\Pasta\AST\PhpBlock;
use Icecave\Pasta\AST\QualifiedName;
use Icecave\Pasta\AST\ReturnStatement;
-use Icecave\Pasta\AST\StatementBlock;
use Icecave\Pasta\AST\Root;
+use Icecave\Pasta\AST\StatementBlock;
+use Icecave\Pasta\AST\Variable;
+
use PHPUnit_Framework_TestCase;
class GeneratorTest extends PHPUnit_Framework_TestCase
@@ -480,6 +482,15 @@ public function testVisitLiteral()
$this->assertSame($expected, $code);
}
+ public function testVisitVariable()
+ {
+ $node = new Variable('thing');
+ $code = $this->_generator->visitVariable($node);
+
+ $expected = '$thing';
+ $this->assertSame($expected, $code);
+ }
+
public function testVisitEquals()
{
$node = new Equals(new Literal(123), new Literal(456));
Please sign in to comment.
Something went wrong with that request. Please try again.