load() public static method

public static load ( $file )
Exemplo n.º 1
0
function balrog_front_controller($baseDir)
{
    $environment = Lisphp_Environment::full();
    $scope = new Lisphp_Scope($environment);
    $scope['require'] = new Lisphp_Runtime_PHPFunction(function ($file) use($scope) {
        $program = Lisphp_Program::load(__DIR__ . '/' . $file . '.lisphp');
        return $program->execute($scope);
    });
    $scope['base-dir'] = $baseDir;
    $filename = __DIR__ . '/front-controller.lisphp';
    $program = Lisphp_Program::load($filename);
    $program->execute($scope);
}
Exemplo n.º 2
0
 public function testFromFile()
 {
     $testFiles = glob(__DIR__ . '/Functional/*.lisphp');
     foreach ($testFiles as $file) {
         $this->result = '';
         $program = Lisphp_Program::load($file);
         $scope = Lisphp_Environment::full();
         $scope['echo'] = new Lisphp_Runtime_PHPFunction(array($this, 'displayStrings'));
         $program->execute($scope);
         $expected = file_get_contents(preg_replace('/\\.lisphp$/', '.out', $file));
         $this->assertSame(trim($expected), trim($this->result));
     }
 }
Exemplo n.º 3
0
 public function testFromFile()
 {
     $program = Lisphp_Program::load(__DIR__ . '/sample.lisphp');
     $this->assertEquals(3, count($program));
     try {
         Lisphp_Program::load($f = __DIR__ . '/sample2.lisphp');
         $this->fail();
     } catch (Lisphp_ParsingException $e) {
         $this->assertEquals(file_get_contents($f), $e->code);
         $this->assertEquals($f, $e->getLisphpFile());
         $this->assertEquals(2, $e->getLisphpLine());
         $this->assertEquals(32, $e->getLisphpColumn());
     }
 }
Exemplo n.º 4
0
<?php

require dirname(__FILE__) . '/Lisphp.php';
$options = getopt('v', array('verbose'));
function displayStrings()
{
    global $result;
    $args = func_get_args();
    $result .= join('', array_map('strval', $args));
}
$testFiles = glob(dirname(__FILE__) . '/tests/*.lisphp');
$fails = array();
foreach ($testFiles as $file) {
    $program = Lisphp_Program::load($file);
    $result = '';
    $scope = Lisphp_Environment::full();
    $scope['echo'] = new Lisphp_Runtime_PHPFunction('displayStrings');
    $program->execute($scope);
    $expected = file_get_contents(preg_replace('/\\.lisphp$/', '.out', $file));
    if (trim($result) == trim($expected)) {
        echo '.';
    } else {
        echo 'F';
        $fails[$file] = $result;
    }
}
if ($fails) {
    echo "\nFailed: ";
} else {
    echo "\nOK ";
}