aboutsummaryrefslogtreecommitdiffstats
path: root/Visitor
diff options
context:
space:
mode:
authorIvan Enderlin <ivan.enderlin@hoa-project.net>2013-06-10 14:58:35 +0200
committerIvan Enderlin <ivan.enderlin@hoa-project.net>2013-06-10 14:58:35 +0200
commit467d39b9047547ff94a37fdcb8805623ef09d542 (patch)
tree9fbb23471e3718c35546d4b6ff0a1e959a18459d /Visitor
parentd2f8208f2951691b550d912b5f725d2371af9e9a (diff)
downloadPraspel-467d39b9047547ff94a37fdcb8805623ef09d542.zip
Praspel-467d39b9047547ff94a37fdcb8805623ef09d542.tar.gz
Praspel-467d39b9047547ff94a37fdcb8805623ef09d542.tar.bz2
Add the @default clause!
The default clause represents a default/else behavior.
Diffstat (limited to 'Visitor')
-rw-r--r--Visitor/Compiler.php27
-rw-r--r--Visitor/Interpreter.php13
-rw-r--r--Visitor/Praspel.php19
3 files changed, 52 insertions, 7 deletions
diff --git a/Visitor/Compiler.php b/Visitor/Compiler.php
index d20b61c..40a835d 100644
--- a/Visitor/Compiler.php
+++ b/Visitor/Compiler.php
@@ -183,15 +183,28 @@ class Compiler implements \Hoa\Visitor\Visit {
$exception->getDisjunction() . '\');' . "\n";
}
}
+ elseif($element instanceof \Hoa\Praspel\Model\DefaultBehavior) {
+
+ $out = "\n" .
+ '$' . $element->getId() . ' = $' .
+ $element->getParent()->getId() .
+ '->getClause(\'default\')' . "\n";
+
+ foreach($element::getAllowedClauses() as $clause)
+ if(true === $element->clauseExists($clause))
+ $out .= $element->getClause($clause)->accept(
+ $this,
+ $handle,
+ $eldnah
+ );
+ }
elseif($element instanceof \Hoa\Praspel\Model\Behavior) {
- $parent = '$' . $element->getParent()->getId();
- $variable = '$' . $element->getId();
- $identifier = $element->getIdentifier();
- $out = "\n" .
- $variable . ' = ' . $parent .
- '->getClause(\'behavior\')' .
- '->get(\'' . $identifier . '\');' . "\n";
+ $out = "\n" .
+ '$' . $element->getId() . ' = $' .
+ $element->getParent()->getId() .
+ '->getClause(\'behavior\')' .
+ '->get(\'' . $element->getIdentifier() . '\');' . "\n";
foreach($element::getAllowedClauses() as $clause)
if(true === $element->clauseExists($clause))
diff --git a/Visitor/Interpreter.php b/Visitor/Interpreter.php
index 4337740..d396e04 100644
--- a/Visitor/Interpreter.php
+++ b/Visitor/Interpreter.php
@@ -162,6 +162,19 @@ class Interpreter implements \Hoa\Visitor\Visit {
$this->_current = $previous;
break;
+ case '#default':
+ $children = $element->getChildren();
+ $previous = $this->_current;
+ $this->_clause = $this->_current
+ = $this->_current
+ ->getClause('default');
+
+ foreach($children as $child)
+ $child->accept($this, $handle, $eldnah);
+
+ $this->_current = $previous;
+ break;
+
case '#throwable':
$this->_clause = $this->_current->getClause('throwable');
$identifier = null;
diff --git a/Visitor/Praspel.php b/Visitor/Praspel.php
index 82c34a3..26949b9 100644
--- a/Visitor/Praspel.php
+++ b/Visitor/Praspel.php
@@ -180,6 +180,25 @@ class Praspel implements \Hoa\Visitor\Visit {
$out = '@throwable' . implode(' or', $oout) . ';';
}
+ elseif($element instanceof \Hoa\Praspel\Model\DefaultBehavior) {
+
+ $out = '@default {' . "\n";
+ $oout = array();
+
+ foreach($element::getAllowedClauses() as $clause)
+ if(true === $element->clauseExists($clause))
+ $oout[] = ' ' . str_replace(
+ "\n",
+ "\n" . ' ',
+ $element->getClause($clause)->accept(
+ $this,
+ $handle,
+ $eldnah
+ )
+ );
+
+ $out .= implode("\n", $oout) . "\n" . '}';
+ }
elseif($element instanceof \Hoa\Praspel\Model\Behavior) {
$out = '@behavior ' . $element->getIdentifier() . ' {' . "\n";