diff options
author | Ivan Enderlin <ivan.enderlin@hoa-project.net> | 2013-04-16 16:15:55 +0200 |
---|---|---|
committer | Ivan Enderlin <ivan.enderlin@hoa-project.net> | 2013-04-16 16:15:55 +0200 |
commit | a47252b81b7f6cb207b27fb4ae3f290d0496c3ea (patch) | |
tree | f5a1675595d9a04224376c2d67ca00dad0b58420 /Visitor | |
parent | c2c368e07a224f7817c033e9a9761ff0241d76ae (diff) | |
download | Praspel-a47252b81b7f6cb207b27fb4ae3f290d0496c3ea.zip Praspel-a47252b81b7f6cb207b27fb4ae3f290d0496c3ea.tar.gz Praspel-a47252b81b7f6cb207b27fb4ae3f290d0496c3ea.tar.bz2 |
Introduce collection of clauses.
Clauses can have variables, so that they extend Declaration. But a
specification or a behavior can have a collection of other clauses, such
as a collection of behavior, represented by an identifier.
To build a collection of clauses, we need to instance the Collection
class with a preset clause and post-clone function. For each new offset
in the collection, the associated value is a clone from the preset
clause with the post-clone function applied on this clone. This
mechanism allows us to build modular collection of clauses.
Diffstat (limited to 'Visitor')
-rw-r--r-- | Visitor/Compiler.php | 7 | ||||
-rw-r--r-- | Visitor/Interpreter.php | 9 |
2 files changed, 10 insertions, 6 deletions
diff --git a/Visitor/Compiler.php b/Visitor/Compiler.php index 2d606d8..852bd1f 100644 --- a/Visitor/Compiler.php +++ b/Visitor/Compiler.php @@ -164,8 +164,8 @@ class Compiler implements \Hoa\Visitor\Visit { $identifier = $element->getIdentifier(); $out = "\n" . $variable . ' = ' . $parent . - '->getClause(\'behavior\');' . "\n" . - $variable . '->setIdentifier(\'' . $identifier . '\');' . "\n"; + '->getClause(\'behavior\')' . + '->get(\'' . $identifier . '\');' . "\n"; $clauses = array( 'invariant', 'requires', @@ -195,6 +195,9 @@ class Compiler implements \Hoa\Visitor\Visit { preg_replace('#(?<!\\\)\'#', '\\\'', $example) . '\';' . "\n"; } + elseif($element instanceof \Hoa\Praspel\Model\Collection) + foreach($element as $el) + $out .= $el->accept($this, $handle, $eldnah); else throw new \Hoa\Core\Exception( '%s is not yet implemented.', 0, get_class($element)); diff --git a/Visitor/Interpreter.php b/Visitor/Interpreter.php index fb3948e..22a03b6 100644 --- a/Visitor/Interpreter.php +++ b/Visitor/Interpreter.php @@ -149,12 +149,13 @@ class Interpreter implements \Hoa\Visitor\Visit { case '#behavior': $children = $element->getChildren(); $child0 = array_shift($children); + $identifier = $child0->accept($this, $handle, false); $previous = $this->_current; + $this->_clause = $this->_current - = $this->_current->getClause('behavior'); - $this->_clause->setIdentifier( - $child0->accept($this, $handle, false) - ); + = $this->_current + ->getClause('behavior') + ->get($identifier); foreach($children as $child) $child->accept($this, $handle, $eldnah); |