Ejemplo n.º 1
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.º 2
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.º 3
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.º 4
0
 function parse(PEG_IContext $context)
 {
     return $context->eos() ? PEG::failure() : $context->readElement();
 }
Ejemplo n.º 5
0
 function parse(PEG_IContext $context)
 {
     $char = $context->readElement();
     return $char !== false && ($this->except xor isset($this->dict[$char])) ? $char : PEG::failure();
 }
Ejemplo n.º 6
0
 function parse(PEG_IContext $context)
 {
     $elt = $context->readElement();
     return preg_match($this->regex, $elt) ? $elt : PEG::failure();
 }