src/Luminous/Scanners/PythonScanner.php
private function importLine()
    {
        $import = false;
        $from = false;
        while (!$this->eol()) {
            $c = $this->peek();
            $tok = null;
            $m = null;

            if ($c === '\\') {
                $m = $this->get(2);
            } elseif ($this->scan('/[,\\.;\\*]+/')) {
                $tok = 'OPERATOR';
            } elseif ($this->scan("/[ \t]+/")) {
            } elseif (($m = $this->scan('/import\\b|from\\b/'))) {
                if ($m === 'import') {
                    $import = true;
                } elseif ($m === 'from') {
                    $from = true;
                } else {
                    assert(0);
                }
                $tok = 'IDENT';
            } elseif ($this->scan('/[_a-zA-Z]\w*/')) {
                assert($from || $import);
                if ($import) {
                    // from module import *item*, or just import *item*
                    $tok = 'USER_FUNCTION';
                    $this->userDefs[$this->match()] = 'TYPE';
                } else {
                    // from *module* ...[import item], the module is not imported
                    $tok = 'IDENT';
                }
            } else {
                break;
            }
            $this->record(($m !== null) ? $m : $this->match(), $tok);
        }
    }
private function importLine()
    {
        $import = false;
        $from = false;
        while (!$this->eol()) {
            $c = $this->peek();
            $tok = null;
            $m = null;

            if ($c === '\\') {
                $m = $this->get(2);
            } elseif ($this->scan('/[,\\.;\\*]+/')) {
                $tok = 'OPERATOR';
            } elseif ($this->scan("/[ \t]+/")) {
            } elseif (($m = $this->scan('/import\\b|from\\b/'))) {
                if ($m === 'import') {
                    $import = true;
                } elseif ($m === 'from') {
                    $from = true;
                } else {
                    assert(0);
                }
                $tok = 'IDENT';
            } elseif ($this->scan('/[_a-zA-Z]\w*/')) {
                assert($from || $import);
                if ($import) {
                    // from module import *item*, or just import *item*
                    $tok = 'USER_FUNCTION';
                    $this->userDefs[$this->match()] = 'TYPE';
                } else {
                    // from *module* ...[import item], the module is not imported
                    $tok = 'IDENT';
                }
            } else {
                break;
            }
            $this->record(($m !== null) ? $m : $this->match(), $tok);
        }
    }
private function importLine ( ) { $ import = false ; $ from = false ; while ( ! $ this -> eol ( ) ) { $ c = $ this -> peek ( ) ; $ tok = null ; $ m = null ; if ( $ c === '\\' ) { $ m = $ this -> get ( 2 ) ; } elseif ( $ this -> scan ( '/[,\\.;\\*]+/' ) ) { $ tok = 'OPERATOR' ; } elseif ( $ this -> scan ( "/[ \t]+/" ) ) { } elseif ( ( $ m = $ this -> scan ( '/import\\b|from\\b/' ) ) ) { if ( $ m === 'import' ) { $ import = true ; } elseif ( $ m === 'from' ) { $ from = true ; } else { assert ( 0 ) ; } $ tok = 'IDENT' ; } elseif ( $ this -> scan ( '/[_a-zA-Z]\w*/' ) ) { assert ( $ from || $ import ) ; if ( $ import ) { // from module import *item*, or just import *item* $ tok = 'USER_FUNCTION' ; $ this -> userDefs [ $ this -> match ( ) ] = 'TYPE' ; } else { // from *module* ...[import item], the module is not imported $ tok = 'IDENT' ; } } else { break ; } $ this -> record ( ( $ m !== null ) ? $ m : $ this -> match ( ) , $ tok ) ; } }
mini-scanner to handle highlighting module names in import lines
mini - scanner to handle highlighting module names in import lines