Inheritance: implements Lisphp_Form
示例#1
0
 function testGet()
 {
     $this->assertEquals(1, $this->scope['abc']);
     $this->assertEquals(true, $this->scope[Lisphp_Symbol::get('def')]);
     $this->assertNull($this->scope['ghi']);
     $this->assertNull($this->scope['x']);
 }
示例#2
0
 public function testToString()
 {
     $quote = new Lisphp_Quote(Lisphp_Symbol::get('abc'));
     $this->assertEquals(':abc', $quote->__toString());
     $quote = new Lisphp_Quote(new Lisphp_List(array(Lisphp_Symbol::get('define'), Lisphp_Symbol::get('pi'), new Lisphp_Literal(3.14))));
     $this->assertEquals(':(define pi 3.14)', $quote->__toString());
 }
示例#3
0
 public function testToString()
 {
     $this->markTestIncomplete('Somebody please debug this, I have no clue what is going on.');
     // todo
     $quote = new Lisphp_Quote(Lisphp_Symbol::get('abc'));
     $this->assertEquals(':abc', $quote->__toString());
     $quote = new Lisphp_Quote(new Lisphp_List(array(Lisphp_Symbol::get('define'), Lisphp_Symbol::get('pi'), new Lisphp_Literal(3.14))));
     $this->assertEquals(':(define pi 3.14)', $quote->__toString());
 }
示例#4
0
 function apply(Lisphp_Scope $scope, Lisphp_List $arguments)
 {
     $tmp = new Lisphp_Scope();
     $use = new Lisphp_Runtime_Use();
     $ns = (string) $arguments->car();
     $simpleNames = iterator_to_array($arguments[1]);
     foreach ($simpleNames as $name) {
         $names[] = Lisphp_Symbol::get("{$ns}/{$name}");
     }
     $retval = $use->apply($tmp, new Lisphp_List($names));
     foreach ($simpleNames as $i => $name) {
         $scope->let($name, $retval[$i]);
     }
     return $retval;
 }
示例#5
0
 function testToString()
 {
     $symbol = Lisphp_Symbol::get('abc');
     $this->assertEquals('abc', $symbol->__toString());
 }
示例#6
0
 function testParseForm_symbol()
 {
     $this->assertForm(Lisphp_Symbol::get('abc'), 3, 'abc');
     $this->assertForm(Lisphp_Symbol::get('-abcd'), 5, '-abcd ');
     $this->assertForm(Lisphp_Symbol::get('-'), 1, '-');
     $this->assertForm(Lisphp_Symbol::get('+'), 1, '+');
 }
示例#7
0
 static function parseForm($form, &$offset)
 {
     static $parentheses = null;
     if (is_null($parentheses)) {
         $_parentheses = self::PARENTHESES;
         $parentheses = array();
         for ($i = 0, $len = strlen($_parentheses); $i < $len; $i += 2) {
             $parentheses[$_parentheses[$i]] = $_parentheses[$i + 1];
         }
         unset($_parentheses);
     }
     if (isset($form[0], $parentheses[$form[0]])) {
         $end = $parentheses[$form[0]];
         $values = array();
         $i = 1;
         $len = strlen($form);
         while ($i < $len && $form[$i] != $end) {
             if (strpos(self::WHITESPACES, $form[$i]) !== false) {
                 ++$i;
                 continue;
             }
             try {
                 $values[] = self::parseForm(substr($form, $i), $_offset);
                 $i += $_offset;
             } catch (Lisphp_ParsingException $e) {
                 throw new Lisphp_ParsingException($form, $i + $e->offset);
             }
         }
         if (isset($form[$i]) && $form[$i] == $end) {
             $offset = $i + 1;
             return new Lisphp_List($values);
         }
         throw new Lisphp_ParsingException($form, $i);
     } else {
         if (isset($form[0]) && $form[0] == self::QUOTE_PREFIX) {
             $parsed = self::parseForm(substr($form, 1), $_offset);
             $offset = $_offset + 1;
             return new Lisphp_Quote($parsed);
         } else {
             if (preg_match(self::REAL_PATTERN, $form, $matches)) {
                 $offset = strlen($matches[0]);
                 return new Lisphp_Literal((double) $matches[0]);
             } else {
                 if (preg_match(self::INTEGER_PATTERN, $form, $matches)) {
                     $offset = strlen($matches[0]);
                     $sign = $matches[1] == '-' ? -1 : 1;
                     $value = !empty($matches[3]) ? hexdec($matches[3]) : (!empty($matches[4]) ? octdec($matches[4]) : $matches[2]);
                     return new Lisphp_Literal($sign * $value);
                 } else {
                     if (preg_match(self::STRING_PATTERN, $form, $matches)) {
                         list($parsed) = $matches;
                         $offset = strlen($parsed);
                         return new Lisphp_Literal(preg_replace_callback(self::STRING_ESCAPE_PATTERN, array(__CLASS__, '_unescapeString'), substr($parsed, 1, -1)));
                     } else {
                         if (preg_match(self::SYMBOL_PATTERN, $form, $matches)) {
                             $offset = strlen($matches[0]);
                             return Lisphp_Symbol::get($matches[0]);
                         } else {
                             throw new Lisphp_ParsingException($form, 0);
                         }
                     }
                 }
             }
         }
     }
 }
示例#8
0
 public function applyFunction(Lisphp_Applicable $function)
 {
     $args = func_get_args();
     array_shift($args);
     $scope = new Lisphp_Scope();
     $symbol = 0;
     foreach ($args as &$value) {
         if ($value instanceof ArrayObject || is_array($value)) {
             $value = new Lisphp_Quote(new Lisphp_List($value));
         } elseif (is_object($value) || is_bool($value) || is_null($value)) {
             $scope["tmp-{$symbol}"] = $value;
             $value = Lisphp_Symbol::get('tmp-' . $symbol++);
         } else {
             $value = new Lisphp_Literal($value);
         }
     }
     return $function->apply($scope, new Lisphp_List($args));
 }
示例#9
0
 function testCdr()
 {
     $this->assertEquals(new Lisphp_List(array(Lisphp_Symbol::get('pi'), new Lisphp_Literal(3.14))), $this->list->cdr());
 }