Tale\Jade\Parser::parse PHP Method

parse() public method

The Abstract Syntax Tree (AST) will be an object-tree consisting of \Tale\Jade\Parser\Node instances. You can either let the compiler compile it or compile it yourself The root-node will always be of type 'document', from there on it can contain several kinds of nodes
public parse ( string $input ) : Node
$input string the input jade string that is to be parsed
return Tale\Jade\Parser\Node the root-node of the parsed AST
    public function parse($input)
    {
        $this->level = 0;
        $this->tokens = $this->lexer->lex($input);
        $this->document = $this->createNode('document', ['line' => 0, 'offset' => 0]);
        $this->currentParent = $this->document;
        $this->current = null;
        $this->last = null;
        $this->inMixin = false;
        $this->mixinLevel = null;
        $this->expansion = null;
        //Fix HHVM generators needing ->next() before ->current()
        //This will actually work as expected, no node will be skipped
        //HHVM always needs a first ->next() (I don't know if this is a bug or
        //expected behaviour)
        if (defined('HHVM_VERSION')) {
            $this->tokens->next();
        }
        //While we have tokens, handle current token, then go to next token
        //rinse and repeat
        while ($this->hasTokens()) {
            $this->handleToken();
            $this->nextToken();
        }
        //Return the final document node with all its awesome child nodes
        return $this->document;
    }

Usage Example

Ejemplo n.º 1
0
 public function convert($inputPath)
 {
     $this->prependOptions(['paths' => []]);
     $parser = new Parser(file_get_contents($inputPath), ['filename' => $inputPath, 'includes' => $this->getOption('paths')]);
     $compiler = new Compiler(!$this->getManager()->getOption('minify'));
     return $compiler->compile($parser->parse());
 }
All Usage Examples Of Tale\Jade\Parser::parse