Esempio n. 1
0
 function parse(PEG_IContext $context)
 {
     $offset = $context->tell();
     $result = $this->parser->parse($context);
     $context->seek($offset);
     return $result;
 }
Esempio n. 2
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);
 }
Esempio n. 3
0
 function parse(PEG_IContext $c)
 {
     if ($c->eos()) {
         return false;
     }
     return PEG::failure();
 }
Esempio n. 4
0
 function parse(PEG_IContext $context)
 {
     $offset = $context->tell();
     $result = $this->parser->parse($context);
     if ($result instanceof PEG_Failure) {
         $context->seek($offset);
         return false;
     }
     return $result;
 }
Esempio n. 5
0
 function parse(PEG_IContext $context)
 {
     list($hit, list($end, $val)) = $context->cache($this);
     if ($hit) {
         $context->seek($end);
         return $val;
     }
     $start = $context->tell();
     $val = $this->parser->parse($context);
     $end = $context->tell();
     $context->save($this, $start, $end, $val);
     return $val;
 }
Esempio n. 6
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();
 }
Esempio n. 7
0
 function parse(PEG_IContext $context)
 {
     $ret = array();
     foreach ($this->parsers as $parser) {
         $offset = $context->tell();
         $result = $parser->parse($context);
         if ($result instanceof PEG_Failure) {
             return $result;
         } elseif ($result !== null) {
             $ret[] = $result;
         }
     }
     return $ret;
 }
Esempio n. 8
0
 function parse(PEG_IContext $context)
 {
     $ret = array();
     do {
         $offset = $context->tell();
         $result = $this->parser->parse($context);
         if ($result instanceof PEG_Failure) {
             $context->seek($offset);
             return $ret;
         } elseif (!is_null($result)) {
             $ret[] = $result;
         }
     } while (!$context->eos());
     return $ret;
 }
Esempio n. 9
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);
 }
Esempio n. 10
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();
 }
Esempio n. 11
0
 function parse(PEG_IContext $context)
 {
     $offset = $context->tell();
     $result = $this->parser->parse($context);
     if ($result instanceof PEG_Failure) {
         return $result;
     }
     $data = array();
     if (count($this->keys) > 0) {
         foreach ($this->keys as $i => $key) {
             $data[$key] = $result[$i];
         }
     } else {
         $data = $result;
     }
     return new HatenaSyntax_Node($this->type, $data, $offset, spl_object_hash($context));
 }
Esempio n. 12
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;
 }
Esempio 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);
 }
Esempio n. 14
0
 function parse(PEG_IContext $context)
 {
     return $context->eos() ? PEG::failure() : $context->readElement();
 }
Esempio n. 15
0
 function parse(PEG_IContext $c)
 {
     return $c->token($this->args);
 }
Esempio n. 16
0
 function parse(PEG_IContext $context)
 {
     $char = $context->readElement();
     return $char !== false && ($this->except xor isset($this->dict[$char])) ? $char : PEG::failure();
 }
Esempio n. 17
0
 function parse(PEG_IContext $context)
 {
     $context->logError($this->error);
     return PEG::failure();
 }
Esempio n. 18
0
 static function _match(PEG_IParser $parser, PEG_IContext $context, $need_matching_start = false)
 {
     while (!$context->eos()) {
         $start = $context->tell();
         $result = $parser->parse($context);
         $end = $context->tell();
         if ($result instanceof PEG_Failure) {
             $context->seek($start + 1);
         } else {
             return $need_matching_start ? array($result, $start) : $result;
         }
     }
     return $need_matching_start ? array(self::failure(), null) : self::failure();
 }
Esempio n. 19
0
 function parse(PEG_IContext $context)
 {
     $elt = $context->readElement();
     return preg_match($this->regex, $elt) ? $elt : PEG::failure();
 }