Hoa central
Public Member Functions | List of all members
Hoa\Praspel\Visitor\Praspel Class Reference
Inheritance diagram for Hoa\Praspel\Visitor\Praspel:

Public Member Functions

 visit (Visitor\Element $element, &$handle=null, $eldnah=null)
 
- Public Member Functions inherited from Hoa\Visitor\Visit
 visit (Element $element, &$handle=null, $eldnah=null)
 

Detailed Description

Class .

Compile the model to Praspel code.

Definition at line 51 of file Praspel.php.

Member Function Documentation

Hoa\Praspel\Visitor\Praspel::visit ( Visitor\Element  $element,
$handle = null,
  $eldnah = null 
)

Visit an element.

Parameters
\Hoa\Visitor\Element$elementElement to visit.
mixed&$handleHandle (reference).
mixed$eldnahHandle (not reference).
Returns
mixed

Definition at line 61 of file Praspel.php.

65  {
66  $out = null;
67 
68  // Hoa\Praspel.
69 
70  if ($element instanceof HoaPraspel\Model\Specification) {
71  $oout = [];
72 
73  foreach ($element::getAllowedClauses() as $clause) {
74  if (true === $element->clauseExists($clause)) {
75  $oout[] = $element->getClause($clause)->accept(
76  $this,
77  $handle,
78  $eldnah
79  );
80  }
81  }
82 
83  $out = implode("\n", $oout);
84  } elseif ($element instanceof HoaPraspel\Model\Is) {
85  $out = '@is ' . $element->getPropertyName() . ';';
86  } elseif ($element instanceof HoaPraspel\Model\Declaration) {
87  $clause = $element->getName();
88  $out = '@' . $clause;
89  $oout = [];
90 
91  foreach ($element->getLocalVariables() as $name => $var) {
92  $oout[] = ' ' . $var->accept($this, $handle, $eldnah);
93  }
94 
95  foreach ($element->getPredicates() as $predicate) {
96  $oout[] = ' \pred(\'' . $predicate . '\')';
97  }
98 
99  $out .= implode(' and', $oout) . ';';
100  } elseif ($element instanceof HoaPraspel\Model\Variable) {
101  $name = $element->getName();
102 
103  if (true === $element->isLocal()) {
104  $out = 'let ';
105  }
106 
107  $out .= $name;
108 
109  if (null === $alias = $element->getAlias()) {
110  $out .=
111  ': ' .
112  $element->getDomains()->accept($this, $handle, $eldnah);
113  } else {
114  $out .= ' domainof ' . $alias;
115  }
116 
117  $constraints = $element->getConstraints();
118 
119  if (isset($constraints['is'])) {
120  $out .=
121  ' and ' . $name . ' is ' .
122  implode(', ', $constraints['is']);
123  }
124 
125  if (isset($constraints['contains'])) {
126  foreach ($constraints['contains'] as $contains) {
127  $out .=
128  ' and ' . $name . ' contains ' .
129  $contains->accept($this, $handle, $eldnah);
130  }
131  }
132 
133  if (isset($constraints['key'])) {
134  foreach ($constraints['key'] as $pairs) {
135  $out .=
136  ' and ' . $name . '[' .
137  $pairs[0]->accept($this, $handle, $eldnah) .
138  ']: ' . $pairs[1]->accept($this, $handle, $eldnah);
139  }
140  }
141  } elseif ($element instanceof HoaPraspel\Model\Throwable) {
142  $oout = [];
143 
144  foreach ($element as $identifier) {
145  $exception = $element[$identifier];
146 
147  if (true === $exception->isDisjointed()) {
148  continue;
149  }
150 
151  $line =
152  ' ' . $exception->getInstanceName() . ' ' .
153  $identifier;
154 
155  foreach ((array) $exception->getDisjunction() as $_identifier) {
156  $_exception = $element[$_identifier];
157  $line .=
158  ' or ' . $_exception->getInstanceName() . ' ' .
159  $_identifier;
160  }
161 
162  if (null !== $with = $exception->getWith()) {
163  $line .= ' with ';
164  $liine = [];
165 
166  foreach ($with as $var) {
167  $liine[] = $var->accept($this, $handle, $eldnah);
168  }
169 
170  foreach ($with->getPredicates() as $predicate) {
171  $liine[] = '\pred(\'' . $predicate . '\')';
172  }
173 
174  $line .= implode(' and ', $liine);
175  }
176 
177  $oout[] = $line;
178  }
179 
180  $out = '@throwable' . implode(' or', $oout) . ';';
181  } elseif ($element instanceof HoaPraspel\Model\DefaultBehavior) {
182  $out = '@default {' . "\n";
183  $oout = [];
184 
185  foreach ($element::getAllowedClauses() as $clause) {
186  if (true === $element->clauseExists($clause)) {
187  $oout[] = ' ' . str_replace(
188  "\n",
189  "\n" . ' ',
190  $element->getClause($clause)->accept(
191  $this,
192  $handle,
193  $eldnah
194  )
195  );
196  }
197  }
198 
199  $out .= implode("\n", $oout) . "\n" . '}';
200  } elseif ($element instanceof HoaPraspel\Model\Behavior) {
201  $out = '@behavior ' . $element->getIdentifier() . ' {' . "\n";
202  $oout = [];
203 
204  foreach ($element::getAllowedClauses() as $clause) {
205  if (true === $element->clauseExists($clause)) {
206  $oout[] = ' ' . str_replace(
207  "\n",
208  "\n" . ' ',
209  $element->getClause($clause)->accept(
210  $this,
211  $handle,
212  $eldnah
213  )
214  );
215  }
216  }
217 
218  $out .= implode("\n", $oout) . "\n" . '}';
219  } elseif ($element instanceof HoaPraspel\Model\Description) {
220  $oout = [];
221 
222  foreach ($element as $example) {
223  $oout[] =
224  '@description \'' .
225  preg_replace('#(?<!\\\)\'#', '\\\'', $example) .
226  '\';';
227  }
228 
229  $out = implode("\n", $oout);
230  } elseif ($element instanceof HoaPraspel\Model\Collection) {
231  foreach ($element as $el) {
232  $out .= $el->accept($this, $handle, $eldnah);
233  }
234  }
235 
236  // Hoa\Realdom.
237 
238  elseif ($element instanceof Realdom\Disjunction) {
239  $realdoms = $element->getUnflattenedRealdoms();
240 
241  if (!empty($realdoms)) {
242  $oout = [];
243 
244  foreach ($realdoms as $realdom) {
245  $oout[] = $realdom->accept($this, $handle, $eldnah);
246  }
247 
248  $out .= implode(' or ', $oout);
249  }
250  } elseif ($element instanceof Realdom) {
251  if ($element instanceof Realdom\IRealdom\Constant) {
252  $out .= $element->getConstantRepresentation();
253  } else {
254  $oout = [];
255 
256  foreach ($element->getArguments() as $argument) {
257  $oout[] = $argument->accept($this, $handle, $eldnah);
258  }
259 
260  $out .= $element->getName() . '(' . implode(', ', $oout) . ')';
261  }
262  } elseif ($element instanceof Realdom\Crate\Constant) {
263  $praspel = $element->getPraspelRepresentation();
264  $out .= $praspel();
265  } elseif ($element instanceof Realdom\Crate\Variable) {
266  $out .= $element->getVariable()->getName();
267  } else {
268  throw new HoaPraspel\Exception\Compiler(
269  '%s is not yet implemented.',
270  0,
271  get_class($element)
272  );
273  }
274 
275  return $out;
276  }

The documentation for this class was generated from the following file: