<?php include_once dirname(__FILE__) . '/t/t.php'; $lime = new lime_test(); $parser = PEG::not(PEG::token('hoge')); $lime->is($parser->parse($c = PEG::context('fuga')), 'fuga'); $lime->is($c->tell(), 0); $lime->is($parser->parse(PEG::context('hoge')), PEG::failure()); $lime->is($parser->parse(PEG::context('')), PEG::failure());
<?php include_once dirname(__FILE__) . '/t/t.php'; $t = new lime_test(); $parser = PEG::token('hoge'); $t->is(PEG::_match($parser, PEG::context('ahoge')), 'hoge'); $t->is(PEG::_match($parser, PEG::context('ahoge'), true), array('hoge', 1)); $t->is(PEG::_match($parser, PEG::context('a')), PEG::failure()); $t->is(PEG::_match($parser, PEG::context('a'), true), array(PEG::failure(), null));
<?php include_once dirname(__FILE__) . '/t/t.php'; $lime = new lime_test(); $many1 = PEG::many1(PEG::token('hoge')); $lime->is($many1->parse(PEG::context('hoge')), array('hoge')); $lime->is($many1->parse(PEG::context('')), PEG::failure()); $lime->is(array('hoge', 'hoge'), $many1->parse(PEG::context('hogehoge')));
<?php include_once dirname(__FILE__) . '/t/t.php'; $t = new lime_test(null, new lime_output_color()); $token = PEG::token('hoge'); $context = PEG::context('hogehoge'); $t->is($token->parse($context), 'hoge'); $t->is($context->tell(), 4); $t->is($token->parse($context), 'hoge'); $t->is($token->parse($context), PEG::failure()); $t->is(PEG::token('hoge', false)->parse(PEG::context('Hoge')), 'Hoge'); $t->is(PEG::token('hoge', false)->parse(PEG::context('hoge')), 'hoge'); $t->is(PEG::token('hoge', false)->parse(PEG::context('fuga')), PEG::failure());
<?php include_once dirname(__FILE__) . '/t/t.php'; $t = new lime_test(); $choice = PEG::choice(PEG::token('hoge'), PEG::token('fuga')); $t->is($choice->parse(PEG::context('hoge')), 'hoge'); $t->is($choice->parse($c = PEG::context('fuga')), 'fuga'); $t->is($c->tell(), 4);
<?php include_once dirname(__FILE__) . '/t/t.php'; $t = new lime_test(); $parser = PEG::token('a'); $t->is(PEG::matchAll($parser, 'abbabbbba'), array('a', 'a', 'a')); $t->is(PEG::matchAll($parser, 'hogehoge'), array());
<?php include_once dirname(__FILE__) . '/t/t.php'; $lime = new lime_test(); $parser = PEG::andalso(PEG::token('hoge'), PEG::token('h')); $lime->is($parser->parse($c = PEG::context('hoge')), 'h'); $lime->is($c->read(3), 'oge'); $result = $parser->parse(PEG::context('hogaaa')); $lime->ok($result instanceof PEG_Failure);
<?php include_once dirname(__FILE__) . '/t/t.php'; class MyActionParser extends PEG_Action { function process($result) { return join('', $result); } } $lime = new lime_test(); $action = new MyActionParser(PEG::many(PEG::token('hoge'))); $lime->is($action->parse(PEG::context('hogehogehogehoge')), 'hogehogehogehoge');
<?php include_once dirname(__FILE__) . '/t/t.php'; $lime = new lime_test(); function hoge($v) { return $v . $v; } $p = new PEG_CallbackAction('hoge', PEG::token('hoge')); $lime->is('hogehoge', $p->parse(PEG::context('hoge')));
<?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');
<?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());
<?php include_once dirname(__FILE__) . '/t/t.php'; $t = new lime_test(); $parser = PEG::listof(PEG::char('abc'), PEG::token(',')); $context = PEG::context('a,b,c'); $t->is($parser->parse($context), array('a', 'b', 'c')); $t->ok($context->eos());
<?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'));
protected function createEmptyParagraph() { $parser = PEG::count(PEG::many1(PEG::token(''))); return $this->nodeCreater(OrgModeSyntax_Node::TYPE_EMPTY_PARAGRAPH, $parser); }
<?php include_once dirname(__FILE__) . '/t/t.php'; $lime = new lime_test(); $p = PEG::at(0, PEG::many(PEG::token('a'))); $c = PEG::context('aaaaaaaaa'); $lime->is($p->parse($c), 'a');
function parser() { return PEG::token('a'); }
<?php include_once dirname(__FILE__) . '/t/t.php'; $t = new lime_test(); $p = PEG::ref($p_ref); $p_ref = PEG::token('hoge'); $t->is($p->parse(PEG::context('hoge')), 'hoge'); $p = PEG::ref($_); $ref =& $p->getRef(); $ref = PEG::token('hoge'); $t->is($p->parse(PEG::context('hoge')), 'hoge'); $p = PEG::ref($_); $p->is(PEG::token('hoge')); $t->is($p->parse(PEG::context('hoge')), 'hoge');
protected function createEmptyParagraph() { $parser = PEG::count(PEG::many1(PEG::token(''))); return $this->nodeCreater('emptyparagraph', $parser); }
<?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'が返る