Ejemplo n.º 1
0
 public function mapLine($line)
 {
     if (in_array(substr($line, 0, 1), array('+'), true)) {
         return $this->li->parse(PEG::context($line));
     }
     return PEG::failure();
 }
Ejemplo n.º 2
0
 function mapHeader($line)
 {
     if (!preg_match('/^>\\|([a-zA-Z0-9]*)\\|$/', $line, $matches)) {
         return PEG::failure();
     }
     return $matches[1];
 }
Ejemplo n.º 3
0
 function parse(PEG_IContext $context)
 {
     if ($context->eos()) {
         return PEG::failure();
     }
     $line = $context->readElement();
     if (!preg_match('#^><p( +class="([^"]+)")?>#', $line, $matches)) {
         return PEG::failure();
     }
     $line = substr($line, strlen($matches[0]));
     $attr = isset($matches[2]) && $matches[2] !== '' ? array('class' => $matches[2]) : array();
     // ><p>~~</p><みたいに一行で終わってるとき
     if (substr($line, -5, 5) === '</p><') {
         $line = substr($line, 0, -5);
         $body = $this->lineParser->parse(PEG::context($line));
         return array('p', $attr, $body);
     }
     $rest = $this->parser->parse($context);
     if ($rest instanceof PEG_Failure) {
         return $rest;
     }
     $line .= join(PHP_EOL, $rest[0]);
     $line .= substr($rest[1], 0, -5);
     $body = $this->lineParser->parse(PEG::context($line));
     return array('p', $attr, $body);
 }
Ejemplo n.º 4
0
 function parse(PEG_IContext $c)
 {
     if ($c->eos()) {
         return false;
     }
     return PEG::failure();
 }
Ejemplo n.º 5
0
 public function map($line)
 {
     if (strpos($line, '*') === 0) {
         list($level, $rest) = $this->toLevelAndRest((string) substr($line, 1));
         $body = $this->child->parse(PEG::context($rest));
         return array($level, $body);
     }
     return PEG::failure();
 }
Ejemplo n.º 6
0
 public function parse(PEG_IContext $context)
 {
     $result = $this->parser->parse($context);
     if ($result instanceof PEG_Failure) {
         return $result;
     }
     list($open, $body, $close) = $result;
     return $open !== $close ? PEG::failure() : array($open, $body);
 }
Ejemplo n.º 7
0
 function token(array $args)
 {
     list($str, $casesensitive) = $args + array(1 => true);
     $matched = $this->read(strlen($str));
     if ($casesensitive) {
         return $str === $matched ? $str : PEG::failure();
     } else {
         return strtolower($str) === strtolower($matched) ? $matched : PEG::failure();
     }
 }
Ejemplo n.º 8
0
 function parse(PEG_IContext $c)
 {
     $offset = $c->tell();
     foreach ($this->parsers as $p) {
         $result = $p->parse($c);
         if ($result instanceof PEG_Failure) {
             $c->seek($offset);
         } else {
             return $result;
         }
     }
     return PEG::failure();
 }
Ejemplo n.º 9
0
 function parse(PEG_IContext $context)
 {
     if ($context->eos()) {
         return PEG::failure();
     }
     $char = $context->readElement();
     if (isset($this->table[$char])) {
         $offset = $context->tell() - 1;
         $context->seek($offset);
         return $this->table[$char]->parse($context);
     }
     return $char;
 }
Ejemplo n.º 10
0
 function parse(PEG_IContext $c)
 {
     $arr = $this->arr;
     if (!$arr) {
         return PEG::failure();
     }
     for ($i = 0; $i < count($arr) - 1; $i++) {
         $offset = $c->tell();
         if ($arr[$i]->parse($c) instanceof PEG_Failure) {
             return PEG::failure();
         }
         $c->seek($offset);
     }
     return $arr[$i]->parse($c);
 }
