powered by nequal
Home » HatenaSyntax » Timeline » 1641

Changeset 1641 -- 2010-02-10 13:17:12

Comment
[Package Release] HatenaSyntax

Diffs

HatenaSyntax/tags/release-1.0.4-20100210131712/test/lib/HatenaSyntax/InlineTag.php

@@ -0,0 +1,10 @@
+<?php
+include_once dirname(__FILE__) . '/../../t.php';
+
+$t = new lime_test;
+
+$p = new HatenaSyntax_InlineTag(PEG::anything());
+
+$c = PEG::context('<strong>a</strong>');
+
+$t->is($p->parse($c), array('strong', array('a')));
属性に変更があったパス: HatenaSyntax/tags/release-1.0.4-20100210131712/test/lib/HatenaSyntax/InlineTag.php
___________________________________________________________________
名前: svn:keywords
+ Id

HatenaSyntax/tags/release-1.0.4-20100210131712/test/lib/HatenaSyntax/List.php

@@ -0,0 +1,11 @@
+<?php
+include_once dirname(__FILE__) . '/../../t.php';
+
+$t = new lime_test;
+
+$p = new HatenaSyntax_List(PEG::anything());
+$c = PEG::context(array(
+    '+a', '+c'
+));
+
+$t->ok($p->parse($c) !== PEG::failure());
属性に変更があったパス: HatenaSyntax/tags/release-1.0.4-20100210131712/test/lib/HatenaSyntax/List.php
___________________________________________________________________
名前: svn:keywords
+ Id

HatenaSyntax/tags/release-1.0.4-20100210131712/test/lib/HatenaSyntax/Quote.php

@@ -0,0 +1,31 @@
+<?php
+include_once dirname(__FILE__) . '/../../t.php';
+
+$t = new lime_test;
+
+$p = new HatenaSyntax_Quote(PEG::anything());
+$c = PEG::context(array(
+    '>>',
+    'a',
+    '<<'
+));
+
+$t->is(
+    $p->parse($c),
+    array(
+        false,
+        array('a')
+    ));
+
+$c = PEG::context(array(
+    '>http://google.com>',
+    'a',
+    '<<'
+));
+
+$t->is(
+    $p->parse($c),
+    array(
+        'http://google.com',
+        array('a')
+    ));
属性に変更があったパス: HatenaSyntax/tags/release-1.0.4-20100210131712/test/lib/HatenaSyntax/Quote.php
___________________________________________________________________
名前: svn:keywords
+ Id

HatenaSyntax/tags/release-1.0.4-20100210131712/test/lib/HatenaSyntax/LineElement.php

@@ -0,0 +1,10 @@
+<?php
+include_once dirname(__FILE__) . '/../../t.php';
+
+$t = new lime_test;
+
+$p = HatenaSyntax_Locator::it()->lineElement;
+
+$c = PEG::context('a');
+
+$t->is($p->parse($c), 'a');
属性に変更があったパス: HatenaSyntax/tags/release-1.0.4-20100210131712/test/lib/HatenaSyntax/LineElement.php
___________________________________________________________________
名前: svn:keywords
+ Id

HatenaSyntax/tags/release-1.0.4-20100210131712/test/lib/HatenaSyntax/CommentRemover.php

@@ -0,0 +1,30 @@
+<?php
+include_once dirname(__FILE__) . '/../../t.php';
+
+$t = new lime_test;
+
+$remover = new HatenaSyntax_CommentRemover;
+
+$text = ">|php|\n<!-- -->||<";
+$t->is($remover->remove($text), $text);
+
+$text = "<!--\n>||\nhogehoge||<\n-->";
+$t->is($remover->remove($text), '');
+
+$text = <<<EOS
+<!-- hoge -->
+>|xml|
+<!--comment-->||<
+<!--
+>||
+
+||<
+-->
+EOS;
+$expected = <<<EOS
+
+>|xml|
+<!--comment-->||<
+
+EOS;
+$t->is($remover->remove($text), $expected);

HatenaSyntax/tags/release-1.0.4-20100210131712/test/lib/HatenaSyntax/NoParagraph.php

@@ -0,0 +1,15 @@
+<?php
+include_once dirname(__FILE__) . '/../../t.php';
+
+$t = new lime_test;
+$p = new HatenaSyntax_NoParagraph(PEG::anything());
+
+$c = PEG::context(array('><p>a</p><'));
+$t->is($p->parse($c), array('p', array(), array('a')));
+
+$c = PEG::context(array(
+    '><p class="hoge">',
+    'fuga',
+    '</p><'
+));
+$t->is($p->parse($c), array('p', array('class' => 'hoge'), array('f', 'u', 'g', 'a')));

HatenaSyntax/tags/release-1.0.4-20100210131712/test/lib/HatenaSyntax/Locator.php

@@ -0,0 +1,10 @@
+<?php
+include_once dirname(__FILE__) . '/../../t.php';
+
+$t = new lime_test;
+
+$p = HatenaSyntax_Locator::it()->bracket;
+
+$c = PEG::context('[http://google.com:title=hoge]');
+
+$t->ok($p->parse($c));

HatenaSyntax/tags/release-1.0.4-20100210131712/test/lib/HatenaSyntax/DefinitionList.php

@@ -0,0 +1,16 @@
+<?php
+include_once dirname(__FILE__) . '/../../t.php';
+
+$t = new lime_test;
+
+$p = new HatenaSyntax_DefinitionList(PEG::anything());
+$c = PEG::context(array(
+    ':a:b', ':a:b'
+));
+
+$t->is(
+    $p->parse($c),
+    array(
+        array(array('a'), array('b')),
+        array(array('a'), array('b'))
+    ));
属性に変更があったパス: HatenaSyntax/tags/release-1.0.4-20100210131712/test/lib/HatenaSyntax/DefinitionList.php
___________________________________________________________________
名前: svn:keywords
+ Id

HatenaSyntax/tags/release-1.0.4-20100210131712/test/lib/HatenaSyntax/Paragraph.php

@@ -0,0 +1,20 @@
+<?php
+include_once dirname(__FILE__) . '/../../t.php';
+
+$t = new lime_test;
+
+$p = new HatenaSyntax_Paragraph(PEG::anything());
+$c = PEG::context(array(
+    'abc',
+    'def'
+));
+
+$t->is(
+    $p->parse($c),
+    array('a', 'b', 'c')
+);
+
+$t->is(
+    $p->parse($c),
+    array('d', 'e', 'f')
+);
属性に変更があったパス: HatenaSyntax/tags/release-1.0.4-20100210131712/test/lib/HatenaSyntax/Paragraph.php
___________________________________________________________________
名前: svn:keywords
+ Id

HatenaSyntax/tags/release-1.0.4-20100210131712/test/lib/HatenaSyntax/SuperPre.php

@@ -0,0 +1,26 @@
+<?php
+include_once dirname(__FILE__) . '/../../t.php';
+
+$t = new lime_test;
+
+$p = new HatenaSyntax_SuperPre;
+$c = PEG::context(array(
+    '>||',
+    'a||<'
+));
+
+$t->is(
+    $p->parse($c),
+    array('', array('a'))
+);
+
+$c = PEG::context(array(
+    '>|a|',
+    'b',
+    '||<'
+));
+
+$t->is(
+    $p->parse($c),
+    array('a', array('b'))
+);
属性に変更があったパス: HatenaSyntax/tags/release-1.0.4-20100210131712/test/lib/HatenaSyntax/SuperPre.php
___________________________________________________________________
名前: svn:keywords
+ Id

HatenaSyntax/tags/release-1.0.4-20100210131712/test/lib/HatenaSyntax/Pre.php

@@ -0,0 +1,26 @@
+<?php
+include_once dirname(__FILE__) . '/../../t.php';
+
+$t = new lime_test;
+
+$p = new HatenaSyntax_Pre(PEG::anything());
+$c = PEG::context(array(
+    '>|',
+    'a|<'
+));
+
+$t->is(
+    $p->parse($c),
+    array(array('a'))
+);
+
+$c = PEG::context(array(
+    '>|',
+    'a',
+    '|<'
+));
+
+$t->is(
+    $p->parse($c),
+    array(array('a'))
+);
属性に変更があったパス: HatenaSyntax/tags/release-1.0.4-20100210131712/test/lib/HatenaSyntax/Pre.php
___________________________________________________________________
名前: svn:keywords
+ Id

HatenaSyntax/tags/release-1.0.4-20100210131712/test/lib/HatenaSyntax/Table.php

@@ -0,0 +1,31 @@
+<?php
+include_once dirname(__FILE__) . '/../../t.php';
+
+$t = new lime_test;
+
+$p = new HatenaSyntax_Table(PEG::anything());
+
+$c = PEG::context(array(
+    '|*a|*b|',
+    '|c|d|'
+));
+
+$t->is(
+    $p->parse($c),
+    array(
+        array(array('*', array('a')), array('*', array('b'))),
+        array(array(false, array('c')), array(false, array('d')))
+    )
+);
+
+$c = PEG::context(array(
+    '|a|'
+));
+
+$t->is(
+    $p->parse($c),
+    array(
+        array(array(false, array('a')))
+    )
+);
+
属性に変更があったパス: HatenaSyntax/tags/release-1.0.4-20100210131712/test/lib/HatenaSyntax/Table.php
___________________________________________________________________
名前: svn:keywords
+ Id

HatenaSyntax/tags/release-1.0.4-20100210131712/test/lib/HatenaSyntax/Header.php

@@ -0,0 +1,13 @@
+<?php
+include_once dirname(__FILE__) . '/../../t.php';
+
+$t = new lime_test;
+
+$p = new HatenaSyntax_Header(PEG::anything());
+$c = PEG::context(array('*abc'));
+
+$t->is($p->parse($c), array(0, false, array('a', 'b', 'c')));
+
+$c = PEG::context(array('*name*a'));
+
+$t->is($p->parse($c), array(0, 'name', array('a')));
属性に変更があったパス: HatenaSyntax/tags/release-1.0.4-20100210131712/test/lib/HatenaSyntax/Header.php
___________________________________________________________________
名前: svn:keywords
+ Id

HatenaSyntax/tags/release-1.0.4-20100210131712/test/lib/HatenaSyntax.php

@@ -0,0 +1,42 @@
+<?php
+include_once dirname(__FILE__) . '/../t.php';
+
+$t = new lime_test;
+$hs = new HatenaSyntax;
+
+$node = $hs->parse('*hoge*header');
+$t->is($hs->getSectionName($node), 'hoge');
+
+$node = $hs->parse('*hoge');
+$t->is($hs->getSectionName($node), '');
+
+$node = $hs->parse('**hoge*header');
+$t->is($hs->getSectionName($node), '');
+
+$nodes = $hs->parseAsSections("\n*hoge\n*fuga\n*piyo");
+$t->is(count($nodes), 3);
+
+$nodes = $hs->parseAsSections("*hoge\n\nfuga");
+$t->is(count($nodes), 1);
+
+$title = $hs->getSectionTitle($hs->parse('*hahaha'));
+$t->is($title, 'hahaha');
+
+$title = $hs->getSectionTitle($hs->parse('*hoge*s[http://google.com]'));
+$t->is($title, 'shttp://google.com');
+
+$hasTopHeader = $hs->hasTopHeader($hs->parse('*hoge'));
+$t->ok($hasTopHeader);
+
+$hasTopHeader = $hs->hasTopHeader($hs->parse('hoge'));
+$t->ok(!$hasTopHeader);
+
+$hasSeparator = $hs->hasSeparator($hs->parse('* fuga'));
+$t->ok(!$hasSeparator);
+
+$hasSeparator = $hs->hasSeparator($hs->parse("* hoge\n====\nhahaha"));
+$t->ok($hasSeparator);
+
+$node = $hs->separate($hs->parse("* hoge\n====\nhahaha"));
+$t->is(count($node->getData()), 2);
+
属性に変更があったパス: HatenaSyntax/tags/release-1.0.4-20100210131712/test/lib/HatenaSyntax.php
___________________________________________________________________
名前: svn:keywords
+ Id

HatenaSyntax/tags/release-1.0.4-20100210131712/test/t.php

@@ -0,0 +1,3 @@
+<?php
+include_once dirname(__FILE__) . '/lime.php';
+include_once dirname(__FILE__) . '/../lib/HatenaSyntax.php';
属性に変更があったパス: HatenaSyntax/tags/release-1.0.4-20100210131712/test/t.php
___________________________________________________________________
名前: svn:keywords
+ Id

HatenaSyntax/tags/release-1.0.4-20100210131712/test/lime.php

@@ -0,0 +1,1078 @@
+<?php
+
+/**
+ * This file is part of the symfony package.
+ * (c) 2004-2006 Fabien Potencier <fabien.potencier@gmail.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+/**
+ * Unit test library.
+ *
+ * @package    lime
+ * @author     Fabien Potencier <fabien.potencier@gmail.com>
+ * @version    SVN: $Id$
+ */
+class lime_test
+{
+  const EPSILON = 0.0000000001;
+
+  public $plan = null;
+  public $test_nb = 0;
+  public $failed = 0;
+  public $passed = 0;
+  public $skipped = 0;
+  public $output = null;
+
+  public function __construct($plan = null, $output_instance = null)
+  {
+    $this->plan = $plan;
+    $this->output = $output_instance ? $output_instance : new lime_output();
+
+    null !== $this->plan and $this->output->echoln(sprintf("1..%d", $this->plan));
+  }
+
+  public function __destruct()
+  {
+    $total = $this->passed + $this->failed + $this->skipped;
+
+    null === $this->plan and $this->plan = $total and $this->output->echoln(sprintf("1..%d", $this->plan));
+
+    if ($total > $this->plan)
+    {
+      $this->output->red_bar(sprintf(" Looks like you planned %d tests but ran %d extra.", $this->plan, $total - $this->plan));
+    }
+    elseif ($total < $this->plan)
+    {
+      $this->output->red_bar(sprintf(" Looks like you planned %d tests but only ran %d.", $this->plan, $total));
+    }
+
+    if ($this->failed)
+    {
+      $this->output->red_bar(sprintf(" Looks like you failed %d tests of %d.", $this->failed, $this->passed + $this->failed));
+    }
+    else if ($total == $this->plan)
+    {
+      $this->output->green_bar(" Looks like everything went fine.");
+    }
+
+    flush();
+  }
+
+  public function ok($exp, $message = '')
+  {
+    if ($result = (boolean) $exp)
+    {
+      ++$this->passed;
+    }
+    else
+    {
+      ++$this->failed;
+    }
+    $this->output->echoln(sprintf("%s %d%s", $result ? 'ok' : 'not ok', ++$this->test_nb, $message = $message ? sprintf('%s %s', 0 === strpos($message, '#') ? '' : ' -', $message) : ''));
+
+    if (!$result)
+    {
+      $traces = debug_backtrace();
+      if (!empty($_SERVER['PHP_SELF']))
+      {
+        $i = strstr($traces[0]['file'], $_SERVER['PHP_SELF']) ? 0 : (isset($traces[1]['file']) ? 1 : 0);
+      }
+      else
+      {
+        $i = 0;
+      }
+      $this->output->diag(sprintf('    Failed test (%s at line %d)', str_replace(getcwd(), '.', $traces[$i]['file']), $traces[$i]['line']));
+    }
+
+    return $result;
+  }
+
+  public function is($exp1, $exp2, $message = '')
+  {
+    if (is_object($exp1) || is_object($exp2))
+    {
+      $value = $exp1 === $exp2;
+    }
+    else if (is_float($exp1) && is_float($exp2))
+    {
+      $value = abs($exp1 - $exp2) < self::EPSILON;
+    }
+    else
+    {
+      $value = $exp1 == $exp2;
+    }
+
+    if (!$result = $this->ok($value, $message))
+    {
+      $this->output->diag(sprintf("           got: %s", var_export($exp1, true)), sprintf("      expected: %s", var_export($exp2, true)));
+    }
+
+    return $result;
+  }
+
+  public function isnt($exp1, $exp2, $message = '')
+  {
+    if (!$result = $this->ok($exp1 != $exp2, $message))
+    {
+      $this->output->diag(sprintf("      %s", var_export($exp2, true)), '          ne', sprintf("      %s", var_export($exp2, true)));
+    }
+
+    return $result;
+  }
+
+  public function like($exp, $regex, $message = '')
+  {
+    if (!$result = $this->ok(preg_match($regex, $exp), $message))
+    {
+      $this->output->diag(sprintf("                    '%s'", $exp), sprintf("      doesn't match '%s'", $regex));
+    }
+
+    return $result;
+  }
+
+  public function unlike($exp, $regex, $message = '')
+  {
+    if (!$result = $this->ok(!preg_match($regex, $exp), $message))
+    {
+      $this->output->diag(sprintf("               '%s'", $exp), sprintf("      matches '%s'", $regex));
+    }
+
+    return $result;
+  }
+
+  public function cmp_ok($exp1, $op, $exp2, $message = '')
+  {
+    eval(sprintf("\$result = \$exp1 $op \$exp2;"));
+    if (!$this->ok($result, $message))
+    {
+      $this->output->diag(sprintf("      %s", str_replace("\n", '', var_export($exp1, true))), sprintf("          %s", $op), sprintf("      %s", str_replace("\n", '', var_export($exp2, true))));
+    }
+
+    return $result;
+  }
+
+  public function can_ok($object, $methods, $message = '')
+  {
+    $result = true;
+    $failed_messages = array();
+    foreach ((array) $methods as $method)
+    {
+      if (!method_exists($object, $method))
+      {
+        $failed_messages[] = sprintf("      method '%s' does not exist", $method);
+        $result = false;
+      }
+    }
+
+    !$this->ok($result, $message);
+
+    !$result and $this->output->diag($failed_messages);
+
+    return $result;
+  }
+
+  public function isa_ok($var, $class, $message = '')
+  {
+    $type = is_object($var) ? get_class($var) : gettype($var);
+    if (!$result = $this->ok($type == $class, $message))
+    {
+      $this->output->diag(sprintf("      isa_ok isn't a '%s' it's a '%s'", $class, $type));
+    }
+
+    return $result;
+  }
+
+  public function is_deeply($exp1, $exp2, $message = '')
+  {
+    if (!$result = $this->ok($this->test_is_deeply($exp1, $exp2), $message))
+    {
+      $this->output->diag(sprintf("           got: %s", str_replace("\n", '', var_export($exp1, true))), sprintf("      expected: %s", str_replace("\n", '', var_export($exp2, true))));
+    }
+
+    return $result;
+  }
+
+  public function pass($message = '')
+  {
+    return $this->ok(true, $message);
+  }
+
+  public function fail($message = '')
+  {
+    return $this->ok(false, $message);
+  }
+
+  public function diag($message)
+  {
+    $this->output->diag($message);
+  }
+
+  public function skip($message = '', $nb_tests = 1)
+  {
+    for ($i = 0; $i < $nb_tests; $i++)
+    {
+      ++$this->skipped and --$this->passed;
+      $this->pass(sprintf("# SKIP%s", $message ? ' '.$message : ''));
+    }
+  }
+
+  public function todo($message = '')
+  {
+    ++$this->skipped and --$this->passed;
+    $this->pass(sprintf("# TODO%s", $message ? ' '.$message : ''));
+  }
+
+  public function include_ok($file, $message = '')
+  {
+    if (!$result = $this->ok((@include($file)) == 1, $message))
+    {
+      $this->output->diag(sprintf("      Tried to include '%s'", $file));
+    }
+
+    return $result;
+  }
+
+  private function test_is_deeply($var1, $var2)
+  {
+    if (gettype($var1) != gettype($var2))
+    {
+      return false;
+    }
+
+    if (is_array($var1))
+    {
+      ksort($var1);
+      ksort($var2);
+
+      $keys1 = array_keys($var1);
+      $keys2 = array_keys($var2);
+      if (array_diff($keys1, $keys2) || array_diff($keys2, $keys1))
+      {
+        return false;
+      }
+      $is_equal = true;
+      foreach ($var1 as $key => $value)
+      {
+        $is_equal = $this->test_is_deeply($var1[$key], $var2[$key]);
+        if ($is_equal === false)
+        {
+          break;
+        }
+      }
+
+      return $is_equal;
+    }
+    else
+    {
+      return $var1 === $var2;
+    }
+  }
+
+  public function comment($message)
+  {
+    $this->output->comment($message);
+  }
+
+  public function info($message)
+  {
+    $this->output->info($message);
+  }
+
+  public function error($message)
+  {
+    $this->output->error($message);
+  }
+
+  public static function get_temp_directory()
+  {
+    if ('\\' == DIRECTORY_SEPARATOR)
+    {
+      foreach (array('TEMP', 'TMP', 'windir') as $dir)
+      {
+        if ($var = isset($_ENV[$dir]) ? $_ENV[$dir] : getenv($dir))
+        {
+          return $var;
+        }
+      }
+
+      return getenv('SystemRoot').'\temp';
+    }
+
+    if ($var = isset($_ENV['TMPDIR']) ? $_ENV['TMPDIR'] : getenv('TMPDIR'))
+    {
+      return $var;
+    }
+
+    return '/tmp';
+  }
+}
+
+class lime_output
+{
+  public function diag()
+  {
+    $messages = func_get_args();
+    foreach ($messages as $message)
+    {
+      array_map(array($this, 'comment'), (array) $message);
+    }
+  }
+
+  public function comment($message)
+  {
+    echo "# $message\n";
+  }
+
+  public function info($message)
+  {
+    echo "> $message\n";
+  }
+
+  public function error($message)
+  {
+    echo "> $message\n";
+  }
+
+  public function echoln($message)
+  {
+    echo "$message\n";
+  }
+
+  public function green_bar($message)
+  {
+    echo "$message\n";
+  }
+
+  public function red_bar($message)
+  {
+    echo "$message\n";
+  }
+}
+
+class lime_output_color extends lime_output
+{
+  public $colorizer = null;
+
+  public function __construct()
+  {
+    $this->colorizer = new lime_colorizer();
+  }
+
+  public function diag()
+  {
+    $messages = func_get_args();
+    foreach ($messages as $message)
+    {
+      echo $this->colorizer->colorize('# '.join("\n# ", (array) $message), 'COMMENT')."\n";
+    }
+  }
+
+  public function comment($message)
+  {
+    echo $this->colorizer->colorize(sprintf('# %s', $message), 'COMMENT')."\n";
+  }
+
+  public function info($message)
+  {
+    echo $this->colorizer->colorize(sprintf('> %s', $message), 'INFO_BAR')."\n";
+  }
+
+  public function error($message)
+  {
+    echo $this->colorizer->colorize(sprintf(' %s ', $message), 'RED_BAR')."\n";
+  }
+
+  public function echoln($message, $colorizer_parameter = null)
+  {
+    $message = preg_replace('/(?:^|\.)((?:not ok|dubious) *\d*)\b/e', '$this->colorizer->colorize(\'$1\', \'ERROR\')', $message);
+    $message = preg_replace('/(?:^|\.)(ok *\d*)\b/e', '$this->colorizer->colorize(\'$1\', \'INFO\')', $message);
+    $message = preg_replace('/"(.+?)"/e', '$this->colorizer->colorize(\'$1\', \'PARAMETER\')', $message);
+    $message = preg_replace('/(\->|\:\:)?([a-zA-Z0-9_]+?)\(\)/e', '$this->colorizer->colorize(\'$1$2()\', \'PARAMETER\')', $message);
+
+    echo ($colorizer_parameter ? $this->colorizer->colorize($message, $colorizer_parameter) : $message)."\n";
+  }
+
+  public function green_bar($message)
+  {
+    echo $this->colorizer->colorize($message.str_repeat(' ', 71 - min(71, strlen($message))), 'GREEN_BAR')."\n";
+  }
+
+  public function red_bar($message)
+  {
+    echo $this->colorizer->colorize($message.str_repeat(' ', 71 - min(71, strlen($message))), 'RED_BAR')."\n";
+  }
+}
+
+class lime_colorizer
+{
+  static public $styles = array();
+
+  public static function style($name, $options = array())
+  {
+    self::$styles[$name] = $options;
+  }
+
+  public static function colorize($text = '', $parameters = array())
+  {
+    // disable colors if not supported (windows or non tty console)
+    if (DIRECTORY_SEPARATOR == '\\' || !function_exists('posix_isatty') || !@posix_isatty(STDOUT))
+    {
+      return $text;
+    }
+
+    static $options    = array('bold' => 1, 'underscore' => 4, 'blink' => 5, 'reverse' => 7, 'conceal' => 8);
+    static $foreground = array('black' => 30, 'red' => 31, 'green' => 32, 'yellow' => 33, 'blue' => 34, 'magenta' => 35, 'cyan' => 36, 'white' => 37);
+    static $background = array('black' => 40, 'red' => 41, 'green' => 42, 'yellow' => 43, 'blue' => 44, 'magenta' => 45, 'cyan' => 46, 'white' => 47);
+
+    !is_array($parameters) && isset(self::$styles[$parameters]) and $parameters = self::$styles[$parameters];
+
+    $codes = array();
+    isset($parameters['fg']) and $codes[] = $foreground[$parameters['fg']];
+    isset($parameters['bg']) and $codes[] = $background[$parameters['bg']];
+    foreach ($options as $option => $value)
+    {
+      isset($parameters[$option]) && $parameters[$option] and $codes[] = $value;
+    }
+
+    return "\033[".implode(';', $codes).'m'.$text."\033[0m";
+  }
+}
+
+lime_colorizer::style('ERROR', array('bg' => 'red', 'fg' => 'white', 'bold' => true));
+lime_colorizer::style('INFO',  array('fg' => 'green', 'bold' => true));
+lime_colorizer::style('PARAMETER', array('fg' => 'cyan'));
+lime_colorizer::style('COMMENT',  array('fg' => 'yellow'));
+
+lime_colorizer::style('GREEN_BAR',  array('fg' => 'white', 'bg' => 'green', 'bold' => true));
+lime_colorizer::style('RED_BAR',  array('fg' => 'white', 'bg' => 'red', 'bold' => true));
+lime_colorizer::style('INFO_BAR',  array('fg' => 'cyan', 'bold' => true));
+
+class lime_harness extends lime_registration
+{
+  public $php_cli = '';
+  public $stats = array();
+  public $output = null;
+
+  public function __construct($output_instance, $php_cli = null)
+  {
+    if (is_null($php_cli))
+    {
+      if (getenv('PHP_PATH'))
+      {
+        $this->php_cli = getenv('PHP_PATH');
+
+        if (!is_executable($this->php_cli))
+        {
+          throw new Exception('The defined PHP_PATH environment variable is not a valid PHP executable.');
+        }
+      }
+      else
+      {
+        $this->php_cli = PHP_BINDIR.DIRECTORY_SEPARATOR.'php';
+      }
+    }
+    else
+    {
+      $this->php_cli = $php_cli;
+    }
+
+    if (!is_executable($this->php_cli))
+    {
+      $this->php_cli = $this->find_php_cli();
+    }
+
+    $this->output = $output_instance ? $output_instance : new lime_output();
+  }
+
+  protected function find_php_cli()
+  {
+    $path = getenv('PATH') ? getenv('PATH') : getenv('Path');
+    $exe_suffixes = DIRECTORY_SEPARATOR == '\\' ? (getenv('PATHEXT') ? explode(PATH_SEPARATOR, getenv('PATHEXT')) : array('.exe', '.bat', '.cmd', '.com')) : array('');
+    foreach (array('php5', 'php') as $php_cli)
+    {
+      foreach ($exe_suffixes as $suffix)
+      {
+        foreach (explode(PATH_SEPARATOR, $path) as $dir)
+        {
+          $file = $dir.DIRECTORY_SEPARATOR.$php_cli.$suffix;
+          if (is_executable($file))
+          {
+            return $file;
+          }
+        }
+      }
+    }
+
+    throw new Exception("Unable to find PHP executable.");
+  }
+
+  public function run()
+  {
+    if (!count($this->files))
+    {
+      throw new Exception('You must register some test files before running them!');
+    }
+
+    // sort the files to be able to predict the order
+    sort($this->files);
+
+    $this->stats =array(
+      '_failed_files' => array(),
+      '_failed_tests' => 0,
+      '_nb_tests'     => 0,
+    );
+
+    foreach ($this->files as $file)
+    {
+      $this->stats[$file] = array(
+        'plan'     =>   null,
+        'nb_tests' => 0,
+        'failed'   => array(),
+        'passed'   => array(),
+      );
+      $this->current_file = $file;
+      $this->current_test = 0;
+      $relative_file = $this->get_relative_file($file);
+
+      ob_start(array($this, 'process_test_output'));
+      passthru(sprintf('%s "%s" 2>&1', $this->php_cli, $file), $return);
+      ob_end_clean();
+
+      if ($return > 0)
+      {
+        $this->stats[$file]['status'] = 'dubious';
+        $this->stats[$file]['status_code'] = $return;
+      }
+      else
+      {
+        $delta = $this->stats[$file]['plan'] - $this->stats[$file]['nb_tests'];
+        if ($delta > 0)
+        {
+          $this->output->echoln(sprintf('%s%s%s', substr($relative_file, -min(67, strlen($relative_file))), str_repeat('.', 70 - min(67, strlen($relative_file))), $this->output->colorizer->colorize(sprintf('# Looks like you planned %d tests but only ran %d.', $this->stats[$file]['plan'], $this->stats[$file]['nb_tests']), 'COMMENT')));
+          $this->stats[$file]['status'] = 'dubious';
+          $this->stats[$file]['status_code'] = 255;
+          $this->stats['_nb_tests'] += $delta;
+          for ($i = 1; $i <= $delta; $i++)
+          {
+            $this->stats[$file]['failed'][] = $this->stats[$file]['nb_tests'] + $i;
+          }
+        }
+        else if ($delta < 0)
+        {
+          $this->output->echoln(sprintf('%s%s%s', substr($relative_file, -min(67, strlen($relative_file))), str_repeat('.', 70 - min(67, strlen($relative_file))), $this->output->colorizer->colorize(sprintf('# Looks like you planned %s test but ran %s extra.', $this->stats[$file]['plan'], $this->stats[$file]['nb_tests'] - $this->stats[$file]['plan']), 'COMMENT')));
+          $this->stats[$file]['status'] = 'dubious';
+          $this->stats[$file]['status_code'] = 255;
+          for ($i = 1; $i <= -$delta; $i++)
+          {
+            $this->stats[$file]['failed'][] = $this->stats[$file]['plan'] + $i;
+          }
+        }
+        else
+        {
+          $this->stats[$file]['status_code'] = 0;
+          $this->stats[$file]['status'] = $this->stats[$file]['failed'] ? 'not ok' : 'ok';
+        }
+      }
+
+      $this->output->echoln(sprintf('%s%s%s', substr($relative_file, -min(67, strlen($relative_file))), str_repeat('.', 70 - min(67, strlen($relative_file))), $this->stats[$file]['status']));
+      if (($nb = count($this->stats[$file]['failed'])) || $return > 0)
+      {
+        if ($nb)
+        {
+          $this->output->echoln(sprintf("    Failed tests: %s", implode(', ', $this->stats[$file]['failed'])));
+        }
+        $this->stats['_failed_files'][] = $file;
+        $this->stats['_failed_tests']  += $nb;
+      }
+
+      if ('dubious' == $this->stats[$file]['status'])
+      {
+        $this->output->echoln(sprintf('    Test returned status %s', $this->stats[$file]['status_code']));
+      }
+    }
+
+    if (count($this->stats['_failed_files']))
+    {
+      $format = "%-30s  %4s  %5s  %5s  %s";
+      $this->output->echoln(sprintf($format, 'Failed Test', 'Stat', 'Total', 'Fail', 'List of Failed'));
+      $this->output->echoln("------------------------------------------------------------------");
+      foreach ($this->stats as $file => $file_stat)
+      {
+        if (!in_array($file, $this->stats['_failed_files'])) continue;
+
+        $relative_file = $this->get_relative_file($file);
+        $this->output->echoln(sprintf($format, substr($relative_file, -min(30, strlen($relative_file))), $file_stat['status_code'], count($file_stat['failed']) + count($file_stat['passed']), count($file_stat['failed']), implode(' ', $file_stat['failed'])));
+      }
+
+      $this->output->red_bar(sprintf('Failed %d/%d test scripts, %.2f%% okay. %d/%d subtests failed, %.2f%% okay.',
+        $nb_failed_files = count($this->stats['_failed_files']),
+        $nb_files = count($this->files),
+        ($nb_files - $nb_failed_files) * 100 / $nb_files,
+        $nb_failed_tests = $this->stats['_failed_tests'],
+        $nb_tests = $this->stats['_nb_tests'],
+        $nb_tests > 0 ? ($nb_tests - $nb_failed_tests) * 100 / $nb_tests : 0
+      ));
+    }
+    else
+    {
+      $this->output->green_bar(' All tests successful.');
+      $this->output->green_bar(sprintf(' Files=%d, Tests=%d', count($this->files), $this->stats['_nb_tests']));
+    }
+
+    return $this->stats['_failed_tests'] ? false : true;
+  }
+
+  private function process_test_output($lines)
+  {
+    foreach (explode("\n", $lines) as $text)
+    {
+      if (false !== strpos($text, 'not ok '))
+      {
+        ++$this->current_test;
+        $test_number = (int) substr($text, 7);
+        $this->stats[$this->current_file]['failed'][] = $test_number;
+
+        ++$this->stats[$this->current_file]['nb_tests'];
+        ++$this->stats['_nb_tests'];
+      }
+      else if (false !== strpos($text, 'ok '))
+      {
+        ++$this->stats[$this->current_file]['nb_tests'];
+        ++$this->stats['_nb_tests'];
+      }
+      else if (preg_match('/^1\.\.(\d+)/', $text, $match))
+      {
+        $this->stats[$this->current_file]['plan'] = $match[1];
+      }
+    }
+
+    return;
+  }
+}
+
+class lime_coverage extends lime_registration
+{
+  public $files = array();
+  public $extension = '.php';
+  public $base_dir = '';
+  public $harness = null;
+  public $verbose = false;
+  protected $coverage = array();
+
+  public function __construct($harness)
+  {
+    $this->harness = $harness;
+
+    if (!function_exists('xdebug_start_code_coverage'))
+    {
+      throw new Exception('You must install and enable xdebug before using lime coverage.');
+    }
+
+    if (!ini_get('xdebug.extended_info'))
+    {
+      throw new Exception('You must set xdebug.extended_info to 1 in your php.ini to use lime coverage.');
+    }
+  }
+
+  public function run()
+  {
+    if (!count($this->harness->files))
+    {
+      throw new Exception('You must register some test files before running coverage!');
+    }
+
+    if (!count($this->files))
+    {
+      throw new Exception('You must register some files to cover!');
+    }
+
+    $this->coverage = array();
+
+    $this->process($this->harness->files);
+
+    $this->output($this->files);
+  }
+
+  public function process($files)
+  {
+    if (!is_array($files))
+    {
+      $files = array($files);
+    }
+
+    $tmp_file = lime_test::get_temp_directory().DIRECTORY_SEPARATOR.'test.php';
+    foreach ($files as $file)
+    {
+      $tmp = <<<EOF
+<?php
+xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE);
+include('$file');
+echo '<PHP_SER>'.serialize(xdebug_get_code_coverage()).'</PHP_SER>';
+EOF;
+      file_put_contents($tmp_file, $tmp);
+      ob_start();
+      passthru(sprintf('%s "%s" 2>&1', $this->harness->php_cli, $tmp_file), $return);
+      $retval = ob_get_clean();
+
+      if (0 != $return) // test exited without success
+      {
+        // something may have gone wrong, we should warn the user so they know
+        // it's a bug in their code and not symfony's
+
+        $this->harness->output->echoln(sprintf('Warning: %s returned status %d, results may be inaccurate', $file, $return), 'ERROR');
+      }
+
+      if (false === $cov = unserialize(substr($retval, strpos($retval, '<PHP_SER>') + 9, strpos($retval, '</PHP_SER>') - 9)))
+      {
+        if (0 == $return)
+        {
+          // failed to serialize, but PHP said it should of worked.
+          // something is seriously wrong, so abort with exception
+          throw new Exception(sprintf('Unable to unserialize coverage for file "%s"', $file));
+        }
+        else
+        {
+          // failed to serialize, but PHP warned us that this might have happened.
+          // so we should ignore and move on
+          continue; // continue foreach loop through $this->harness->files
+        }
+      }
+
+      foreach ($cov as $file => $lines)
+      {
+        if (!isset($this->coverage[$file]))
+        {
+          $this->coverage[$file] = $lines;
+          continue;
+        }
+
+        foreach ($lines as $line => $flag)
+        {
+          if ($flag == 1)
+          {
+            $this->coverage[$file][$line] = 1;
+          }
+        }
+      }
+    }
+
+    if (file_exists($tmp_file))
+    {
+      unlink($tmp_file);
+    }
+  }
+
+  public function output($files)
+  {
+    ksort($this->coverage);
+    $total_php_lines = 0;
+    $total_covered_lines = 0;
+    foreach ($files as $file)
+    {
+      $is_covered = isset($this->coverage[$file]);
+      $cov = isset($this->coverage[$file]) ? $this->coverage[$file] : array();
+      $covered_lines = array();
+      $missing_lines = array();
+
+      foreach ($cov as $line => $flag)
+      {
+        switch ($flag)
+        {
+          case 1:
+            $covered_lines[] = $line;
+            break;
+          case -1:
+            $missing_lines[] = $line;
+            break;
+        }
+      }
+      $total_lines = count($covered_lines) + count($missing_lines);
+
+      $output = $this->harness->output;
+      $percent = $total_lines ? count($covered_lines) * 100 / $total_lines : 0;
+
+      $total_php_lines += $total_lines;
+      $total_covered_lines += count($covered_lines);
+
+      $relative_file = $this->get_relative_file($file);
+      $output->echoln(sprintf("%-70s %3.0f%%", substr($relative_file, -min(70, strlen($relative_file))), $percent), $percent == 100 ? 'INFO' : ($percent > 90 ? 'PARAMETER' : ($percent < 20 ? 'ERROR' : '')));
+      if ($this->verbose && $is_covered && $percent != 100)
+      {
+        $output->comment(sprintf("missing: %s", $this->format_range($missing_lines)));
+      }
+    }
+
+    $output->echoln(sprintf("TOTAL COVERAGE: %3.0f%%", $total_php_lines ? $total_covered_lines * 100 / $total_php_lines : 0));
+  }
+
+  public static function get_php_lines($content)
+  {
+    if (is_readable($content))
+    {
+      $content = file_get_contents($content);
+    }
+
+    $tokens = token_get_all($content);
+    $php_lines = array();
+    $current_line = 1;
+    $in_class = false;
+    $in_function = false;
+    $in_function_declaration = false;
+    $end_of_current_expr = true;
+    $open_braces = 0;
+    foreach ($tokens as $token)
+    {
+      if (is_string($token))
+      {
+        switch ($token)
+        {
+          case '=':
+            if (false === $in_class || (false !== $in_function && !$in_function_declaration))
+            {
+              $php_lines[$current_line] = true;
+            }
+            break;
+          case '{':
+            ++$open_braces;
+            $in_function_declaration = false;
+            break;
+          case ';':
+            $in_function_declaration = false;
+            $end_of_current_expr = true;
+            break;
+          case '}':
+            $end_of_current_expr = true;
+            --$open_braces;
+            if ($open_braces == $in_class)
+            {
+              $in_class = false;
+            }
+            if ($open_braces == $in_function)
+            {
+              $in_function = false;
+            }
+            break;
+        }
+
+        continue;
+      }
+
+      list($id, $text) = $token;
+
+      switch ($id)
+      {
+        case T_CURLY_OPEN:
+        case T_DOLLAR_OPEN_CURLY_BRACES:
+          ++$open_braces;
+          break;
+        case T_WHITESPACE:
+        case T_OPEN_TAG:
+        case T_CLOSE_TAG:
+          $end_of_current_expr = true;
+          $current_line += count(explode("\n", $text)) - 1;
+          break;
+        case T_COMMENT:
+        case T_DOC_COMMENT:
+          $current_line += count(explode("\n", $text)) - 1;
+          break;
+        case T_CLASS:
+          $in_class = $open_braces;
+          break;
+        case T_FUNCTION:
+          $in_function = $open_braces;
+          $in_function_declaration = true;
+          break;
+        case T_AND_EQUAL:
+        case T_BREAK:
+        case T_CASE:
+        case T_CATCH:
+        case T_CLONE:
+        case T_CONCAT_EQUAL:
+        case T_CONTINUE:
+        case T_DEC:
+        case T_DECLARE:
+        case T_DEFAULT:
+        case T_DIV_EQUAL:
+        case T_DO:
+        case T_ECHO:
+        case T_ELSEIF:
+        case T_EMPTY:
+        case T_ENDDECLARE:
+        case T_ENDFOR:
+        case T_ENDFOREACH:
+        case T_ENDIF:
+        case T_ENDSWITCH:
+        case T_ENDWHILE:
+        case T_EVAL:
+        case T_EXIT:
+        case T_FOR:
+        case T_FOREACH:
+        case T_GLOBAL:
+        case T_IF:
+        case T_INC:
+        case T_INCLUDE:
+        case T_INCLUDE_ONCE:
+        case T_INSTANCEOF:
+        case T_ISSET:
+        case T_IS_EQUAL:
+        case T_IS_GREATER_OR_EQUAL:
+        case T_IS_IDENTICAL:
+        case T_IS_NOT_EQUAL:
+        case T_IS_NOT_IDENTICAL:
+        case T_IS_SMALLER_OR_EQUAL:
+        case T_LIST:
+        case T_LOGICAL_AND:
+        case T_LOGICAL_OR:
+        case T_LOGICAL_XOR:
+        case T_MINUS_EQUAL:
+        case T_MOD_EQUAL:
+        case T_MUL_EQUAL:
+        case T_NEW:
+        case T_OBJECT_OPERATOR:
+        case T_OR_EQUAL:
+        case T_PLUS_EQUAL:
+        case T_PRINT:
+        case T_REQUIRE:
+        case T_REQUIRE_ONCE:
+        case T_RETURN:
+        case T_SL:
+        case T_SL_EQUAL:
+        case T_SR:
+        case T_SR_EQUAL:
+        case T_SWITCH:
+        case T_THROW:
+        case T_TRY:
+        case T_UNSET:
+        case T_UNSET_CAST:
+        case T_USE:
+        case T_WHILE:
+        case T_XOR_EQUAL:
+          $php_lines[$current_line] = true;
+          $end_of_current_expr = false;
+          break;
+        default:
+          if (false === $end_of_current_expr)
+          {
+            $php_lines[$current_line] = true;
+          }
+      }
+    }
+
+    return $php_lines;
+  }
+
+  public function compute($content, $cov)
+  {
+    $php_lines = self::get_php_lines($content);
+
+    // we remove from $cov non php lines
+    foreach (array_diff_key($cov, $php_lines) as $line => $tmp)
+    {
+      unset($cov[$line]);
+    }
+
+    return array($cov, $php_lines);
+  }
+
+  public function format_range($lines)
+  {
+    sort($lines);
+    $formatted = '';
+    $first = -1;
+    $last = -1;
+    foreach ($lines as $line)
+    {
+      if ($last + 1 != $line)
+      {
+        if ($first != -1)
+        {
+          $formatted .= $first == $last ? "$first " : "[$first - $last] ";
+        }
+        $first = $line;
+        $last = $line;
+      }
+      else
+      {
+        $last = $line;
+      }
+    }
+    if ($first != -1)
+    {
+      $formatted .= $first == $last ? "$first " : "[$first - $last] ";
+    }
+
+    return $formatted;
+  }
+}
+
+class lime_registration
+{
+  public $files = array();
+  public $extension = '.php';
+  public $base_dir = '';
+
+  public function register($files_or_directories)
+  {
+    foreach ((array) $files_or_directories as $f_or_d)
+    {
+      if (is_file($f_or_d))
+      {
+        $this->files[] = realpath($f_or_d);
+      }
+      elseif (is_dir($f_or_d))
+      {
+        $this->register_dir($f_or_d);
+      }
+      else
+      {
+        throw new Exception(sprintf('The file or directory "%s" does not exist.', $f_or_d));
+      }
+    }
+  }
+
+  public function register_glob($glob)
+  {
+    if ($dirs = glob($glob))
+    {
+      foreach ($dirs as $file)
+      {
+        $this->files[] = realpath($file);
+      }
+    }
+  }
+
+  public function register_dir($directory)
+  {
+    if (!is_dir($directory))
+    {
+      throw new Exception(sprintf('The directory "%s" does not exist.', $directory));
+    }
+
+    $files = array();
+
+    $current_dir = opendir($directory);
+    while ($entry = readdir($current_dir))
+    {
+      if ($entry == '.' || $entry == '..') continue;
+
+      if (is_dir($entry))
+      {
+        $this->register_dir($entry);
+      }
+      elseif (preg_match('#'.$this->extension.'$#', $entry))
+      {
+        $files[] = realpath($directory.DIRECTORY_SEPARATOR.$entry);
+      }
+    }
+
+    $this->files = array_merge($this->files, $files);
+  }
+
+  protected function get_relative_file($file)
+  {
+    return str_replace(DIRECTORY_SEPARATOR, '/', str_replace(array(realpath($this->base_dir).DIRECTORY_SEPARATOR, $this->extension), '', $file));
+  }
+}
属性に変更があったパス: HatenaSyntax/tags/release-1.0.4-20100210131712/test/lime.php
___________________________________________________________________
名前: svn:keywords
+ Id

HatenaSyntax/tags/release-1.0.4-20100210131712/test/testall.php

@@ -0,0 +1,7 @@
+<?php
+include_once dirname(__FILE__) . '/t.php';
+
+$lime = new lime_harness(null);
+$lime->register_glob(dirname(__FILE__) . '/lib/*.php');
+$lime->register_glob(dirname(__FILE__) . '/lib/HatenaSyntax/*.php');
+$lime->run();
属性に変更があったパス: HatenaSyntax/tags/release-1.0.4-20100210131712/test/testall.php
___________________________________________________________________
名前: svn:keywords
+ Id

HatenaSyntax/tags/release-1.0.4-20100210131712/sample/sample1.php

@@ -0,0 +1,185 @@
+<?php
+include_once dirname(__FILE__) . '/../lib/HatenaSyntax.php';
+
+
+$str = '*header1
+[:contents]
+
+[http://google.com:title]
+
+**header2
+
+:definition term:definition description
+::description2
+
+-list1
+++fuga2
+++hoge3
+---list4
+---list5
+-list6
+
+paragraph((footnote))
+[[keywordlink]]
+[][[nulllink]][]
+
+|*table header |*table header2 |
+|apple         |1              |
+|orange        |2              |
+
+>|
+hoge
+
+fuga|<
+
+[http://example.com/example.gif:image]
+
+>>
+***blockquote header
+fuga
+<<
+
+>|php|
+<?php
+echo "hogehoge";||<
+
+[http://google.com]
+
+';
+
+function spreHandler($type, Array $lines)
+{
+    foreach ($lines as &$line) $line = htmlspecialchars($line, ENT_QUOTES, 'utf-8');
+    $body = join(PHP_EOL, $lines);
+    return '<pre class="superpre ' . htmlspecialchars($type, ENT_QUOTES, 'utf-8')
+           . '">' . PHP_EOL . $body . '</pre>';
+}
+
+function keywordLinkHandler($path)
+{
+    return './' . $path;
+}
+
+function linkTitleHandler($url)
+{
+    return $url;
+}
+
+// オプションは全て省略可。第二引数自体も省略可。
+echo HatenaSyntax::render($str, array(
+
+    // ヘッダの基準値。デフォルトは1
+    'headerlevel' => 3,
+
+    // 記事の識別子。指定しない場合はランダムなIDが生成される
+    'id' => 'hoge',
+
+    // htmlをエスケープするか。デフォルトはtrue。
+    'htmlescape' => false,
+
+    // 記事本体を囲むdiv要素のクラス。デフォルトは'section'
+    'sectionclass' => 'section',
+
+    // 脚注を囲むdiv要素のクラス。デフォルトは'footnote'
+    'footnoteclass' => 'footnote',
+
+    // キーワード記法のキーワードをアドレスに処理するコールバック
+    'keywordlinkhanlder' => 'keywordLinkHandler',
+
+    // superpre記法の中身を処理するコールバック
+    'superprehandler' => 'spreHandler',
+
+    // [http://~~:title]のリンクを処理するコールバック
+    'linktitlehandler' => 'linkTitleHandler'
+));
+
+/* 結果
+<div class="section">
+<h3>header1<a name="ea703e7aa1efda0064eaa507d9e8ab7e_header_0" id="ea703e7aa1efda0064eaa507d9e8ab7e_header_0"></a></h3>
+<div class="toc"><ol>
+<li>
+<a href="#ea703e7aa1efda0064eaa507d9e8ab7e_header_0">header1</a>
+<ol>
+<li>
+<a href="#ea703e7aa1efda0064eaa507d9e8ab7e_header_1">header2</a>
+<ol>
+<li><a href="#ea703e7aa1efda0064eaa507d9e8ab7e_header_2">blockquote header</a></li>
+</ol>
+</li>
+</ol>
+</li>
+</ol>
+</div>
+
+<p><a href="http://google.com">http://google.com</a></p>
+
+<h4>header2<a name="ea703e7aa1efda0064eaa507d9e8ab7e_header_1" id="ea703e7aa1efda0064eaa507d9e8ab7e_header_1"></a></h4>
+
+<dl>
+<dt>definition term</dt>
+<dd>definition description</dd>
+<dd>description2</dd>
+</dl>
+
+<ul>
+<li>
+list1
+<ol>
+<li>fuga2</li>
+<li>
+hoge3
+<ul>
+<li>list4</li>
+<li>list5</li>
+</ul>
+</li>
+</ol>
+</li>
+<li>list6</li>
+</ul>
+
+
+<p>paragraph(<a href="#ea703e7aa1efda0064eaa507d9e8ab7e_footnote_1" name="ea703e7aa1efda0064eaa507d9e8ab7e_footnotelink_1" id="ea703e7aa1efda0064eaa507d9e8ab7e_footnotelink_1" title="footnote">*1</a>)</p>
+<p><a href="./keywordlink">keywordlink</a></p>
+<p>[[nulllink]]</p>
+
+<table>
+<tr>
+<th>table header </th>
+<th>table header2 </th>
+</tr>
+<tr>
+<td>apple         </td>
+<td>1              </td>
+</tr>
+<tr>
+<td>orange        </td>
+<td>2              </td>
+</tr>
+</table>
+
+<pre>
+hoge
+
+fuga</pre>
+
+<p><a href="http://example.com/example.gif"><img src="http://example.com/example.gif" /></a></p>
+
+<blockquote>
+<h5>blockquote header<a name="ea703e7aa1efda0064eaa507d9e8ab7e_header_2" id="ea703e7aa1efda0064eaa507d9e8ab7e_header_2"></a></h5>
+<p>fuga</p>
+</blockquote>
+
+<pre class="superpre php">
+&lt;?php
+echo &quot;hogehoge&quot;;</pre>
+
+<p><a href="http://google.com"></a></p>
+
+</div>
+
+
+<div class="footnote">
+<p><a href="#ea703e7aa1efda0064eaa507d9e8ab7e_footnotelink_1" name="ea703e7aa1efda0064eaa507d9e8ab7e_footnote_1" id="ea703e7aa1efda0064eaa507d9e8ab7e_footnote_1">*1</a>: footnote</p>
+</div>
+*/
属性に変更があったパス: HatenaSyntax/tags/release-1.0.4-20100210131712/sample/sample1.php
___________________________________________________________________
名前: svn:keywords
+ Id

HatenaSyntax/tags/release-1.0.4-20100210131712/sample/sample2.php

@@ -0,0 +1,77 @@
+<?php
+include_once dirname(__FILE__) . '/../lib/HatenaSyntax.php';
+
+$str = '*hogehoge
+
+fugafuga';
+
+var_dump(HatenaSyntax::parse($str));
+/*
+object(HatenaSyntax_Node)#217 (2) {
+  ["type":protected]=>
+  string(4) "root"
+  ["data":protected]=>
+  array(3) {
+    [0]=>
+    object(HatenaSyntax_Node)#213 (2) {
+      ["type":protected]=>
+      string(6) "header"
+      ["data":protected]=>
+      array(2) {
+        ["level"]=>
+        int(0)
+        ["body"]=>
+        array(8) {
+          [0]=>
+          string(1) "h"
+          [1]=>
+          string(1) "o"
+          [2]=>
+          string(1) "g"
+          [3]=>
+          string(1) "e"
+          [4]=>
+          string(1) "h"
+          [5]=>
+          string(1) "o"
+          [6]=>
+          string(1) "g"
+          [7]=>
+          string(1) "e"
+        }
+      }
+    }
+    [1]=>
+    object(HatenaSyntax_Node)#214 (2) {
+      ["type":protected]=>
+      string(14) "emptyparagraph"
+      ["data":protected]=>
+      string(0) ""
+    }
+    [2]=>
+    object(HatenaSyntax_Node)#216 (2) {
+      ["type":protected]=>
+      string(9) "paragraph"
+      ["data":protected]=>
+      array(8) {
+        [0]=>
+        string(1) "f"
+        [1]=>
+        string(1) "u"
+        [2]=>
+        string(1) "g"
+        [3]=>
+        string(1) "a"
+        [4]=>
+        string(1) "f"
+        [5]=>
+        string(1) "u"
+        [6]=>
+        string(1) "g"
+        [7]=>
+        string(1) "a"
+      }
+    }
+  }
+}
+*/
属性に変更があったパス: HatenaSyntax/tags/release-1.0.4-20100210131712/sample/sample2.php
___________________________________________________________________
名前: svn:keywords
+ Id

HatenaSyntax/tags/release-1.0.4-20100210131712/sample/sample3.php

@@ -0,0 +1,48 @@
+<?php
+include_once dirname(__FILE__) . '/../lib/HatenaSyntax.php';
+
+$text = <<<EOS
+*s1* hoge
+a
+
+*s2* fuga
+b
+
+*s3* piyo
+c
+
+EOS;
+
+$nodes = HatenaSyntax::parseAsSections($text);
+
+foreach ($nodes as $node) {
+	$name = HatenaSyntax::getSectionName($node);
+	echo "<!--{$name}-->\n";
+	echo HatenaSyntax::renderNode($node);
+	echo "\n";
+}
+
+/* 結果
+
+<!--s1-->
+<div class="section">
+<h1> hoge<a name="0a5f00d24e95fc67f4933ba9d374a09f_header_0" id="0a5f00d24e95fc67f4933ba9d374a09f_header_0"></a></h1>
+<p>a</p>
+
+</div>
+
+<!--s2-->
+<div class="section">
+<h1> fuga<a name="685dfe890c0b3e6cb12683009061a63d_header_0" id="685dfe890c0b3e6cb12683009061a63d_header_0"></a></h1>
+<p>b</p>
+
+</div>
+
+<!--s3-->
+<div class="section">
+<h1> piyo<a name="d510334f8a5d7d6144e323f5f90553c0_header_0" id="d510334f8a5d7d6144e323f5f90553c0_header_0"></a></h1>
+<p>c</p>
+
+</div>
+
+ */

HatenaSyntax/tags/release-1.0.4-20100210131712/lib/HatenaSyntax/Block.php

@@ -0,0 +1,109 @@
+<?php
+/**
+ * @package HatenaSyntax
+ * @author anatoo<anatoo@nequal.jp>
+ * @license http://www.opensource.org/licenses/mit-license.php MIT License
+ * @version $Id$
+ */
+
+class HatenaSyntax_Block implements PEG_IParser
+{
+    protected
+        $lineTable,
+        $paragraphCheckTable,
+        $firstCharTable,
+        $paragraph;
+
+    function __construct(HatenaSyntax_Locator $locator)
+    {
+        /*
+         * 当該パーサへのディスパッチの試行は以下の順で行われる。
+         * ディスパッチが失敗した場合、次のディスパッチが試行される
+         *
+         * 1. lineTableからのディスパッチ
+         * 2. paragraphCheckTableからのディスパッチ
+         * 3. firstCharTableからのディスパッチ
+         * 4. パラグラフ
+         *
+         */
+
+        $this->lineTable = array(
+            '' => $locator->emptyParagraph,
+            '>>' => PEG::choice(
+                $locator->blockquote,
+                $locator->paragraph
+            ),
+            '>|' => PEG::choice(
+                $locator->pre,
+                $locator->paragraph
+            ),
+            '>||' => PEG::choice(
+                $locator->superpre,
+                $locator->paragraph
+            ),
+            '[:contents]' => $locator->tableOfContents,
+            '====' => $locator->separator
+        );
+
+        // 行の最初の一文字が存在し、かつこの配列のキー以外だった場合
+        // 必ずパラグラフが来る
+        $this->paragraphCheckTable = array(
+            ':' => true,
+            '>' => true,
+            '|' => true,
+            '+' => true,
+            '-' => true,
+            '*' => true
+        );
+
+        $this->firstCharTable = array(
+            '*' => $locator->header,
+            '+' => $locator->list,
+            '-' => $locator->list,
+            '|' => PEG::choice(
+                $locator->table,
+                $locator->paragraph
+            ),
+            ':' => PEG::choice(
+                $locator->definitionList,
+                $locator->paragraph
+            ),
+            '>' => PEG::choice(
+                $locator->superpre,
+                $locator->blockquote,
+                $locator->noParagraph,
+                $locator->paragraph
+            )
+        );
+
+        $this->paragraph = $locator->paragraph;
+    }
+
+    function parse(PEG_IContext $context)
+    {
+        if ($context->eos()) {
+            return PEG::failure();
+        }
+
+        $line = $context->readElement();
+        $context->seek($context->tell() - 1);
+
+        // 行でディスパッチ
+        if (isset($this->lineTable[$line])) {
+            return $this->lineTable[$line]->parse($context);
+        }
+
+        $char = substr($line, 0, 1);
+
+        // 最初の文字でパラグラフかどうか判断
+        if (!isset($this->paragraphCheckTable[$char])) {
+            return $this->paragraph->parse($context);
+        }
+
+        if (isset($this->firstCharTable[$char])) {
+            return $this->firstCharTable[$char]->parse($context);
+        }
+
+        return $this->paragraph->parse($context);
+    }
+}
属性に変更があったパス: HatenaSyntax/tags/release-1.0.4-20100210131712/lib/HatenaSyntax/Block.php
___________________________________________________________________
名前: svn:keywords
+ Id

HatenaSyntax/tags/release-1.0.4-20100210131712/lib/HatenaSyntax/NodeCreater.php

@@ -0,0 +1,38 @@
+<?php
+/**
+ * @package HatenaSyntax
+ * @author anatoo<anatoo@nequal.jp>
+ * @license http://www.opensource.org/licenses/mit-license.php MIT License
+ * @version $Id$
+ */
+
+class HatenaSyntax_NodeCreater implements PEG_IParser
+{
+    protected $type, $keys, $parser;
+    function __construct($type, PEG_IParser $parser, Array $keys = array())
+    {
+        $this->type = $type;
+        $this->keys = $keys;
+        $this->parser = $parser;
+    }
+    function parse(PEG_IContext $context)
+    {
+        $offset = $context->tell();
+        $result = $this->parser->parse($context);
+
+        if ($result instanceof PEG_Failure) {
+            return $result;
+        }
+
+        $data = array();
+        if (count($this->keys) > 0) foreach ($this->keys as $i => $key) {
+            $data[$key] = $result[$i];
+        }
+        else {
+            $data = $result;
+        }
+
+        return new HatenaSyntax_Node(
+            $this->type, $data, $offset, spl_object_hash($context));
+    }
+}
属性に変更があったパス: HatenaSyntax/tags/release-1.0.4-20100210131712/lib/HatenaSyntax/NodeCreater.php
___________________________________________________________________
名前: svn:keywords
+ Id

HatenaSyntax/tags/release-1.0.4-20100210131712/lib/HatenaSyntax/Quote.php

@@ -0,0 +1,41 @@
+<?php
+/**
+ * @package HatenaSyntax
+ * @author anatoo<anatoo@nequal.jp>
+ * @license http://www.opensource.org/licenses/mit-license.php MIT License
+ * @version $Id$
+ */
+
+class HatenaSyntax_Quote implements PEG_IParser
+{
+    protected $child, $parser;
+
+    function __construct(PEG_IParser $child)
+    {
+        $this->child = $child;
+
+        $this->parser = PEG::seq(
+            PEG::callbackAction(array($this, 'mapHeader'), PEG::anything()),
+            PEG::many(PEG::subtract($this->child, '<<')),
+            PEG::drop('<<')
+        );
+    }
+
+    function parse(PEG_IContext $context)
+    {
+        return $this->parser->parse($context);
+    }
+
+    function mapHeader($line)
+    {
+        if (substr($line, 0, 1) !== '>') {
+            return PEG::failure();
+        }
+
+        if (!preg_match('#^>(|https?://[^>]+)>$#', $line, $matches)) {
+            return PEG::failure();
+        }
+
+        return $matches[1] === '' ? false : $matches[1];
+    }
+}
属性に変更があったパス: HatenaSyntax/tags/release-1.0.4-20100210131712/lib/HatenaSyntax/Quote.php
___________________________________________________________________
名前: svn:keywords
+ Id

HatenaSyntax/tags/release-1.0.4-20100210131712/lib/HatenaSyntax/Tree.php

@@ -0,0 +1,66 @@
+<?php
+/**
+ * @package HatenaSyntax
+ * @author anatoo<anatoo@nequal.jp>
+ * @license http://www.opensource.org/licenses/mit-license.php MIT License
+ * @version $Id$
+ */
+
+class HatenaSyntax_Tree
+{
+    /**
+     * array('level' => ?, 'value' => ?)の配列を渡す
+     *
+     * @param array $arr
+     */
+    static function make(Array $arr)
+    {
+        return new HatenaSyntax_Tree_Root(self::makeNodeArray($arr));
+    }
+
+    static protected function makeNodeArray(Array $arr)
+    {
+        $i = 0;
+        $len = count($arr);
+        $tree_arr = array();
+        $min_level = self::fetchMinLevel($arr);
+        while ($i < $len) {
+            list($tree_arr[], $i) = self::makeNode($arr, $i, $min_level);
+        }
+        return $tree_arr;
+    }
+
+    static protected function makeNode(Array $arr, $i, $min_level)
+    {
+        $children = array();
+        $len = count($arr);
+        if ($min_level < $arr[$i]['level']) {
+            // Node
+            for (; $i < $len && $min_level < $arr[$i]['level']; $i++) {
+                $children[] = $arr[$i];
+            }
+            return array(new HatenaSyntax_Tree_Node(self::makeNodeArray($children)), $i);
+        }
+        else {
+            // NodeかLeaf
+            $value = $arr[$i]['value'];
+            $i++;
+            for (; $i < $len && $min_level < $arr[$i]['level']; $i++) {
+                $children[] = $arr[$i];
+            }
+            $node = $children ? new HatenaSyntax_Tree_Node(self::makeNodeArray($children), $value) :
+                                new HatenaSyntax_Tree_Leaf($value);
+            return array($node, $i);
+        }
+    }
+
+    static protected function fetchMinLevel(Array $arr)
+    {
+        foreach ($arr as $elt) {
+            if (!isset($level) || $level > $elt['level']) {
+                $level = $elt['level'];
+            }
+        }
+        return $level;
+    }
+}
\ ファイルの末尾に改行がありません
属性に変更があったパス: HatenaSyntax/tags/release-1.0.4-20100210131712/lib/HatenaSyntax/Tree.php
___________________________________________________________________
名前: svn:keywords
+ Id

HatenaSyntax/tags/release-1.0.4-20100210131712/lib/HatenaSyntax/LineElement.php

@@ -0,0 +1,39 @@
+<?php
+/**
+ * @package HatenaSyntax
+ * @author anatoo<anatoo@nequal.jp>
+ * @license http://www.opensource.org/licenses/mit-license.php MIT License
+ * @version $Id$
+ */
+
+class HatenaSyntax_LineElement implements PEG_IParser
+{
+    protected $table;
+
+    function __construct(PEG_IParser $bracket, PEG_IParser $footnote, PEG_IParser $inlinetag)
+    {
+        $this->table = array(
+            '[' => PEG::choice($bracket, PEG::anything()),
+            '(' => PEG::choice($footnote, PEG::anything()),
+            '<' => PEG::choice($inlinetag, PEG::anything())
+        );
+    }
+
+    function parse(PEG_IContext $context)
+    {
+        if ($context->eos()) {
+            return PEG::failure();
+        }
+
+        $char = $context->readElement();
+
+        if (isset($this->table[$char])) {
+            $offset = $context->tell() - 1;
+            $context->seek($offset);
+
+            return $this->table[$char]->parse($context);
+        }
+
+        return $char;
+    }
+}
属性に変更があったパス: HatenaSyntax/tags/release-1.0.4-20100210131712/lib/HatenaSyntax/LineElement.php
___________________________________________________________________
名前: svn:keywords
+ Id

HatenaSyntax/tags/release-1.0.4-20100210131712/lib/HatenaSyntax/NoParagraph.php

@@ -0,0 +1,63 @@
+<?php
+/**
+ * @package HatenaSyntax
+ * @author anatoo<anatoo@nequal.jp>
+ * @license http://www.opensource.org/licenses/mit-license.php MIT License
+ * @version $Id: Paragraph.php 1574 2010-01-25 08:28:15Z anatoo $
+ */
+
+class HatenaSyntax_NoParagraph implements PEG_IParser
+{
+    protected $parser, $lineParser;
+
+    function __construct(PEG_IParser $element)
+    {
+        $end = new HatenaSyntax_Regex('#</p><$#');
+        $this->lineParser = PEG::many($element);
+        $this->parser = PEG::seq(
+            PEG::many(
+                PEG::subtract(PEG::anything(), $end)
+            ),
+            $end
+        );
+    }
+
+    function parse(PEG_IContext $context)
+    {
+        if ($context->eos()) {
+            return PEG::failure();
+        }
+
+        $line = $context->readElement();
+
+        if (!preg_match('#^><p( +class="([^"]+)")?>#', $line, $matches)) {
+            return PEG::failure();
+        }
+
+        $line = substr($line, strlen($matches[0]));
+        $attr = isset($matches[2]) && $matches[2] !== ''
+            ? array('class' => $matches[2])
+            : array();
+
+        // ><p>~~</p><みたいに一行で終わってるとき
+        if (substr($line, -5, 5) === '</p><') {
+            $line = substr($line, 0, -5);
+            $body = $this->lineParser->parse(PEG::context($line));
+
+            return array('p', $attr, $body);
+        }
+
+        $rest = $this->parser->parse($context);
+
+        if ($rest instanceof PEG_Failure) {
+            return $rest;
+        }
+
+        $line .= join(PHP_EOL, $rest[0]);
+        $line .= substr($rest[1], 0, -5);
+
+        $body = $this->lineParser->parse(PEG::context($line));
+
+        return array('p', $attr, $body);
+    }
+}

HatenaSyntax/tags/release-1.0.4-20100210131712/lib/HatenaSyntax/CommentRemover.php

@@ -0,0 +1,24 @@
+<?php
+/**
+ * @package HatenaSyntax
+ * @author anatoo<anatoo@nequal.jp>
+ * @license http://www.opensource.org/licenses/mit-license.php MIT License
+ * @version $Id$
+ */
+
+class HatenaSyntax_CommentRemover
+{
+	static function remove($str)
+	{
+		$str = preg_replace_callback(
+			'/<!--.*?-->|\n>\|[^|]*\|\n.*?\|\|<\n/s',
+			array(__CLASS__, 'replace'),
+			"\n" . $str . "\n");
+		return substr($str, 1, -1);
+	}
+
+	static function replace($matches)
+	{
+		return substr($matches[0], 0, 1) === '<' ? '' : $matches[0];
+	}
+}
属性に変更があったパス: HatenaSyntax/tags/release-1.0.4-20100210131712/lib/HatenaSyntax/CommentRemover.php
___________________________________________________________________
名前: svn:keywords
+ Id

HatenaSyntax/tags/release-1.0.4-20100210131712/lib/HatenaSyntax/Locator.php

@@ -0,0 +1,239 @@
+<?php
+/**
+ * @package HatenaSyntax
+ * @author anatoo<anatoo@nequal.jp>
+ * @license http://www.opensource.org/licenses/mit-license.php MIT License
+ * @version $Id$
+ */
+
+class HatenaSyntax_Locator
+{
+    protected $blockRef = null, $lineElementRef = null;
+    protected $shared = array();
+    protected $facade;
+
+    private function __construct()
+    {
+        $this->setup();
+    }
+
+    protected function setup()
+    {
+        $this->lineElement;
+        $this->lineElementRef = new HatenaSyntax_LineElement($this->bracket, $this->footnote, $this->inlineTag);
+        $this->block;
+        $this->blockRef = PEG::memo(new HatenaSyntax_Block($this));
+    }
+
+    static function it()
+    {
+        static $obj = null;
+        return $obj ? $obj : $obj = new self;
+    }
+
+    function __get($name)
+    {
+        return isset($this->shared[$name]) ?
+            $this->shared[$name] :
+            $this->shared[$name] = $this->{'create' . $name}();
+    }
+
+    protected function nodeCreater($type, PEG_IParser $parser, Array $keys = array())
+    {
+        return new HatenaSyntax_NodeCreater($type, $parser, $keys);
+    }
+
+    protected function createLineChar()
+    {
+        return PEG::anything();
+    }
+
+    protected function createFootnote()
+    {
+        $elt = PEG::subtract(
+            PEG::choice($this->bracket, $this->lineChar),
+            '))');
+
+        $parser = PEG::pack('((',
+                            PEG::many1($elt),
+                            '))');
+
+        return $this->nodeCreater('footnote', $parser);
+    }
+
+    protected function createInlineTag()
+    {
+        $parser = new HatenaSyntax_InlineTag($this->lineElement);
+
+        return $this->nodeCreater('inlinetag', $parser, array('name', 'body'));
+    }
+
+    protected function createLineElement()
+    {
+        return PEG::ref($this->lineElementRef);
+    }
+
+    protected function createLineSegment()
+    {
+        return PEG::many($this->lineElement);
+    }
+
+    protected function createHttpLink()
+    {
+        $title_char = PEG::subtract($this->lineChar, ']');
+        $title = PEG::choice(
+            PEG::second(':title=', PEG::join(PEG::many1($title_char))),
+            PEG::second(':title', '')
+        );
+
+        $url_char = PEG::subtract($this->lineChar, ']', ':title');
+        $url = PEG::join(PEG::seq(
+            PEG::choice('http://', 'https://'),
+            PEG::many1($url_char)));
+
+        $parser = PEG::seq($url, PEG::optional($title));
+
+        return $this->nodeCreater('httplink', $parser, array('href', 'title'));
+    }
+
+    protected function createImageLink()
+    {
+        $url_char = PEG::subtract($this->lineChar, ']', ':image]');
+        $url = PEG::join(PEG::seq(
+            PEG::choice('http://', 'https://'),
+            PEG::many1($url_char)));
+
+        $parser = PEG::first($url, ':image');
+
+        return $this->nodeCreater('imagelink', $parser);
+    }
+
+    protected function createKeywordLink()
+    {
+        $body = PEG::join(PEG::many1(PEG::subtract($this->lineChar, ']]')));
+        $body = PEG::subtract($body, 'javascript:');
+        $parser = PEG::pack('[', $body, ']');
+
+        return $this->nodeCreater('keywordlink', $parser);
+    }
+
+    protected function createNullLink()
+    {
+        $body = PEG::join(PEG::many1(PEG::subtract($this->lineChar, '[]')));
+        $parser = PEG::pack(']', $body, '[');
+
+        return $parser;
+    }
+
+    protected function createTableOfContents()
+    {
+        $parser = new HatenaSyntax_Regex('/^\[:contents]$/');
+
+        return $this->nodeCreater('tableofcontents', $parser);
+    }
+
+    protected function createInlineTableOfContents()
+    {
+        $parser = PEG::token(':contents');
+        return $this->nodeCreater('tableofcontents', $parser);
+    }
+
+    protected function createBracket()
+    {
+        return PEG::pack('[', PEG::choice(
+            $this->inlineTableOfContents,
+            $this->nullLink,
+            $this->keywordLink,
+            $this->imageLink,
+            $this->httpLink),
+        ']');
+    }
+
+    protected function createSeparator()
+    {
+        $parser = PEG::token('====');
+        return $this->nodeCreater('separator', $parser);
+    }
+
+    protected function createDefinitionList()
+    {
+        $parser = new HatenaSyntax_DefinitionList($this->lineElement);
+        return $this->nodeCreater('definitionlist', $parser);
+    }
+
+    protected function createPre()
+    {
+        $parser = new HatenaSyntax_Pre($this->lineElement);
+
+        return $this->nodeCreater('pre', $parser);
+    }
+
+    protected function createSuperPre()
+    {
+        $parser = new HatenaSyntax_SuperPre;
+
+        return $this->nodeCreater('superpre', $parser, array('type', 'body'));
+    }
+
+    protected function createHeader()
+    {
+        $parser = new HatenaSyntax_Header($this->lineElement);
+
+        return $this->nodeCreater('header', $parser, array('level', 'name', 'body'));
+    }
+
+    protected function createNoParagraph()
+    {
+        $parser = new HatenaSyntax_NoParagraph($this->lineElement);
+
+        return $this->nodeCreater('noparagraph', $parser, array('tag', 'attr', 'body'));
+    }
+
+    protected function createList()
+    {
+        $parser = new HatenaSyntax_List($this->lineElement);
+
+        return $this->nodeCreater('list', $parser);
+    }
+
+    protected function createTable()
+    {
+        $parser = new HatenaSyntax_Table($this->lineElement);
+
+        return $this->nodeCreater('table', $parser);
+    }
+
+    protected function createBlockQuote()
+    {
+        $parser = new HatenaSyntax_Quote($this->block);
+
+        return $this->nodeCreater('blockquote', $parser, array('url', 'body'));
+    }
+
+    protected function createParagraph()
+    {
+        $parser = new HatenaSyntax_Paragraph($this->lineElement);
+
+        return $this->nodeCreater('paragraph', $parser);
+    }
+
+    protected function createEmptyParagraph()
+    {
+        $parser = PEG::count(PEG::many1(PEG::token('')));
+
+        return $this->nodeCreater('emptyparagraph', $parser);
+    }
+
+    protected function createBlock()
+    {
+        $parser = PEG::ref($this->blockRef);
+
+        return $parser;
+    }
+
+    protected function createParser()
+    {
+        return $this->nodeCreater('root', PEG::many($this->block));
+    }
+
+}
属性に変更があったパス: HatenaSyntax/tags/release-1.0.4-20100210131712/lib/HatenaSyntax/Locator.php
___________________________________________________________________
名前: svn:keywords
+ Id

HatenaSyntax/tags/release-1.0.4-20100210131712/lib/HatenaSyntax/Paragraph.php

@@ -0,0 +1,32 @@
+<?php
+/**
+ * @package HatenaSyntax
+ * @author anatoo<anatoo@nequal.jp>
+ * @license http://www.opensource.org/licenses/mit-license.php MIT License
+ * @version $Id$
+ */
+
+class HatenaSyntax_Paragraph implements PEG_IParser
+{
+    protected $parser, $line;
+
+    function __construct(PEG_IParser $lineelt)
+    {
+        $this->parser = PEG::callbackAction(
+            array($this, 'map'),
+            PEG::anything()
+        );
+        $this->line = PEG::many($lineelt);
+    }
+
+    function parse(PEG_IContext $context)
+    {
+        return $this->parser->parse($context);
+    }
+
+    function map($line)
+    {
+        return $this->line->parse(PEG::context($line));
+    }
+
+}
属性に変更があったパス: HatenaSyntax/tags/release-1.0.4-20100210131712/lib/HatenaSyntax/Paragraph.php
___________________________________________________________________
名前: svn:keywords
+ Id

HatenaSyntax/tags/release-1.0.4-20100210131712/lib/HatenaSyntax/SuperPre.php

@@ -0,0 +1,57 @@
+<?php
+/**
+ * @package HatenaSyntax
+ * @author anatoo<anatoo@nequal.jp>
+ * @license http://www.opensource.org/licenses/mit-license.php MIT License
+ * @version $Id$
+ */
+
+class HatenaSyntax_SuperPre implements PEG_IParser
+{
+    protected $parser;
+
+    function __construct()
+    {
+        $end = new HatenaSyntax_Regex('/\|\|<$/');
+        $this->parser = PEG::callbackAction(
+            array($this, 'map'),
+            PEG::seq(
+                $this->header(),
+                PEG::many(PEG::subtract(PEG::anything(), $end)),
+                $end
+            )
+        );
+    }
+
+    function parse(PEG_IContext $context)
+    {
+        return $this->parser->parse($context);
+    }
+
+    function map(Array $superpre)
+    {
+        list($type, $body, $end) = $superpre;
+
+        if ($end !== '||<') {
+            $body[] = substr($end, 0, -3);
+        }
+
+        return array($type, $body);
+    }
+
+    function header()
+    {
+        return PEG::callbackAction(
+            array($this, 'mapHeader'),
+            PEG::anything());
+    }
+
+    function mapHeader($line)
+    {
+        if (!preg_match('/^>\|([a-zA-Z0-9]*)\|$/', $line, $matches)) {
+            return PEG::failure();
+        }
+
+        return $matches[1];
+    }
+}
属性に変更があったパス: HatenaSyntax/tags/release-1.0.4-20100210131712/lib/HatenaSyntax/SuperPre.php
___________________________________________________________________
名前: svn:keywords
+ Id

HatenaSyntax/tags/release-1.0.4-20100210131712/lib/HatenaSyntax/Renderer.php

@@ -0,0 +1,345 @@
+<?php
+/**
+ * @package HatenaSyntax
+ * @author anatoo<anatoo@nequal.jp>
+ * @license http://www.opensource.org/licenses/mit-license.php MIT License
+ * @version $Id$
+ */
+
+class HatenaSyntax_Renderer
+{
+    protected
+        $config,
+        $footnote,
+        $fncount,
+        $root,
+        $treeRenderer,
+        $headerCount;
+
+    function __construct(Array $config = array())
+    {
+        $this->config = $config + array(
+            'headerlevel'        => 1,
+            'htmlescape'         => true,
+            'id'                 => uniqid('sec'),
+            'sectionclass'       => 'section',
+            'footnoteclass'      => 'footnote',
+            'keywordlinkhandler' => array($this, 'keywordLinkHandler'),
+            'superprehandler'    => array($this, 'superPreHandler'),
+            'linktitlehandler'   => array($this, 'linkTitleHandler')
+        );
+
+        $this->treeRenderer = new HatenaSyntax_TreeRenderer(
+            array($this, 'listItemCallback'),
+            array($this, 'isOrderedCallback'));
+    }
+
+    static function linkTitleHandler($url)
+    {
+        return $url;
+    }
+
+    static function superPreHandler($type, $lines)
+    {
+        $body = join(PHP_EOL, array_map(array('HatenaSyntax_Renderer', 'escape'), $lines));
+        return '<pre class="superpre">' . PHP_EOL . $body . '</pre>';
+    }
+
+    static function keywordLinkHandler($path)
+    {
+        return './' . $path;
+    }
+
+    function listItemCallback(Array $data)
+    {
+        list(, $lineSegment) = $data;
+        return $this->renderLineSegment($lineSegment);
+    }
+
+    function isOrderedCallback(HatenaSyntax_Tree_INode $node)
+    {
+        $children = $node->getChildren();
+        foreach ($children as $child) {
+            if ($child->hasValue()) {
+                $buf = $child->getValue();
+                return $buf[0] === '+';
+            }
+        }
+        return false;
+    }
+
+    function render(HatenaSyntax_Node $rootnode)
+    {
+        if ($rootnode->getType() !== 'root') throw new InvalidArgumentException();
+
+        $this->footnote = '';
+        $this->fncount = 0;
+        $this->root = $rootnode;
+        $this->headerCount = 0;
+
+        $ret = $this->renderNode($rootnode);
+        $ret = '<div class="' . $this->config['sectionclass'] . '">' . PHP_EOL . $ret . PHP_EOL . '</div>' . PHP_EOL;
+        if ($this->fncount > 0) {
+            $ret .= PHP_EOL . PHP_EOL . '<div class="' . $this->config['footnoteclass'] . '">' .
+                    PHP_EOL . $this->footnote .  '</div>';
+        }
+
+        return $ret;
+    }
+
+    function renderTitle(HatenaSyntax_Node $root)
+    {
+        if ($root->getType() !== 'root') {
+            throw new InvalidArgumentException();
+        }
+
+        $this->footnote = '';
+        $this->fncount = 0;
+        $this->root = $root;
+        $this->headerCount = 0;
+
+        $nodes = $root->getData();
+
+        if (isset($nodes[0]) && $nodes[0]->isTopHeader()) {
+            return strip_tags($this->renderLineSegment($nodes[0]->at('body')));
+        }
+        return '';
+    }
+
+    protected function renderSeparator()
+    {
+        return '<div class="separator"></div>' . PHP_EOL;
+    }
+
+    protected function renderTableOfContents()
+    {
+        $tocRenderer = new HatenaSyntax_TOCRenderer();
+        return $tocRenderer->render($this->root, $this->config['id']);
+    }
+
+    protected function renderNode(HatenaSyntax_Node $node)
+    {
+        $ret = $this->{'render' . $node->getType()}($node->getData());
+        return $ret;
+    }
+
+    protected function renderRoot(Array $arr)
+    {
+        foreach ($arr as &$elt) $elt = $this->renderNode($elt);
+        return join(PHP_EOL, $arr);
+    }
+
+    protected function renderHeader(Array $data)
+    {
+        $level  = $data['level'] + $this->config['headerlevel'];
+        $name   = md5($this->config['id']) . '_header_' . $this->headerCount++;
+        $anchor = '<a name="' . $name . '" id="' . $name . '"></a>';
+
+        return "<h{$level}>" . $this->renderLineSegment($data['body']) . $anchor . "</h{$level}>";
+    }
+
+    protected function renderNoParagraph(Array $data)
+    {
+        $ret = '';
+        $ret .= "<{$data['tag']}";
+        foreach ($data['attr'] as $name => $value) {
+            $ret .= " {$name}=\"{$value}\"";
+        }
+        $ret .= ">" . PHP_EOL;
+
+        $ret .= $this->renderLineSegment($data['body']);
+
+        $ret .= PHP_EOL . "</{$data['tag']}>" . PHP_EOL;
+
+        return $ret;
+    }
+
+    protected function renderLineSegment(Array $data)
+    {
+        $data = self::normalize($data);
+        foreach ($data as &$elt) {
+            $elt = !$elt instanceof HatenaSyntax_Node
+                ? ($this->config['htmlescape'] ? $this->escape($elt) : $elt)
+                : $this->renderNode($elt);
+        }
+        return join('', $data);
+    }
+
+    protected function renderFootnote(Array $data)
+    {
+        $this->fncount++;
+        $id = md5($this->config['id']);
+        $n = $this->fncount;
+        $title = $body = $this->renderLineSegment($data);
+        $title = strip_tags($body);
+        if (!$this->config['htmlescape']) {
+            $title = $this->escape($title);
+        }
+
+        $fnname = sprintf('%s_footnote_%d', $id, $n);
+        $fnlinkname = sprintf('%s_footnotelink_%d', $id, $n);
+        $this->footnote .= sprintf('<p><a href="#%s" name="%s" id="%s">*%d</a>: %s</p>' . PHP_EOL, $fnlinkname, $fnname, $fnname, $n, $body);
+        return sprintf('(<a href="#%s" name="%s" id="%s" title="%s">*%d</a>)', $fnname, $fnlinkname, $fnlinkname, $title, $n);
+    }
+
+    protected function renderInlineTag(Array $data)
+    {
+        return
+            "<{$data['name']}>"
+            . $this->renderLineSegment($data['body'])
+            . "</{$data['name']}>";
+    }
+
+    protected function renderHttpLink(Array $data)
+    {
+        list($href, $title) = array($data['href'], $data['title']);
+
+        if ($title === '') {
+            $title = call_user_func($this->config['linktitlehandler'], $href);
+        }
+        elseif ($title === false) {
+            $title = $href;
+        }
+
+        return sprintf('<a href="%s">%s</a>', self::escape($href), self::escape($title));
+    }
+
+    protected function renderImageLink($url)
+    {
+        $url = self::escape($url);
+        return '<a href="' . $url . '"><img src="' . $url . '" /></a>';
+    }
+
+    protected function renderKeywordLink($path)
+    {
+        $href = call_user_func($this->config['keywordlinkhandler'], $path);
+        return '<a href="' . self::escape($href) . '">' . self::escape($path) . '</a>';
+    }
+
+    protected function renderDefinitionList(Array $data)
+    {
+        foreach ($data as &$elt) $elt = $this->renderDefinition($elt);
+        return join(PHP_EOL, array('<dl>', join(PHP_EOL, $data), '</dl>'));
+    }
+
+    protected function renderDefinition(Array $data)
+    {
+        list($dt, $dd) = $data;
+        $ret = array();
+        if ($dt) $ret[] = '<dt>' . $this->renderLineSegment($dt) . '</dt>';
+        $ret[] = '<dd>' . $this->renderLineSegment($dd) . '</dd>';
+        return join(PHP_EOL, $ret);
+    }
+
+    protected function renderPre(Array $data)
+    {
+        $ret = array();
+        $ret[] = '<pre>';
+        foreach ($data as &$elt) $elt = $this->renderLineSegment($elt);
+        $ret[] = join(PHP_EOL, $data) . '</pre>';
+        return join(PHP_EOL, $ret);
+    }
+
+    protected function renderSuperPre(Array $data)
+    {
+        $ret = array();
+        list($type, $lines) = array($data['type'], $data['body']);
+        $ret[] = call_user_func($this->config['superprehandler'], $type, $lines);
+        return join(PHP_EOL, $ret);
+    }
+
+    protected function renderTable(Array $data)
+    {
+        $ret = array();
+        $ret[] = '<table>';
+        foreach ($data as $tr) {
+            $ret[] = '<tr>';
+            foreach ($tr as $td) $ret[] = $this->renderTableCell($td[0], $td[1]);
+            $ret[] = '</tr>';
+        }
+        $ret[] = '</table>';
+        return join(PHP_EOL, $ret);
+    }
+
+    protected function renderTableCell($header, $segment)
+    {
+        $tag = $header ? 'th' : 'td';
+        $ret = "<{$tag}>" . $this->renderLineSegment($segment) . "</{$tag}>";
+        return $ret;
+    }
+
+    protected function renderBlockQuote(Array $arr)
+    {
+        $ret = array();
+        $ret[] = '<blockquote>';
+        foreach ($arr['body'] as $elt) $ret[] = $this->renderNode($elt);
+        if ($arr['url']) $ret[] = '<cite><a href="' . self::escape($arr['url']) . '">' . self::escape($arr['url']) . '</a></cite>';
+        $ret[] = '</blockquote>';
+        return join(PHP_EOL, $ret);
+    }
+
+    protected function renderParagraph(Array $data)
+    {
+        return '<p>' . $this->renderLineSegment($data) . '</p>';
+    }
+
+    protected function renderEmptyParagraph($data)
+    {
+        return str_repeat('<br />' . PHP_EOL, max($data - 1, 0));
+    }
+
+    protected function renderList(HatenaSyntax_Tree_Root $root)
+    {
+        return $this->treeRenderer->render($root);
+    }
+
+
+    protected static function escape($str)
+    {
+        if (!is_string($str)) {
+            debug_print_backtrace();
+            return;
+        }
+        return htmlspecialchars($str, ENT_QUOTES, 'UTF-8');
+    }
+
+    /**
+     * @param Array
+     * @return Array
+     */
+    protected static function normalize(Array $arr)
+    {
+        $ret = array();
+
+        while ($arr) {
+            list($elt, $arr) = self::segment($arr);
+            $ret[] = $elt;
+        }
+
+        return $ret;
+    }
+
+    /**
+     * @param Array
+     * @return Array array($elt, $rest)
+     */
+    static function segment(Array $arr)
+    {
+        $first = array_shift($arr);
+
+        if (!is_string($first)) {
+            return array($first, $arr);
+        }
+
+        $str = $first;
+        while ($arr) {
+            if (is_string($arr[0])) {
+                $str .= array_shift($arr);
+            }
+            else {
+                return array($str, $arr);
+            }
+        }
+        return array($str, array());
+    }
+}
属性に変更があったパス: HatenaSyntax/tags/release-1.0.4-20100210131712/lib/HatenaSyntax/Renderer.php
___________________________________________________________________
名前: svn:keywords
+ Id

HatenaSyntax/tags/release-1.0.4-20100210131712/lib/HatenaSyntax/Tree/INode.php

@@ -0,0 +1,19 @@
+<?php
+/**
+ * @package HatenaSyntax
+ * @author anatoo<anatoo@nequal.jp>
+ * @license http://www.opensource.org/licenses/mit-license.php MIT License
+ * @version $Id$
+ */
+
+interface HatenaSyntax_Tree_INode
+{
+    function hasValue();
+    function getValue();
+    function hasChildren();
+
+    // HatenaSyntax_Tree_INodeの配列を返す
+    function getChildren();
+
+    function getType();
+}
\ ファイルの末尾に改行がありません
属性に変更があったパス: HatenaSyntax/tags/release-1.0.4-20100210131712/lib/HatenaSyntax/Tree/INode.php
___________________________________________________________________
名前: svn:keywords
+ Id

HatenaSyntax/tags/release-1.0.4-20100210131712/lib/HatenaSyntax/Tree/Root.php

@@ -0,0 +1,44 @@
+<?php
+/**
+ * @package HatenaSyntax
+ * @author anatoo<anatoo@nequal.jp>
+ * @license http://www.opensource.org/licenses/mit-license.php MIT License
+ * @version $Id$
+ */
+
+include_once dirname(__FILE__) . '/INode.php';
+
+class HatenaSyntax_Tree_Root implements HatenaSyntax_Tree_INode
+{
+    protected $children;
+
+    function __construct(Array $children)
+    {
+        $this->children = $children;
+    }
+
+    function hasValue()
+    {
+        return false;
+    }
+
+    function getValue()
+    {
+        return null;
+    }
+
+    function hasChildren()
+    {
+        return true;
+    }
+
+    function getChildren()
+    {
+        return $this->children;
+    }
+
+    function getType()
+    {
+        return 'root';
+    }
+}
\ ファイルの末尾に改行がありません
属性に変更があったパス: HatenaSyntax/tags/release-1.0.4-20100210131712/lib/HatenaSyntax/Tree/Root.php
___________________________________________________________________
名前: svn:keywords
+ Id

HatenaSyntax/tags/release-1.0.4-20100210131712/lib/HatenaSyntax/Tree/Node.php

@@ -0,0 +1,44 @@
+<?php
+/**
+ * @package HatenaSyntax
+ * @author anatoo<anatoo@nequal.jp>
+ * @license http://www.opensource.org/licenses/mit-license.php MIT License
+ * @version $Id$
+ */
+
+include_once dirname(__FILE__) . '/INode.php';
+
+class HatenaSyntax_Tree_Node implements HatenaSyntax_Tree_INode
+{
+    protected $value, $children;
+
+    function __construct(Array $children, $value = null)
+    {
+        list($this->children, $this->value) = array($children, $value);
+    }
+
+    function hasValue()
+    {
+        return isset($this->value);
+    }
+
+    function getValue()
+    {
+        return $this->value;
+    }
+
+    function hasChildren()
+    {
+        return true;
+    }
+
+    function getChildren()
+    {
+        return $this->children;
+    }
+
+    function getType()
+    {
+        return 'node';
+    }
+}
\ ファイルの末尾に改行がありません
属性に変更があったパス: HatenaSyntax/tags/release-1.0.4-20100210131712/lib/HatenaSyntax/Tree/Node.php
___________________________________________________________________
名前: svn:keywords
+ Id

HatenaSyntax/tags/release-1.0.4-20100210131712/lib/HatenaSyntax/Tree/Leaf.php

@@ -0,0 +1,44 @@
+<?php
+/**
+ * @package HatenaSyntax
+ * @author anatoo<anatoo@nequal.jp>
+ * @license http://www.opensource.org/licenses/mit-license.php MIT License
+ * @version $Id$
+ */
+
+include_once dirname(__FILE__) . '/INode.php';
+
+class HatenaSyntax_Tree_Leaf implements HatenaSyntax_Tree_INode
+{
+    protected $value;
+
+    function __construct($value)
+    {
+        $this->value = $value;
+    }
+
+    function hasValue()
+    {
+        return true;
+    }
+
+    function getValue()
+    {
+        return $this->value;
+    }
+
+    function hasChildren()
+    {
+        return false;
+    }
+
+    function getChildren()
+    {
+        return array();
+    }
+
+    function getType()
+    {
+        return 'leaf';
+    }
+}
\ ファイルの末尾に改行がありません
属性に変更があったパス: HatenaSyntax/tags/release-1.0.4-20100210131712/lib/HatenaSyntax/Tree/Leaf.php
___________________________________________________________________
名前: svn:keywords
+ Id

HatenaSyntax/tags/release-1.0.4-20100210131712/lib/HatenaSyntax/Regex.php

@@ -0,0 +1,23 @@
+<?php
+/**
+ * @package HatenaSyntax
+ * @author anatoo<anatoo@nequal.jp>
+ * @license http://www.opensource.org/licenses/mit-license.php MIT License
+ * @version $Id$
+ */
+
+class HatenaSyntax_Regex implements PEG_IParser
+{
+    protected $regex;
+
+    function __construct($regex)
+    {
+        $this->regex = $regex;
+    }
+
+    function parse(PEG_IContext $context)
+    {
+        $elt = $context->readElement();
+        return preg_match($this->regex, $elt) ? $elt : PEG::failure();
+    }
+}
属性に変更があったパス: HatenaSyntax/tags/release-1.0.4-20100210131712/lib/HatenaSyntax/Regex.php
___________________________________________________________________
名前: svn:keywords
+ Id

HatenaSyntax/tags/release-1.0.4-20100210131712/lib/HatenaSyntax/InlineTag.php

@@ -0,0 +1,32 @@
+<?php
+/**
+ * @package HatenaSyntax
+ * @author anatoo<anatoo@nequal.jp>
+ * @license http://www.opensource.org/licenses/mit-license.php MIT License
+ * @version $Id$
+ */
+
+class HatenaSyntax_InlineTag implements PEG_IParser
+{
+    protected $parser;
+
+    function __construct(PEG_IParser $element)
+    {
+        $open = PEG::second('<', PEG::choice('del', 'strong', 'inc', 'em'), '>');
+        $close = PEG::second('</', PEG::choice('del', 'strong', 'inc', 'em'), '>');
+        $this->parser = PEG::seq($open, PEG::many(PEG::subtract($element, $close)), $close);
+    }
+
+    function parse(PEG_IContext $context)
+    {
+        $result = $this->parser->parse($context);
+
+        if ($result instanceof PEG_Failure) {
+            return $result;
+        }
+
+        list($open, $body, $close) = $result;
+
+        return $open !== $close ? PEG::failure() : array($open, $body);
+    }
+}
属性に変更があったパス: HatenaSyntax/tags/release-1.0.4-20100210131712/lib/HatenaSyntax/InlineTag.php
___________________________________________________________________
名前: svn:keywords
+ Id

HatenaSyntax/tags/release-1.0.4-20100210131712/lib/HatenaSyntax/List.php

@@ -0,0 +1,46 @@
+<?php
+/**
+ * @package HatenaSyntax
+ * @author anatoo<anatoo@nequal.jp>
+ * @license http://www.opensource.org/licenses/mit-license.php MIT License
+ * @version $Id$
+ */
+
+class HatenaSyntax_List implements PEG_IParser
+{
+    protected $parser, $li;
+
+    function __construct(PEG_IParser $lineelt)
+    {
+        $item = PEG::callbackAction(
+            array($this, 'mapLine'),
+            PEG::anything());
+
+        $this->parser = PEG::callbackAction(
+            array('HatenaSyntax_Tree', 'make'),
+            PEG::many1($item)
+        );
+
+        $this->li = PEG::callbackAction(
+            array('HatenaSyntax_Util', 'processListItem'),
+            PEG::seq(
+                PEG::many(PEG::char('+-')),
+                PEG::many($lineelt)
+            )
+        );
+    }
+
+    function parse(PEG_IContext $context)
+    {
+        return $this->parser->parse($context);
+    }
+
+    function mapLine($line)
+    {
+        if (in_array(substr($line, 0, 1), array('+', '-'), true)) {
+            return $this->li->parse(PEG::context($line));
+        }
+
+        return PEG::failure();
+    }
+}
属性に変更があったパス: HatenaSyntax/tags/release-1.0.4-20100210131712/lib/HatenaSyntax/List.php
___________________________________________________________________
名前: svn:keywords
+ Id

HatenaSyntax/tags/release-1.0.4-20100210131712/lib/HatenaSyntax/TOCRenderer.php

@@ -0,0 +1,105 @@
+<?php
+/**
+ * @package HatenaSyntax
+ * @author anatoo<anatoo@nequal.jp>
+ * @license http://www.opensource.org/licenses/mit-license.php MIT License
+ * @version $Id$
+ */
+
+class HatenaSyntax_TOCRenderer
+{
+    protected $headerCount;
+
+    function render(HatenaSyntax_Node $rootnode, $id)
+    {
+        $treeroot = HatenaSyntax_Tree::make($this->filter($rootnode));
+        $this->headerCount = 0;
+        $this->id = $id;
+        $renderer = new HatenaSyntax_TreeRenderer(array($this, 'renderHeader'));
+        return '<div class="toc">' . $renderer->render($treeroot) . '</div>';
+    }
+
+    protected function escape($str)
+    {
+        return htmlspecialchars($str, ENT_QUOTES);
+    }
+
+    function renderHeader($node)
+    {
+        $count = $this->headerCount++;
+        $buf = array();
+        $data = $node->getData();
+        foreach ($data['body'] as $leaf) {
+            if (is_string($leaf)) {
+                $buf[] = $leaf;
+            }
+            else {
+                $buf [] = $this->{'render' . $leaf->getType()}($lead->getData());
+            }
+        }
+        return '<a href="#' . md5($this->id) . '_header_' . $count . '">' . $this->escape(join('', $buf)) . '</a>';
+    }
+
+    protected function renderFootnote($data)
+    {
+        return '';
+    }
+
+    function filter(HatenaSyntax_Node $rootnode)
+    {
+        if ($rootnode->getType() !== 'root') throw new Exception;
+        $header_arr = $this->fetchHeader($rootnode);
+        $ret = array();
+        foreach ($header_arr as $header) {
+            $buf = $header->getData();
+            $ret[] = array('level' => $buf['level'], 'value' => $header);
+        }
+        return $ret;
+    }
+
+    protected function fetchHeader($node)
+    {
+        return $this->{'fetchHeaderIn' . $node->getType()}($node);
+    }
+
+    protected function fetchHeaderInRoot($node)
+    {
+        $buf = array();
+        foreach ($node->getData() as $node) {
+            $buf[] = $this->fetchHeader($node);
+        }
+
+        return $this->concat($buf);
+    }
+
+    protected function fetchHeaderInHeader($node)
+    {
+        return array($node);
+    }
+
+    protected function fetchHeaderInBlockQuote($node)
+    {
+        $buf = array();
+        $data = $node->getData();
+        foreach ($data['body'] as $node) {
+            $buf[] = $this->fetchHeader($node);
+        }
+        return $this->concat($buf);
+    }
+
+    function __call($name, $args)
+    {
+        if (preg_match('#^fetchHeaderIn\w+$#i', $name)) return array();
+        throw new Exception(sprintf('method(%s) not found', $name));
+    }
+
+    protected function concat(Array $target)
+    {
+        if (!$target) return array();
+        $target = array_reverse($target);
+        while (1 < count($target)) {
+            array_push($target, array_merge(array_pop($target), array_pop($target)));
+        }
+        return $target[0];
+    }
+}
属性に変更があったパス: HatenaSyntax/tags/release-1.0.4-20100210131712/lib/HatenaSyntax/TOCRenderer.php
___________________________________________________________________
名前: svn:keywords
+ Id

HatenaSyntax/tags/release-1.0.4-20100210131712/lib/HatenaSyntax/Util.php

@@ -0,0 +1,24 @@
+<?php
+/**
+ * @package HatenaSyntax
+ * @author anatoo<anatoo@nequal.jp>
+ * @license http://www.opensource.org/licenses/mit-license.php MIT License
+ * @version $Id$
+ */
+
+class HatenaSyntax_Util
+{
+    static function normalizeList(Array $data)
+    {
+        return HatenaSyntax_Tree::make($data);
+    }
+
+    static function processListItem(Array $li)
+    {
+        $ret = array();
+        $ret['level'] = count($li[0]) - 1;
+        $ret['value'] = array(end($li[0]), $li[1]);
+
+        return $ret;
+    }
+}
属性に変更があったパス: HatenaSyntax/tags/release-1.0.4-20100210131712/lib/HatenaSyntax/Util.php
___________________________________________________________________
名前: svn:keywords
+ Id

HatenaSyntax/tags/release-1.0.4-20100210131712/lib/HatenaSyntax/DefinitionList.php

@@ -0,0 +1,41 @@
+<?php
+/**
+ * @package HatenaSyntax
+ * @author anatoo<anatoo@nequal.jp>
+ * @license http://www.opensource.org/licenses/mit-license.php MIT License
+ * @version $Id$
+ */
+
+class HatenaSyntax_DefinitionList implements PEG_IParser
+{
+    protected $parser, $definition;
+
+    function __construct(PEG_IParser $elt)
+    {
+        $dt = PEG::many(PEG::subtract($elt, ':'));
+        $dd = PEG::many($elt);
+
+        $this->parser = PEG::many1(PEG::callbackAction(
+            array($this, 'map'),
+            PEG::anything()
+        ));
+
+        $sep = PEG::drop(':');
+        $this->definition = PEG::seq(
+            $sep,
+            $dt,
+            $sep,
+            $dd
+        );
+    }
+
+    function parse(PEG_IContext $context)
+    {
+        return $this->parser->parse($context);
+    }
+
+    function map($line)
+    {
+        return $this->definition->parse(PEG::context($line));
+    }
+}
属性に変更があったパス: HatenaSyntax/tags/release-1.0.4-20100210131712/lib/HatenaSyntax/DefinitionList.php
___________________________________________________________________
名前: svn:keywords
+ Id

HatenaSyntax/tags/release-1.0.4-20100210131712/lib/HatenaSyntax/Node.php

@@ -0,0 +1,51 @@
+<?php
+/**
+ * @package HatenaSyntax
+ * @author anatoo<anatoo@nequal.jp>
+ * @license http://www.opensource.org/licenses/mit-license.php MIT License
+ * @version $Id$
+ */
+
+class HatenaSyntax_Node
+{
+    protected $type, $offset, $data, $contextHash;
+    function __construct($type, $data = array(), $offset = null, $contextHash = null)
+    {
+        $this->type = $type;
+        $this->data = $data;
+        $this->offset = $offset;
+        $this->contextHash = $contextHash;
+    }
+
+    function getContextHash()
+    {
+        return $this->contextHash;
+    }
+
+    function getOffset()
+    {
+        return $this->offset;
+    }
+
+    function getType()
+    {
+        return $this->type;
+    }
+
+    function getData()
+    {
+        return $this->data;
+    }
+
+    function at($name, $defaultVal = null)
+    {
+        return array_key_exists($name, $this->data)
+            ? $this->data[$name]
+            : $defaultVal;
+    }
+
+    function isTopHeader()
+    {
+        return $this->type === 'header' && $this->at('level') === 0;
+    }
+}
属性に変更があったパス: HatenaSyntax/tags/release-1.0.4-20100210131712/lib/HatenaSyntax/Node.php
___________________________________________________________________
名前: svn:keywords
+ Id

HatenaSyntax/tags/release-1.0.4-20100210131712/lib/HatenaSyntax/Pre.php

@@ -0,0 +1,47 @@
+<?php
+/**
+ * @package HatenaSyntax
+ * @author anatoo<anatoo@nequal.jp>
+ * @license http://www.opensource.org/licenses/mit-license.php MIT License
+ * @version $Id$
+ */
+
+class HatenaSyntax_Pre implements PEG_IParser
+{
+    protected $line, $parser;
+
+    function __construct(PEG_IParser $elt)
+    {
+        $this->line = PEG::many($elt);
+
+        $end = new HatenaSyntax_Regex('/\|<$/');
+        $this->parser = PEG::callbackAction(
+            array($this, 'map'),
+            PEG::seq(
+                PEG::drop('>|'),
+                PEG::many(PEG::subtract(PEG::anything(), $end)),
+                $end
+            )
+        );
+    }
+
+    function parse(PEG_IContext $context)
+    {
+        return $this->parser->parse($context);
+    }
+
+    function map(Array $pre)
+    {
+        list($body, $end) = $pre;
+
+        if ($end !== '|<') {
+            $body[] = substr($end, 0, -2);
+        }
+
+        foreach ($body as &$line) {
+            $line = $this->line->parse(PEG::context($line));
+        }
+
+        return $body;
+    }
+}
属性に変更があったパス: HatenaSyntax/tags/release-1.0.4-20100210131712/lib/HatenaSyntax/Pre.php
___________________________________________________________________
名前: svn:keywords
+ Id

HatenaSyntax/tags/release-1.0.4-20100210131712/lib/HatenaSyntax/TreeRenderer.php

@@ -0,0 +1,78 @@
+<?php
+/**
+ * @package HatenaSyntax
+ * @author anatoo<anatoo@nequal.jp>
+ * @license http://www.opensource.org/licenses/mit-license.php MIT License
+ * @version $Id$
+ */
+
+class HatenaSyntax_TreeRenderer
+{
+    protected $valueCallback, $isOrderedCallback;
+
+    function __construct($valueCallback, $isOrderedCallback = false)
+    {
+        $this->valueCallback = $valueCallback;
+        $this->isOrderedCallback = $isOrderedCallback ? $isOrderedCallback : array($this, 'isOrderedDefaultCallback');
+    }
+
+    function isOrderedDefaultCallback($node)
+    {
+        return true;
+    }
+
+    protected function renderValue($value)
+    {
+        return call_user_func($this->valueCallback, $value);
+    }
+
+    protected function isOrdered($node)
+    {
+        return call_user_func($this->isOrderedCallback, $node);
+    }
+
+    protected function listOpenTag($bool)
+    {
+        return ($bool ? '<ol>' : '<ul>') . PHP_EOL;
+    }
+
+    protected function listCloseTag($bool)
+    {
+        return ($bool ? '</ol>' : '</ul>') . PHP_EOL;
+    }
+
+    function render(HatenaSyntax_Tree_Root $root)
+    {
+        $ordered = $this->isOrdered($root);
+        $ret = $this->listOpenTag($ordered);
+        foreach ($root->getChildren() as $child) {
+            $ret .= $this->_render($child);
+        }
+        $ret .= $this->listCloseTag($ordered);
+        return $ret;
+    }
+
+    protected function _render($node)
+    {
+        return $this->{'render' . $node->getType()}($node);
+    }
+
+    protected function renderNode($node)
+    {
+        $ret = '<li>' . PHP_EOL;
+        if ($node->hasValue()) $ret .= $this->renderValue($node->getValue());
+        $ordered = $this->isOrdered($node);
+        $ret .= PHP_EOL . $this->listOpenTag($ordered);
+        foreach ($node->getChildren() as $child) {
+            $ret .= $this->_render($child);
+        }
+        $ret .= $this->listCloseTag($ordered);
+        $ret .= '</li>' . PHP_EOL;
+        return $ret;
+    }
+
+    protected function renderLeaf($node)
+    {
+        return '<li>' . $this->renderValue($node->getValue()) . '</li>' . PHP_EOL;
+    }
+}
属性に変更があったパス: HatenaSyntax/tags/release-1.0.4-20100210131712/lib/HatenaSyntax/TreeRenderer.php
___________________________________________________________________
名前: svn:keywords
+ Id

HatenaSyntax/tags/release-1.0.4-20100210131712/lib/HatenaSyntax/Table.php

@@ -0,0 +1,43 @@
+<?php
+/**
+ * @package HatenaSyntax
+ * @author anatoo<anatoo@nequal.jp>
+ * @license http://www.opensource.org/licenses/mit-license.php MIT License
+ * @version $Id$
+ */
+
+class HatenaSyntax_Table implements PEG_IParser
+{
+    protected $parser, $line;
+
+    function __construct(PEG_IParser $lineelt)
+    {
+        $cellbody = PEG::many(PEG::subtract($lineelt, '|'));
+
+        $this->parser = PEG::many1(
+            PEG::callbackAction(
+                array($this, 'map'),
+                PEG::anything()
+            )
+        );
+
+        $this->line = PEG::second(
+            '|',
+            PEG::many1(
+                PEG::optional('*'),
+                $cellbody,
+                PEG::drop('|')),
+            PEG::eos()
+        );
+    }
+
+    function parse(PEG_IContext $context)
+    {
+        return $this->parser->parse($context);
+    }
+
+    function map($line)
+    {
+        return $this->line->parse(PEG::context($line));
+    }
+}
属性に変更があったパス: HatenaSyntax/tags/release-1.0.4-20100210131712/lib/HatenaSyntax/Table.php
___________________________________________________________________
名前: svn:keywords
+ Id

HatenaSyntax/tags/release-1.0.4-20100210131712/lib/HatenaSyntax/Header.php

@@ -0,0 +1,64 @@
+<?php
+/**
+ * @package HatenaSyntax
+ * @author anatoo<anatoo@nequal.jp>
+ * @license http://www.opensource.org/licenses/mit-license.php MIT License
+ * @version $Id$
+ */
+
+class HatenaSyntax_Header implements PEG_IParser
+{
+    protected $child, $parser;
+
+    function __construct(PEG_IParser $elt)
+    {
+        $this->child = PEG::many($elt);
+        $this->parser = PEG::callbackAction(array($this, 'map'), PEG::anything());
+    }
+
+    function parse(PEG_IContext $context)
+    {
+        return $this->parser->parse($context);
+    }
+
+    function map($line)
+    {
+        if (strpos($line, '*') === 0) {
+            list($level, $rest) = $this->toLevelAndRest((string)substr($line, 1));
+
+            list($name, $rest) = $level === 0
+                ? $this->toNameAndRest($rest)
+                : array(false, $rest);
+
+            $body = $this->child->parse(PEG::context($rest));
+
+            return array($level, $name, $body);
+        }
+
+        return PEG::failure();
+    }
+
+    protected function toLevelAndRest($line)
+    {
+        $level = 0;
+
+        for ($i = 0, $len = strlen($line); $i < $len; $i++) {
+            if ($line[$i] === '*') {
+                $level++;
+            } else {
+                break;
+            }
+        }
+
+        return array($level, (string)substr($line, $level));
+    }
+
+    protected function toNameAndRest($rest)
+    {
+        if (preg_match('/^([-[:alnum:]_]*)\*/', $rest, $matches)) {
+            return array($matches[1], (string)substr($rest, strlen($matches[0])));
+        }
+
+        return array(false, $rest);
+    }
+}
属性に変更があったパス: HatenaSyntax/tags/release-1.0.4-20100210131712/lib/HatenaSyntax/Header.php
___________________________________________________________________
名前: svn:keywords
+ Id

HatenaSyntax/tags/release-1.0.4-20100210131712/lib/HatenaSyntax.php

@@ -0,0 +1,229 @@
+<?php
+/**
+ * @package HatenaSyntax
+ * @author anatoo<anatoo@nequal.jp>
+ * @license http://www.opensource.org/licenses/mit-license.php MIT License
+ * @version $Id$
+ */
+
+include_once 'PEG.php';
+include_once dirname(__FILE__) . '/HatenaSyntax/Node.php';
+include_once dirname(__FILE__) . '/HatenaSyntax/Regex.php';
+include_once dirname(__FILE__) . '/HatenaSyntax/Locator.php';
+include_once dirname(__FILE__) . '/HatenaSyntax/NodeCreater.php';
+include_once dirname(__FILE__) . '/HatenaSyntax/InlineTag.php';
+include_once dirname(__FILE__) . '/HatenaSyntax/Renderer.php';
+include_once dirname(__FILE__) . '/HatenaSyntax/TOCRenderer.php';
+include_once dirname(__FILE__) . '/HatenaSyntax/Util.php';
+include_once dirname(__FILE__) . '/HatenaSyntax/Header.php';
+include_once dirname(__FILE__) . '/HatenaSyntax/Block.php';
+include_once dirname(__FILE__) . '/HatenaSyntax/LineElement.php';
+include_once dirname(__FILE__) . '/HatenaSyntax/Quote.php';
+include_once dirname(__FILE__) . '/HatenaSyntax/Table.php';
+include_once dirname(__FILE__) . '/HatenaSyntax/DefinitionList.php';
+include_once dirname(__FILE__) . '/HatenaSyntax/List.php';
+include_once dirname(__FILE__) . '/HatenaSyntax/Paragraph.php';
+include_once dirname(__FILE__) . '/HatenaSyntax/NoParagraph.php';
+include_once dirname(__FILE__) . '/HatenaSyntax/Pre.php';
+include_once dirname(__FILE__) . '/HatenaSyntax/SuperPre.php';
+include_once dirname(__FILE__) . '/HatenaSyntax/TreeRenderer.php';
+include_once dirname(__FILE__) . '/HatenaSyntax/Tree.php';
+include_once dirname(__FILE__) . '/HatenaSyntax/CommentRemover.php';
+include_once dirname(__FILE__) . '/HatenaSyntax/Tree/INode.php';
+include_once dirname(__FILE__) . '/HatenaSyntax/Tree/Node.php';
+include_once dirname(__FILE__) . '/HatenaSyntax/Tree/Root.php';
+include_once dirname(__FILE__) . '/HatenaSyntax/Tree/Leaf.php';
+
+class HatenaSyntax
+{
+    /**
+     * 文字列をパースしてHatenaSyntax_Nodeインスタンスからなる構文木を返す。
+     *
+     * @param string
+     * @return HatenaSyntax_Node
+     */
+    static function parse($str)
+    {
+        return HatenaSyntax_Locator::it()->parser->parse(self::context($str));
+    }
+
+    /**
+     * 文字列をパースしてHatenaSyntax_Nodeインスタンスからなる構文木の配列を返す
+     *
+     * @param string
+     * @return Array
+     */
+    static function parseAsSections($str)
+    {
+        $blocks = self::parse($str)->getData();
+
+        // 先頭にある空のパラグラフを削る
+        foreach ($blocks as $i => $block) {
+            if ($block->getType() === 'emptyparagraph') {
+                unset($blocks[$i]);
+            }
+            else {
+                break;
+            }
+        }
+        $blocks = array_values($blocks);
+
+        // セクションごとにブロック要素をまとめる
+        $sections = array();
+        $len = count($blocks);
+        $blocks = array_reverse($blocks);
+        for ($i = 0; $i < $len; $i++) {
+            $section = array();
+            for (;$i < $len; $i++) {
+                $section[] = $blocks[$i];
+                if ($blocks[$i]->isTopHeader()) {
+                    break;
+                }
+            }
+            $sections[] = array_reverse($section);
+        }
+        $sections = array_reverse($sections);
+
+        // ブロック要素の配列をノードにする
+        foreach ($sections as $i => $section) {
+            $sections[$i] = new HatenaSyntax_Node('root', $section);
+        }
+
+        return $sections;
+    }
+
+    /**
+     * 文字列をパースしてhtmlを返す。
+     *
+     * @param string
+     * @param Array
+     * @return string
+     */
+    static function render($str, Array $config = array())
+    {
+        $node = self::parse($str);
+        $renderer = new HatenaSyntax_Renderer($config);
+        return $renderer->render($node);
+    }
+
+    /**
+     * @param string
+     * @return PEG_IContext
+     */
+    static protected function context($str)
+    {
+        $str = str_replace(array("\r\n", "\r"), "\n", $str);
+        $str = strpos('<!--', $str) === false ? $str : HatenaSyntax_CommentRemover::remove($str);
+
+        return PEG::context(preg_split("/\n/", $str));
+    }
+
+    /**
+     * HatenaSyntax_Nodeインスタンスからなる構文木をhtmlにして返す。
+     *
+     * @param HatenaSyntax_Node
+     * @param Array
+     * @return string
+     */
+    static function renderNode(HatenaSyntax_Node $root, Array $config = array())
+    {
+        $renderer = new HatenaSyntax_Renderer($config);
+        return $renderer->render($root);
+    }
+
+    /**
+     * セクション名を取得する。
+     * 見つからなかった場合は空の文字列を返す。
+     *
+     * @param HatenaSyntax_Node
+     * @return string
+     */
+    static function getSectionName(HatenaSyntax_Node $root)
+    {
+        self::assertRootNode($root);
+
+        list($block) = $root->getData() + array(false);
+
+        return $block && $block->isTopHeader()
+            ? (string)$block->at('name', '')
+            : '';
+    }
+
+    /**
+     * セクションのタイトルを取得する。
+     * 見つからなかった場合は空の文字列を返す。
+     *
+     * @param HatenaSyntax_Node
+     * @param Array $config HatenaSyntax_Rendererに渡す設定
+     * @return string
+     */
+    static function getSectionTitle(HatenaSyntax_Node $root, Array $config = array())
+    {
+        self::assertRootNode($root);
+
+        $renderer = new HatenaSyntax_Renderer($config);
+        return $renderer->renderTitle($root);
+    }
+
+    /**
+     * セクションの先頭にトップのヘッダを持っているかを取得する
+     *
+     * @param HatenaSyntax_Node
+     * @return bool
+     */
+    static function hasTopHeader(HatenaSyntax_Node $root)
+    {
+        self::assertRootNode($root);
+
+        list($block) = $root->getData() + array(false);
+
+        return $block && $block->isTopHeader();
+    }
+
+    /**
+     * 続きを読む記法があるかどうかを取得する
+     *
+     * @param HatenaSyntax_Node
+     * @return bool
+     */
+    static function hasSeparator(HatenaSyntax_Node $root)
+    {
+        self::assertRootNode($root);
+
+        foreach ($root->getData() as $block) {
+            if ($block->getType() === 'separator') {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    /**
+     * 続きを読む記法よりも後ろの部分を切り離した前半の章を取得する
+     *
+     * @param HatenaSyntax_Node
+     * @return HatenaSyntax_Node
+     */
+    static function separate(HatenaSyntax_Node $root)
+    {
+        self::assertRootNode($root);
+
+        $blocks = array();
+
+        foreach ($root->getData() as $block) {
+            $blocks[] = $block;
+            if ($block->getType() === 'separator') {
+                break;
+            }
+        }
+
+        return new HatenaSyntax_Node('root', $blocks);
+    }
+
+    static protected function assertRootNode(HatenaSyntax_Node $node)
+    {
+        if ($node->getType() !== 'root') {
+            throw new InvalidArgumentException('this node must be root node');
+        }
+    }
+}
属性に変更があったパス: HatenaSyntax/tags/release-1.0.4-20100210131712/lib/HatenaSyntax.php
___________________________________________________________________
名前: svn:keywords
+ Id
属性に変更があったパス: HatenaSyntax/tags/release-1.0.4-20100210131712
___________________________________________________________________
名前: svn:ignore
+ .*