Пример #1
0
 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);
 }
Пример #2
0
 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);
 }
Пример #3
0
 protected function createImageLink()
 {
     $ext = PEG::choice('.jpg', '.png', '.gif');
     $src_char = PEG::pack('[', PEG::seq(PEG::many1(PEG::subtract($this->lineChar, ']', $ext)), $ext), ']');
     $src = PEG::join($src_char);
     $alt_char = PEG::pack('[', PEG::many1(PEG::subtract($this->lineChar, ']')), ']');
     $alt = PEG::join($alt_char);
     $parser = PEG::seq($src, PEG::optional($alt));
     return $this->nodeCreater(OrgModeSyntax_Node::TYPE_IMAGELINK, $parser, array('src', 'alt'));
 }
Пример #4
0
 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));
 }
Пример #5
0
 */
$t = new Benchmark_Timer();
$str = '((((((((1))))))))';
$t->start();
// メモ化していないパーサ
$a = PEG::ref($a_ref);
$p = PEG::ref($p_ref);
$a_ref = PEG::choice(PEG::seq($p, '+', $a), PEG::seq($p, '-', $a), $p);
$p_ref = PEG::choice(PEG::seq('(', $a, ')'), '1');
$a->parse(PEG::context($str));
$t->setMarker('no memoize');
// メモ化しているパーサ
$a = PEG::ref($a_ref);
$p = PEG::ref($p_ref);
$a_ref = PEG::memo(PEG::choice(PEG::seq($p, '+', $a), PEG::seq($p, '-', $a), $p));
$p_ref = PEG::memo(PEG::choice(PEG::seq('(', $a, ')'), '1'));
$a->parse($c = PEG::context($str));
$t->setMarker('memoize');
$t->stop();
$t->display();
/* 結果
---------------------------------------------------------
marker       time index            ex time         perct   
---------------------------------------------------------
Start        1242400475.10093900   -                0.00%
---------------------------------------------------------
no memoize   1242400476.30805000   1.207111        99.74%
---------------------------------------------------------
memoize      1242400476.31115500   0.003105         0.26%
---------------------------------------------------------
Stop         1242400476.31117700   0.000022         0.00%
Пример #6
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('<<'));
 }
Пример #7
0
 public function __construct(PEG_IParser $element)
 {
     $open = PEG::second('<', PEG::choice('del', 'strong', 'ins', 'em'), '>');
     $close = PEG::second('</', PEG::choice('del', 'strong', 'ins', 'em'), '>');
     $this->parser = PEG::seq($open, PEG::many(PEG::subtract($element, $close)), $close);
 }
Пример #8
0
<?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, ')'), ')'));
Пример #9
0
 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));
 }
Пример #10
0
<?php

include_once dirname(__FILE__) . '/t/t.php';
$lime = new lime_test();
$join = PEG::join(PEG::seq('b', PEG::many('a')));
$context = PEG::context('baaa');
$lime->is($join->parse($context), 'baaa');
Пример #11
0
<?php

include_once dirname(__FILE__) . '/t/t.php';
$t = new lime_test();
$p = PEG::tail(PEG::seq("a", "b", "c"));
$c = PEG::context('abc');
$t->is($p->parse($c), 'c');
Пример #12
0
 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)));
 }
Пример #13
0
<?php

include_once dirname(__FILE__) . '/t/t.php';
$lime = new lime_test();
$seq = PEG::seq(PEG::token('h'), PEG::token('o'));
$context = PEG::context('ho');
$lime->is($seq->parse($context), array('h', 'o'));
Пример #14
0
 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);
 }
Пример #15
0
<?php

include_once dirname(__FILE__) . '/../code/PEG.php';
/*
 * 単語にヒットするパーサ。
 * 
 * EBNF:
 * word := (PEG::alphabet | "_") (PEG::alphabet | PEG::digit | "_")+
 */
$word = PEG::join(PEG::seq(PEG::choice(PEG::alphabet(), PEG::token('_')), PEG::many(PEG::choice(PEG::alphabet(), PEG::digit(), PEG::token('_')))));
var_dump($word->parse(PEG::context('a')));
//=> 'a'
var_dump($word->parse(PEG::context('hogehoge')));
//=> 'hogehoge'
var_dump($word->parse(PEG::context('some_id')));
//=> 'some_id'
var_dump($word->parse(PEG::context('  ')));
//=> パースに失敗する
var_dump($word->parse(PEG::context('hoge fuga')));
//=> パースはコンテキストの途中で止まり 'hoge'が返る