Beispiel #1
0
 /**
  * Applying of delayed rule (delayed rules are rules that are executed after setting context of current token
  * but before starting to process next one)
  */
 private function applyDelayed()
 {
     if (isset($this->delayed_rule)) {
         if ($this->debug_enabled && $this->Stat) {
             $msg = "Found delayed rule: " . print_r($this->delayed_rule, true);
             $msg .= " in current state: {$this->state}";
             $this->Stat->addDebug($msg);
         }
         $this->state = $this->delayed_rule;
         $this->executeTransition();
         $this->delayed_rule = null;
     }
 }
Beispiel #2
0
 private function printContextMessage($context)
 {
     $padding = "    ";
     if (!isset($context['current_pos'])) {
         // error from hook
         $this->Stat->addIssue($padding . "{$context['descr']} on line {$context['line']}");
         return;
     }
     $token_pos = $context['current_pos'];
     $in = $context['in'];
     $out = $context['out'];
     if (strlen($in) && isset($context['from'])) {
         if ($context['from'] == PHPCF_KEY_LEFT) {
             $token_pos--;
         } else {
             $token_pos++;
         }
     }
     if ($token_pos < 0) {
         $token_pos = 0;
     } else {
         if ($token_pos >= count($this->ptokens)) {
             $token_pos = count($this->ptokens) - 1;
         }
     }
     $token = $this->ptokens[$token_pos];
     $token_line = $token[PHPCF_KEY_LINE];
     // compensate for hack for whitespace lines
     if ($token[PHPCF_KEY_CODE] == 'T_WHITESPACE') {
         $token_line -= substr_count($token[PHPCF_KEY_TEXT], "\n");
     }
     if (!substr_count($out, "\n") || substr_count($out, "\n") != substr_count($in, "\n")) {
         $col = 1;
         for ($i = $token_pos - 1; $i >= 0; $i--) {
             $tok = $this->ptokens[$i];
             $contents = $tok[PHPCF_KEY_TEXT];
             if (strpos($contents, "\n") !== false) {
                 $parts = explode("\n", $contents);
                 $col += strlen(end($parts));
                 break;
             } else {
                 $col += strlen($contents);
             }
         }
         if (!strlen($in) && isset($context['from']) && $context['from'] == PHPCF_KEY_RIGHT) {
             $col += strlen($token[PHPCF_KEY_TEXT]);
         }
         if (substr_count($out, "\n")) {
             $out_parts = explode("\n", $out);
             $indent_msg = " and " . $this->getIndentDescription($out_parts[1]);
         } else {
             $indent_msg = "";
         }
         $reason = "Expected " . lcfirst($context['descr']) . $indent_msg . " on line {$token_line} column {$col}";
         $this->Stat->addIssue($padding . $reason);
     } else {
         $out_lines = explode("\n", $out);
         $in_lines = explode("\n", $in);
         foreach ($out_lines as $k => $v) {
             if ($v === $in_lines[$k]) {
                 continue;
             } else {
                 if ($k == 0) {
                     // first element is not indent, but spaces at the end of line
                     $ln = $token_line + $k;
                     $reason = "Expected '{$v}', got '{$in_lines[$k]}' at the end of line {$ln}";
                     $this->Stat->addIssue($padding . $reason);
                 } else {
                     $ln = $token_line + $k;
                     $col = strlen($in_lines[$k]) + 1;
                     $reason = "Expected " . $this->getIndentDescription($v) . ", got " . $this->getIndentDescription($in_lines[$k]);
                     $this->Stat->addIssue($padding . $reason . " on line {$ln} column {$col}");
                 }
             }
         }
     }
 }