source: applications/nimpad/branches/0.2/lib/HatenaSyntax/NodeCreater.php @ 1488

SVN
Revision 1488, 958 bytes checked in by anatoo, 10 months ago (diff)

HatenaSyntax?とPEGをリポジトリの中に置いておくようにした

Line 
1<?php
2/**
3 * @package HatenaSyntax
4 * @author anatoo<anatoo@nequal.jp>
5 * @license http://www.opensource.org/licenses/mit-license.php MIT License
6 * @version $Id: NodeCreater.php 658 2009-04-12 07:47:13Z anatoo $
7 */
8
9class HatenaSyntax_NodeCreater implements PEG_IParser
10{
11    protected $keys, $parser;
12    function __construct($type, PEG_IParser $parser, Array $keys = array())
13    {
14        $this->type = $type;
15        $this->keys = $keys;
16        $this->parser = $parser;
17    }
18    function parse(PEG_IContext $context)
19    {
20        $result = $this->parser->parse($context);
21        if ($result instanceof PEG_Failure) return $result;
22       
23        $data = array();
24        if (count($this->keys) > 0) foreach ($this->keys as $i => $key) {
25            $data[$key] = $result[$i];
26        }
27        else {
28            $data = $result;
29        }
30       
31        return new HatenaSyntax_Node($this->type, $data);
32    }
33}
Note: See TracBrowser for help on using the repository browser.