Example #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);
 }
Example #2
0
 public function __construct(PEG_IParser $lineelt)
 {
     $this->parser = PEG::callbackAction(array($this, 'map'), PEG::anything());
     $this->line = PEG::many($lineelt);
 }
Example #3
0
 protected function createParser()
 {
     return $this->nodeCreater(OrgModeSyntax_Node::TYPE_ROOT, PEG::many($this->block));
 }
Example #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('<<'));
 }
Example #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());
 }
Example #6
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);
 }
Example #7
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'が返る
Example #8
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.
"
 */
Example #9
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');
Example #10
0
include_once dirname(__FILE__) . '/../code/PEG.php';
/**
 * 括弧の対応をとる再帰的なパーサのサンプル。
 * 認識した括弧を用いて文字列を階層化する。
 * 
 * パーサのEBNFはこんな感じ
 * item       := paren | anything
 * paren_item := (?! ")") item
 * paren      := "(" paren_item* ")"
 * parser     := item*
 */
$paren = PEG::ref($paren_ref);
$item = PEG::choice($paren, PEG::anything());
$paren_item = PEG::andalso(PEG::not(')'), $item);
$paren_ref = PEG::pack('(', PEG::many($paren_item), ')');
$parser = PEG::many($item);
$str = 'abc(def(ghi)(jkl(mno)))pq';
var_dump($parser->parse(PEG::context($str)));
/* 結果
array(6) {
  [0]=>
  string(1) "a"
  [1]=>
  string(1) "b"
  [2]=>
  string(1) "c"
  [3]=>
  array(5) {
    [0]=>
    string(1) "d"
    [1]=>
Example #11
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());
Example #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)));
 }
Example #13
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);
 }
Example #14
0
<?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');
Example #15
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));
 }
Example #16
0
 protected function createParser()
 {
     return $this->nodeCreater('root', PEG::many($this->block));
 }
Example #17
0
File: At.php Project: ngyuki/PHPPEG
<?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');
Example #18
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));
 }
Example #19
0
 function __construct(PEG_IParser $elt)
 {
     $this->child = PEG::many($elt);
     $this->parser = PEG::callbackAction(array($this, 'map'), PEG::anything());
 }