-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFomlExecNode.php
executable file
·51 lines (46 loc) · 1.27 KB
/
FomlExecNode.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
class FomlExecNode extends FomlNode
{
public $mode = Foml::PHP_MODE;
const MATCH_RE = "/^-\s*(.*)/";
/*
* Examples
* - $x = 0
* - foreach ($i=0;$i<10;$i++)
*/
/*
* else and elseif are interesting. They don't need special handling - the tree
* will naturally render like this:
* < ? php if (condition) { ? >
* stuff
* < ? php } ? >
* < ? php else { ? >
* more stuff
* < ? php } ? >
* because
*/
public $code;
public $hasBlock; // if true enclose block in {} otherwise end command with ";"
function __construct($Matches)
{
$this->code = $Matches[1];
$this->hasBlock = preg_match("/^(foreach|for|while|if|else|elseif)/", $this->code);
}
function RenderPrefix()
{
// The first \n is required to escape any trailing // or # comment.
// It would also be possible to end and restart the PHP code block to abort the comment.'
print $this->code;
if ($this->hasBlock && count($this->children)>0) {
print "\n{\n";
} else {
print "\n;\n";
}
}
function RenderSuffix()
{
if ($this->hasBlock && count($this->children)>0) {
print "}\n";
}
}
}