Gregwar\RST\Parser::parseLine PHP Метод

parseLine() защищенный Метод

Process one line
protected parseLine ( string &$line )
$line string the line string
    protected function parseLine(&$line)
    {
        switch ($this->state) {
            case self::STATE_BEGIN:
                if (trim($line)) {
                    if ($this->isListLine($line)) {
                        $this->state = self::STATE_LIST;
                        $this->buffer = $this->kernel->build('Nodes\\ListNode');
                        $this->lineInfo = null;
                        $this->listFlow = true;
                        return false;
                    } else {
                        if ($this->isBlockLine($line)) {
                            if ($this->isCode) {
                                $this->state = self::STATE_CODE;
                            } else {
                                $this->state = self::STATE_BLOCK;
                            }
                            return false;
                        } else {
                            if ($this->isDirective($line)) {
                                $this->state = self::STATE_DIRECTIVE;
                                $this->buffer = array();
                                $this->flush();
                                $this->initDirective($line);
                            } else {
                                if ($this->parseLink($line)) {
                                    return true;
                                } else {
                                    if ($parts = $this->parseTableLine($line)) {
                                        $this->state = self::STATE_TABLE;
                                        $this->buffer = $this->kernel->build('Nodes\\TableNode', $parts);
                                    } else {
                                        $this->state = self::STATE_NORMAL;
                                        return false;
                                    }
                                }
                            }
                        }
                    }
                }
                break;
            case self::STATE_LIST:
                if (!$this->pushListLine($line)) {
                    $this->flush();
                    $this->state = self::STATE_BEGIN;
                    return false;
                }
                break;
            case self::STATE_TABLE:
                if (!trim($line)) {
                    $this->flush();
                    $this->state = self::STATE_BEGIN;
                } else {
                    $parts = $this->parseTableLine($line);
                    if (!$this->buffer->push($parts, $line)) {
                        $this->flush();
                        $this->state = self::STATE_BEGIN;
                        return false;
                    }
                }
                break;
            case self::STATE_NORMAL:
                if (trim($line)) {
                    $specialLetter = $this->isSpecialLine($line);
                    if ($specialLetter) {
                        $this->specialLetter = $specialLetter;
                        $lastLine = array_pop($this->buffer);
                        if ($lastLine) {
                            $this->buffer = array($lastLine);
                            $this->state = self::STATE_TITLE;
                        } else {
                            $this->buffer[] = $line;
                            $this->state = self::STATE_SEPARATOR;
                        }
                        $this->flush();
                        $this->state = self::STATE_BEGIN;
                    } else {
                        if ($this->isDirective($line)) {
                            $this->flush();
                            $this->state = self::STATE_BEGIN;
                            return false;
                        }
                        if ($this->isComment($line)) {
                            $this->flush();
                            $this->state = self::STATE_COMMENT;
                        } else {
                            $this->buffer[] = $line;
                        }
                    }
                } else {
                    $this->flush();
                    $this->state = self::STATE_BEGIN;
                }
                break;
            case self::STATE_COMMENT:
                $isComment = false;
                if (!$this->isComment($line) && (!trim($line) || $line[0] != ' ')) {
                    $this->state = self::STATE_BEGIN;
                    return false;
                }
                break;
            case self::STATE_BLOCK:
            case self::STATE_CODE:
                if (!$this->isBlockLine($line)) {
                    $this->flush();
                    $this->state = self::STATE_BEGIN;
                    return false;
                } else {
                    $this->buffer[] = $line;
                }
                break;
            case self::STATE_DIRECTIVE:
                if (!$this->directiveAddOption($line)) {
                    if ($this->isDirective($line)) {
                        $this->flush();
                        $this->initDirective($line);
                    } else {
                        $directive = $this->getCurrentDirective();
                        $this->isCode = $directive ? $directive->wantCode() : false;
                        $this->state = self::STATE_BEGIN;
                        return false;
                    }
                }
                break;
            default:
                $this->getEnvironment()->getErrorManager()->error('Parser ended in an unexcepted state');
        }
        return true;
    }