/** * Creates a new node instance with the given type. * * If a token is given, the location in the code of that token * is also passed to the Node instance * * If no token is passed, a dummy-token with the current * lexer's offset and line is created * * Notice that nodes are expando-objects, you can add properties on-the-fly * and retrieve them as an array later * * @param string $type the type the node should have * @param array|null $token the token to relate this node to * * @return Node The newly created node */ protected function createNode($type, array $token = null) { $token = $token ? $token : ['line' => $this->lexer->getLine(), 'offset' => $this->lexer->getOffset()]; $node = new Node($type, $token['line'], $token['offset']); return $node; }
echo json_encode(['success' => true, 'id' => $id]); exit; case 'compile': $compilerOptions = ['pretty' => isset($_POST['pretty']) ? $_POST['pretty'] === 'true' : false, 'standAlone' => isset($_POST['standAlone']) ? $_POST['standAlone'] === 'true' : false, 'allowImports' => false]; $compiler = new Compiler($compilerOptions); $result = null; try { $result = $compiler->compile($jade); } catch (\Exception $e) { echo json_encode(['success' => false, 'message' => "\n" . get_class($e) . "\n\n" . $e->getMessage()]); exit; } echo json_encode(['success' => true, 'output' => $result]); exit; case 'lex': $lexer = new Lexer(); $result = null; try { ob_start(); $lexer->dump($jade); $result = ob_get_clean(); } catch (\Exception $e) { echo json_encode(['success' => false, 'message' => "\n" . get_class($e) . "\n\n" . $e->getMessage()]); exit; } echo json_encode(['success' => true, 'output' => $result]); exit; case 'parse': $parser = new Parser(); $result = null; try {