Ejemplo n.º 11
0
 function mapHeader($line)
 {
     if (substr($line, 0, 1) !== '>' || substr($line, -1, 1) !== '>') {
         return PEG::failure();
     }
     if ($line === '>>') {
         return false;
     }
     $link_exp = substr($line, 1, strlen($line) - 2);
     if (!preg_match('#^(https?://[^>:]+)(:title(=(.+))?)?$#', $link_exp, $matches)) {
         return PEG::failure();
     }
     $title = !isset($matches[2]) ? false : (isset($matches[4]) ? $matches[4] : '');
     return new HatenaSyntax_Node('httplink', array('href' => $matches[1], 'title' => isset($matches[4]) ? $matches[4] : false));
 }
Ejemplo n.º 12
0
 function parse(PEG_IContext $context)
 {
     if ($context->eos()) {
         return PEG::failure();
     }
     $offset = $context->tell();
     $result = $this->parser->parse($context);
     if ($result instanceof PEG_Failure) {
         $i = $context->tell() - $offset;
         $context->seek($offset);
         $ret = $context->read($i);
         $context->seek($offset);
         return $ret;
     }
     return PEG::failure();
 }
Ejemplo n.º 13
0
 /**
  * @param	PEG_IContext
  */
 public function parse(PEG_IContext $context)
 {
     if ($context->eos()) {
         return PEG::failure();
     }
     $line = $context->readElement();
     $context->seek($context->tell() - 1);
     // 行ディスパッチ
     if (isset($this->lineTable[$line])) {
         return $this->lineTable[$line]->parse($context);
     }
     $char = substr($line, 0, 1);
     if (!isset($this->paragraphCheckTable[$char])) {
         return $this->paragraph->parse($context);
     }
     if (isset($this->firstCharTable[$char])) {
         return $this->firstCharTable[$char]->parse($context);
     }
     return $this->paragraph->parse($context);
 }
Ejemplo n.º 14
0
<?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());
Ejemplo n.º 15
0
 function parse(PEG_IContext $context)
 {
     return $context->eos() ? PEG::failure() : $context->readElement();
 }
Ejemplo n.º 16
0
<?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));
Ejemplo n.º 17
0
 function parse(PEG_IContext $context)
 {
     $char = $context->readElement();
     return $char !== false && ($this->except xor isset($this->dict[$char])) ? $char : PEG::failure();
 }
Ejemplo n.º 18
0
 function parse(PEG_IContext $context)
 {
     $context->logError($this->error);
     return PEG::failure();
 }
Ejemplo n.º 19
0
<?php

include_once dirname(__FILE__) . '/../../t.php';
$t = new lime_test();
$p = new HatenaSyntax_List(PEG::anything());
$c = PEG::context(array('+a', '+c'));
$t->ok($p->parse($c) !== PEG::failure());
Ejemplo n.º 20
0
<?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());
Ejemplo n.º 21
0
<?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')));
Ejemplo n.º 22
0
 function token(array $args)
 {
     if (count($args) === 1) {
         return $this->readElement() === $args[0] ? $args[0] : PEG::failure();
     }
     return $this->read(count($args)) === $args ? $args : PEG::failure();
 }
Ejemplo n.º 23
0
 function parse(PEG_IContext $context)
 {
     $elt = $context->readElement();
     return preg_match($this->regex, $elt) ? $elt : PEG::failure();
 }
Ejemplo n.º 24
0
<?php

include_once dirname(__FILE__) . '/t/t.php';
$t = new lime_test();
function parser()
{
    return PEG::token('a');
}
$p = PEG::delay('parser');
$t->is($p->parse(PEG::context('a')), 'a');
$t->is($p->parse(PEG::context('b')), PEG::failure());
Ejemplo n.º 25
0
<?php

include_once dirname(__FILE__) . '/t/t.php';
$t = new lime_test();
$parser = PEG::token('hoge');
$t->is(PEG::match($parser, 'hoge'), 'hoge');
$t->is(PEG::match($parser, 'a'), PEG::failure());