Haanga_Compiler_Tokenizer::yylex_main PHP Method

yylex_main() public method

public yylex_main ( )
    function yylex_main()
    {
        $data =& $this->data;
        for ($i =& $this->N; is_null($this->token) && $i < $this->length; ++$i) {
            switch ($data[$i]) {
                /* strings {{{ */
                case '"':
                case "'":
                    $end = $data[$i];
                    $value = "";
                    while ($data[++$i] != $end) {
                        switch ($data[$i]) {
                            case "\\":
                                switch ($data[++$i]) {
                                    case "n":
                                        $value .= "\n";
                                        break;
                                    case "t":
                                        $value .= "\t";
                                        break;
                                    default:
                                        $value .= $data[$i];
                                }
                                break;
                            case $end:
                                --$i;
                                break 2;
                            default:
                                if ($data[$i] == "\n") {
                                    $this->line++;
                                }
                                $value .= $data[$i];
                        }
                        if (!isset($data[$i + 1])) {
                            $this->Error("unclosed string");
                        }
                    }
                    $this->value = $value;
                    $this->token = HG_Parser::T_STRING;
                    break;
                    /* }}} */
                    /* number {{{ */
                /* }}} */
                /* number {{{ */
                case '0':
                case '1':
                case '2':
                case '3':
                case '4':
                case '5':
                case '6':
                case '7':
                case '8':
                case '9':
                    $value = "";
                    $dot = FALSE;
                    for ($e = 0; $i < $this->length; ++$e, ++$i) {
                        switch ($data[$i]) {
                            case '0':
                            case '1':
                            case '2':
                            case '3':
                            case '4':
                            case '5':
                            case '6':
                            case '7':
                            case '8':
                            case '9':
                                $value .= $data[$i];
                                break;
                            case '.':
                                if (!$dot) {
                                    $value .= ".";
                                    $dot = TRUE;
                                } else {
                                    $this->error("Invalid number");
                                }
                                break;
                            default:
                                break 2;
                                /* break the main loop */
                        }
                    }
                    if (!$this->is_token_end($data[$i]) && !isset(self::$operators_single[$data[$i]]) || $value[$e - 1] == '.') {
                        $this->error("Unexpected '{$data[$i]}'");
                    }
                    $this->value = $value;
                    $this->token = HG_Parser::T_NUMERIC;
                    break 2;
                    /* }}} */
                /* }}} */
                case "\n":
                case " ":
                case "\t":
                case "\r":
                case "\f":
                    for (; is_null($this->token) && $i < $this->length; ++$i) {
                        switch ($data[$i]) {
                            case "\n":
                                $this->line++;
                            case " ":
                            case "\t":
                            case "\r":
                            case "\f":
                                break;
                            case '.':
                                if ($data[$i + 1] != '.') {
                                    $this->token = HG_Parser::T_CONCAT;
                                    $this->value = '.';
                                    $i++;
                                    return;
                                }
                            default:
                                /* break main loop */
                                /* and decrease because last processed byte */
                                /* wasn't a dot (T_CONCAT)                  */
                                --$i;
                                break 2;
                        }
                    }
                    break;
                    /* whitespaces are ignored */
                /* whitespaces are ignored */
                default:
                    if (!$this->getTag() && !$this->getOperator()) {
                        $alpha = $this->getAlpha();
                        if ($alpha === FALSE) {
                            $this->error("error: unexpected " . substr($data, $i));
                        }
                        static $tag = NULL;
                        if (!$tag) {
                            $tag = Haanga_Extension::getInstance('Tag');
                        }
                        if ($this->status == self::IN_ECHO && !$this->echoFirstToken) {
                            $this->token = HG_Parser::T_ALPHA;
                        } else {
                            $value = $tag->isValid($alpha);
                            $this->token = $value ? $value : HG_Parser::T_ALPHA;
                        }
                        $this->value = $alpha;
                    }
                    break 2;
            }
        }
        if ($this->status == self::IN_ECHO) {
            $this->echoFirstToken = true;
        }
        if ($this->token == HG_Parser::T_TAG_CLOSE || $this->token == HG_Parser::T_PRINT_CLOSE) {
            $this->status = self::IN_NONE;
        }
    }