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); }
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 /** * 行頭に#があったら無視するパーサのサンプル */ 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. " */
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 __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()); }
<?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());