public function parse($parser) { if (in_array($this->value, PPP::synonym_list())) { $parser->token_list[] = PPP::$synonyms[$this->value]; } else { $parser->token_list[] = $this->value; } }
public function parse($content) { $synonyms = PPP::$synonyms; $synonym_list = PPP::synonym_list(); $lines = explode("\n", $content); if ($this->opts['init']) { $this->output = array("<?php"); } else { $this->output = array(); } $this->in_block_quotes = false; $this->reset = true; $this->cur_token = 0; $this->token_count = 0; $this->reset_state(); $this->reset_indentation(); foreach ($lines as $line) { $trimmed = trim($line); if (empty($trimmed)) { $this->output[] = ''; continue; } if (empty($this->array_stack) && !$this->in_block_quotes) { // Capture indentation preg_match('/^(\\s+?)[^\\s]/', $line, $leading_whitespace); if (!empty($leading_whitespace) && !empty($leading_whitespace[1])) { $this->match_indentation(strlen($leading_whitespace[1])); } else { $this->match_indentation(0); } } $this->tokens = self::tokenize($line); if ($this->reset) { $this->reset_state(); } $this->token_count = count($this->tokens); $this->cur_token = 0; $this->reset = true; while ($this->cur_token < $this->token_count) { try { $this->prev_token = null; $this->next_token = null; $end = false; $this->token = $token = $this->tokens[$this->cur_token]; if ($this->cur_token == 0) { if ($token->value == ']' || $token->value == '}') { $tab_variation = -1; } else { $tab_variation = 0; } $this->tabs($tab_variation); } if ($this->cur_token - 1 >= 0) { $this->prev_token = $this->tokens[$this->cur_token - 1]; } $this->next_token = $next_token = $this->next_token(); $this->cur_token++; $this->blockQuotes(); $token->parse($this); if (is_null($this->next_token)) { if ($token->value == ',' || !empty($this->array_stack)) { $this->reset = false; continue; } while (!empty($this->open_stack)) { $this->token_list[] = array_pop($this->open_stack); } if ($this->ends_curly) { $this->token_list[] = ' {'; } else { if (!$end) { $this->token_list[] = ';'; } } } } catch (PPP_ParserException_TokenBreak $e) { break; } catch (PPP_ParserException_TokenContinue $e) { continue; } } if ($this->reset) { $processed = implode('', $this->token_list); $this->output[] = $processed; } else { $this->token_list[] = "\n"; } } while ($this->indentation['count']) { $this->dedent(true); } $printer = implode(PHP_EOL, $this->output); return $printer; }