public 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())); $this->definitionList = PEG::seq(PEG::drop('-'), $dt, PEG::drop(':'), $dd); }
<?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')));
<?php include_once dirname(__FILE__) . '/../../t.php'; $t = new lime_test(); $p = new OrgModeSyntax_List(PEG::anything()); $c = PEG::context(array('+ List item 1', '++ List item 1-1')); $root = $p->parse($c); $t->is($root->getType(), 'root'); $nodes = $root->getChildren(); $t->is($nodes[0]->getType(), 'node'); $t->is($nodes[0]->getValue(), array('+', str_split(' List item 1'))); $leaf = $nodes[0]->getChildren(); $t->is($leaf[0]->getType(), 'leaf'); $t->is($leaf[0]->getValue(), array('+', str_split(' List item 1-1')));
protected function createLineChar() { return PEG::anything(); }
public function __construct(PEG_IParser $lineelt) { $this->parser = PEG::callbackAction(array($this, 'map'), PEG::anything()); $this->line = PEG::many($lineelt); }
<?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', '<<')); $result = $p->parse($c); $t->is($result[1], array('a')); $t->is($result[0]->at('href'), 'http://google.com'); $t->is($result[0]->at('title'), false); $c = PEG::context(array('>http://google.com:title>', 'a', '<<')); $result = $p->parse($c); $t->is($result[1], array('a')); $t->is($result[0]->at('href'), 'http://google.com'); $t->is($result[0]->at('title'), ''); $c = PEG::context(array('>http://google.com:title=hoge>', 'a', '<<')); $result = $p->parse($c); $t->is($result[1], array('a')); $t->is($result[0]->at('href'), 'http://google.com'); $t->is($result[0]->at('title'), 'hoge');
<?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'))));
<?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());
<?php $cwd = dirname(__FILE__); include_once $cwd . '/../../t.php'; $t = new lime_test(); $p = new OrgModeSyntax_Paragraph(PEG::anything()); $c = PEG::context(array('abc', 'def')); $t->is($p->parse($c), str_split('abc')); $t->is($p->parse($c), str_split('def'));
<?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')));
<?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')));
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 __construct(PEG_IParser $elt) { $this->child = PEG::many($elt); $this->parser = PEG::callbackAction(array($this, 'map'), PEG::anything()); }
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()); }
public function __construct(PEG_IParser $lineelt) { $item = PEG::callbackAction(array($this, 'mapLine'), PEG::anything()); $this->parser = PEG::callbackAction(array('OrgModeSyntax_Tree', 'make'), PEG::many1($item)); $this->li = PEG::callbackAction(array('OrgModeSyntax_Util', 'processListItem'), PEG::seq(PEG::many(PEG::char('+')), PEG::many($lineelt))); }
<?php include_once dirname(__FILE__) . '/../../t.php'; $t = new lime_test(); $p = new OrgModeSyntax_DefinitionList(PEG::anything()); $c = PEG::context(array('- foo : bar', '- baz : qux')); $t->is($p->parse($c), array(array(str_split(' foo '), str_split(' bar')), array(str_split(' baz '), str_split(' qux'))));
<?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')));
<?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')))));
<?php include_once dirname(__FILE__) . '/../code/PEG.php'; /** * 括弧の対応をとる再帰的なパーサのサンプル。 * 認識した括弧を用いて文字列を階層化する。 * * パーサのEBNFはこんな感じ * item := paren | anything * paren_item := (?! ")") item * paren := "(" paren_item* ")" * parser := item* */ $paren = PEG::ref($paren_ref); $item = PEG::choice($paren, PEG::anything()); $paren_item = PEG::andalso(PEG::not(')'), $item); $paren_ref = PEG::pack('(', PEG::many($paren_item), ')'); $parser = PEG::many($item); $str = 'abc(def(ghi)(jkl(mno)))pq'; var_dump($parser->parse(PEG::context($str))); /* 結果 array(6) { [0]=> string(1) "a" [1]=> string(1) "b" [2]=> string(1) "c" [3]=> array(5) { [0]=>
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 header() { return PEG::callbackAction(array($this, 'mapHeader'), PEG::anything()); }
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())); }
<?php include_once dirname(__FILE__) . '/t/t.php'; $t = new lime_test(); $p = PEG::seq('a', 'a'); $c = PEG::context(array('a', 'a')); $t->is($p->parse($c), array('a', 'a')); $p = PEG::seq('(', PEG::choice(PEG::ref($ref), PEG::anything()), ')'); $ref = $p; $c = PEG::context(array('(', 3, ')')); $t->is($p->parse($c), array('(', 3, ')')); $c = PEG::context(array('(', '(', 3, ')', ')')); $t->is($p->parse($c), array('(', array('(', 3, ')'), ')'));
<?php include_once dirname(__FILE__) . '/t/t.php'; $lime = new lime_test(); $anything = PEG::anything(); $lime->is('a', $anything->parse(PEG::context('a')));
<?php $cwd = dirname(__FILE__); include_once $cwd . '/../../t.php'; $t = new lime_test(); $p = new OrgModeSyntax_Header(PEG::anything()); $c = PEG::context(array('* Top level headline')); $t->is($p->parse($c), array(0, str_split(' Top level headline'))); $c = PEG::context(array('** Second level')); $t->is($p->parse($c), array(1, str_split(' Second level'))); $c = PEG::context(array('*** 3rd level', 'some text')); $t->is($p->parse($c), array(2, str_split(' 3rd level')));
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)); }
<?php $cwd = dirname(__FILE__); include_once $cwd . '/../../t.php'; $t = new lime_test(); $p = new OrgModeSyntax_InlineTag(PEG::anything()); $c = PEG::context('<strong>a</strong>'); $t->is($p->parse($c), array('strong', array('a')));