function imports($file) { try { $handle = @fopen($file, "r"); if ($handle == false) { throw new Exception(); } $lines = array(); while (($line = fgets($handle)) !== false) { if (strpos($line, "imports(") !== false) { $nextfile = explode("\"", $line); $nextfile = $nextfile[1]; imports($nextfile); } elseif (!strpos($line, "//!print")) { $line = str_replace("\r", "", $line); $line = str_replace("\n", "", $line); echo $line . "\r\n"; } } $cutfront = true; foreach ($lines as $line) { if ($cutfront == true) { if ($line == "") { array_shift($lines); } else { $cutfront = false; } } } $cutrear = true; for ($i = count($lines) - 1; $i > -1; $i--) { $line = $lines[$i]; if ($cutrear == true) { if ($line == "") { array_pop($lines); } else { $cutrear = false; } } } foreach ($lines as $line) { //echo $line."\r\n"; } } catch (Exception $e) { echo "// File '" . $file . "' not found.\r\n"; } }
function haxe($str) { $lines = explode("\n", $str); $str = ''; foreach ($lines as $ln) { $ln = preg_replace('/(\\!\\=|\\>\\=|\\<\\=|\\|\\||\\=\\=|\\&\\&)/', '<span class="operator">\\1</span>', $ln); if (preg_match('/^\\s*(class )|(interface )/', $ln)) { $ln = classDef($ln); } elseif (preg_match('/(var )|(function )/U', preg_replace('/(\\/\\/.*$)/U', '', $ln))) { $ln = definition($ln); } else { $ln = preg_replace('/\\@(dispatch|param|result|return|author|throws|throw|exception)/', '<span class="tag \\1">@\\1</span>', $ln) . "\n"; # @tags } $ln = preg_replace('/^(\\s*(\\*|\\/\\*).*)$/', '<i>\\1</i>', $ln); $ln = preg_replace('/^(\\s*\\*\\/)/', '<i>\\1</i>', $ln); $ln = preg_replace('/(?<!\\:)(\\/\\/.*)$/', '<i>\\1</i>', $ln); $ln = preg_replace('/(\\s|\\()(([a-z0-9_]+\\.)+[A-Z][a-zA-Z0-9_]*)/', '\\1<type>\\2</type>', $ln); $ln = preg_replace('/(\\s+)(!([.a-zA-Z0-9_]+))([^=.a-zA-Z0-9_])/', '\\1\\3\\4', $ln); $ln = preg_replace('/([^a-zA-Z0-9_])(this|super)([^a-zA-Z0-9_])/', '\\1<span class="\\2">\\2</span>\\3', $ln); $ln = preg_replace('/([^a-zA-Z0-9_])(package|cast|null|false|true|return)([^a-zA-Z0-9_])/', '\\1<span class="\\2">\\2</span>\\3', $ln); $ln = preg_replace('/([^a-zA-Z-0-9_])if(\\s*)\\(/', '\\1<span class="if">if</span>\\3(', $ln); $str .= $ln; } return "<div class=\"haxe\">\n" . imports($str) . "</div>"; }