aboutsummaryrefslogtreecommitdiffstats
path: root/Visitor
diff options
context:
space:
mode:
authorIvan Enderlin <ivan.enderlin@hoa-project.net>2013-11-05 15:17:06 +0100
committerIvan Enderlin <ivan.enderlin@hoa-project.net>2013-11-05 15:35:27 +0100
commit2d4561ddd7a86b5afbcf80bc4d7033d0b31d28af (patch)
treecb347c1da3b4d20a06fdb88af553b8c99fa0d4db /Visitor
parenta6a72c47a1b1ed1f0e14fda5e97e8f2fe4d93b76 (diff)
downloadPraspel-2d4561ddd7a86b5afbcf80bc4d7033d0b31d28af.zip
Praspel-2d4561ddd7a86b5afbcf80bc4d7033d0b31d28af.tar.gz
Praspel-2d4561ddd7a86b5afbcf80bc4d7033d0b31d28af.tar.bz2
Include visitors from Hoa\Realdom.
Diffstat (limited to 'Visitor')
-rw-r--r--Visitor/Compiler.php82
-rw-r--r--Visitor/Praspel.php53
2 files changed, 130 insertions, 5 deletions
diff --git a/Visitor/Compiler.php b/Visitor/Compiler.php
index 74c06b7..38600f3 100644
--- a/Visitor/Compiler.php
+++ b/Visitor/Compiler.php
@@ -78,6 +78,8 @@ class Compiler implements \Hoa\Visitor\Visit {
$out = null;
+ // Hoa\Praspel.
+
if($element instanceof \Hoa\Praspel\Model\Specification) {
$variable = '$' . $element->getId();
@@ -126,7 +128,9 @@ class Compiler implements \Hoa\Visitor\Visit {
if(null !== $alias = $element->getAlias())
$out .= '->domainof(\'' . $alias . '\');' . "\n";
else
- $out .= '->in = ' . $element->getDomains() . ';' . "\n";
+ $out .= '->in = ' .
+ $element->getDomains()->accept($this, $handle, $eldnah) .
+ ';' . "\n";
$constraints = $element->getConstraints();
@@ -230,6 +234,82 @@ class Compiler implements \Hoa\Visitor\Visit {
elseif($element instanceof \Hoa\Praspel\Model\Collection)
foreach($element as $el)
$out .= $el->accept($this, $handle, $eldnah);
+
+ // Hoa\Realdom.
+
+ elseif($element instanceof \Hoa\Realdom\Disjunction) {
+
+ $realdoms = $element->getUnflattenedRealdoms();
+
+ if(!empty($realdoms)) {
+
+ $oout = array();
+
+ foreach($realdoms as $realdom) {
+
+ if($realdom instanceof \Hoa\Realdom\IRealdom\Constant)
+ $oout[] = 'const(' .
+ $realdom->accept($this, $handle, $eldnah) .
+ ')';
+ else
+ $oout[] = $realdom->accept($this, $handle, $eldnah);
+ }
+
+ $out .= 'realdom()->' . implode('->or->', $oout);
+ }
+ }
+ elseif($element instanceof \Hoa\Realdom) {
+
+ if($element instanceof \Hoa\Realdom\IRealdom\Constant) {
+
+ if($element instanceof \Hoa\Realdom\_Array) {
+
+ $oout = array();
+
+ foreach($element['pairs'] as $pair) {
+
+ $_oout = null;
+
+ foreach($pair as $_pair) {
+
+ if(null !== $_oout)
+ $_oout .= ', ';
+
+ $_oout .= $_pair->accept($this, $handle, $eldnah);
+ }
+
+ $oout[] = 'array(' . $_oout . ')';
+ }
+
+ $out .= 'array(' . implode(', ', $oout) . ')';
+ }
+ else
+ $out .= $element->getConstantRepresentation();
+ }
+ else {
+
+ $oout = array();
+
+ foreach($element->getArguments() as $argument)
+ $oout[] = $argument->accept($this, $handle, $eldnah);
+
+ $out .= $element->getName() .
+ '(' . implode(', ', $oout) . ')';
+ }
+ }
+ elseif($element instanceof \Hoa\Realdom\Crate\Variable) {
+
+ $holder = $element->getVariable();
+
+ if($holder instanceof \Hoa\Praspel\Model\Variable\Implicit)
+ $out .= 'variable($' . $holder->getClause()->getId() .
+ '->getImplicitVariable(\'' . $holder->getName() .
+ '\'))';
+ else
+ $out .= 'variable($' . $holder->getClause()->getId() .
+ '[\'' . $holder->getName() . '\'])';
+ }
+
else
throw new \Hoa\Praspel\Exception\Compiler(
'%s is not yet implemented.', 0, get_class($element));
diff --git a/Visitor/Praspel.php b/Visitor/Praspel.php
index 0471ddf..e1487ff 100644
--- a/Visitor/Praspel.php
+++ b/Visitor/Praspel.php
@@ -78,6 +78,8 @@ class Praspel implements \Hoa\Visitor\Visit {
$out = null;
+ // Hoa\Praspel.
+
if($element instanceof \Hoa\Praspel\Model\Specification) {
$oout = array();
@@ -120,7 +122,8 @@ class Praspel implements \Hoa\Visitor\Visit {
$out .= $name;
if(null === $alias = $element->getAlias())
- $out .= ': ' . $element->getDomains()->toPraspel();
+ $out .= ': ' .
+ $element->getDomains()->accept($this, $handle, $eldnah);
else
$out .= ' domainof ' . $alias;
@@ -133,12 +136,13 @@ class Praspel implements \Hoa\Visitor\Visit {
if(isset($constraints['contains']))
foreach($constraints['contains'] as $contains)
$out .= ' and ' . $name . ' contains ' .
- $contains->toPraspel();
+ $contains->accept($this, $handle, $eldnah);
if(isset($constraints['key']))
foreach($constraints['key'] as $pairs)
- $out .= ' and ' . $name . '[' . $pairs[0]->toPraspel() .
- ']: ' . $pairs[1]->toPraspel();
+ $out .= ' and ' . $name . '[' .
+ $pairs[0]->accept($this, $handle, $eldnah) .
+ ']: ' . $pairs[1]->accept($this, $handle, $eldnah);
}
elseif($element instanceof \Hoa\Praspel\Model\Throwable) {
@@ -233,6 +237,47 @@ class Praspel implements \Hoa\Visitor\Visit {
elseif($element instanceof \Hoa\Praspel\Model\Collection)
foreach($element as $el)
$out .= $el->accept($this, $handle, $eldnah);
+
+ // Hoa\Realdom.
+
+ elseif($element instanceof \Hoa\Realdom\Disjunction) {
+
+ $realdoms = $element->getUnflattenedRealdoms();
+
+ if(!empty($realdoms)) {
+
+ $oout = array();
+
+ foreach($realdoms as $realdom)
+ $oout[] = $realdom->accept($this, $handle, $eldnah);
+
+ $out .= implode(' or ', $oout);
+ }
+ }
+ elseif($element instanceof \Hoa\Realdom) {
+
+ if($element instanceof \Hoa\Realdom\IRealdom\Constant)
+ $out .= $element->getConstantRepresentation();
+ else {
+
+ $oout = array();
+
+ foreach($element->getArguments() as $argument)
+ $oout[] = $argument->accept($this, $handle, $eldnah);
+
+ $out .= $element->getName() . '(' . implode(', ', $oout) . ')';
+ }
+ }
+ elseif($element instanceof \Hoa\Realdom\Crate\Constant) {
+
+ $praspel = $element->getPraspelRepresentation();
+ $out .= $praspel();
+ }
+ elseif($element instanceof \Hoa\Realdom\Crate\Variable) {
+
+ $out .= $element->getVariable()->getName();
+ }
+
else
throw new \Hoa\Praspel\Exception\Compiler(
'%s is not yet implemented.', 0, get_class($element));