/** * {@inheritdoc} */ public function check() { if (null !== $this->error) { throw new LintingException(sprintf('PHP Parse error: %s on line %d.', $this->error->getMessage(), $this->error->getLine()), $this->error->getCode(), $this->error); } }
/** * Get a ErrorException instance. * * @param \ParseError|\TypeError|\Throwable $exception * * @return \ErrorException */ private function getErrorException($exception) : ErrorException { if ($exception instanceof ParseError) { $message = 'Parse error: ' . $exception->getMessage(); $severity = E_PARSE; } elseif ($exception instanceof TypeError) { $message = 'Type error: ' . $exception->getMessage(); $severity = E_RECOVERABLE_ERROR; } else { $message = $exception->getMessage(); $severity = E_ERROR; } return new ErrorException($message, $exception->getCode(), $severity, $exception->getFile(), $exception->getLine()); }
/** * @param \Exception|\ParseError $e */ public function exceptionHandler($e) { if ($this->mode === 'development') { $trace = $e->getTrace(); } else { $trace = $e->getTraceAsString(); } $this->addHandler($e->getCode(), $e->getMessage(), $e->getFile(), $e->getLine(), $trace); }
require_once "gaphu.php"; header("content-type: text/xml"); $dictionary = array("one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen", "twenty"); $expression = $_GET["expression"]; $pos = 0; $unrecognized = null; preg_match_all("/([^\\s]+)\\s*/", $expression, $matches); $tokens = $matches[1]; // the matches for capture group 1 $count = count($tokens); for ($i = 0; $i < $count; $i++) { $token = $tokens[$i]; if (array_search($token, $dictionary) === FALSE) { $unrecognized = encode($token); break; } $pos += strlen($token) + 1; } if ($unrecognized == null) { $parseSuccess = new ParseSuccess($expression, "OK"); echo $parseSuccess->getXML(); } else { $expectedStr = "Found {$unrecognized} at position {$pos}. \nExpected the name of a Number"; // $count = count($dictionary); // for ($i=0; $i<$count; $i++){ // $expectedStr .= "\n\t" . $dictionary[$i]; // } $parseError = new ParseError($expression, $expectedStr, $pos, $unrecognized); echo $parseError->getXML(); }