Пример #1
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);
 }
Пример #2
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));
 }
Пример #3
0
<?php

/**
 * 行頭に#があったら無視するパーサのサンプル
 */
include_once dirname(__FILE__) . '/../code/PEG.php';
$line = PEG::line();
$ignore = PEG::drop(PEG::andalso('#', $line));
$parser = PEG::join(PEG::many(PEG::choice($ignore, $line)));
$context = PEG::context('
Lorem ipsum dolor sit amet, 
#consectetur adipisicing elit, 
#sed do eiusmod tempor incididunt ut 
labore et dolore magna aliqua.
');
var_dump($parser->parse($context));
/* 結果
string(64) "
Lorem ipsum dolor sit amet, 
labore et dolore magna aliqua.
"
 */
Пример #4
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('<<'));
 }
Пример #5
0
 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());
 }
Пример #6
0
<?php

include_once dirname(__FILE__) . '/t/t.php';
$lime = new lime_test();
$many = PEG::many(PEG::token('a'));
$context = PEG::context('aaaaaaaa');
$lime->is($many->parse($context), array('a', 'a', 'a', 'a', 'a', 'a', 'a', 'a'));
$lime->is($context->tell(), 8);
$context = PEG::context('ab');
$parser = PEG::many(PEG::drop(PEG::token('ab')));
$lime->is($parser->parse($context), array());