protected function createHttpLink() { $title_char = PEG::subtract($this->lineChar, ']'); $title = PEG::choice(PEG::second(':title=', PEG::join(PEG::many1($title_char))), PEG::second(':title', '')); $url_char = PEG::subtract($this->lineChar, ']', ':title'); $url = PEG::join(PEG::seq(PEG::choice('http://', 'https://'), PEG::many1($url_char))); $parser = PEG::seq($url, PEG::optional($title)); return $this->nodeCreater('httplink', $parser, array('href', 'title')); }
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')); }
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(); $optional = PEG::optional(PEG::token('hoge')); $lime->is($optional->parse(PEG::context('fuga')), false); $lime->is($optional->parse(PEG::context('hoge')), 'hoge');