* Parses the code with the native parser or the polyfill.
* If $suppress_parse_errors is false, this also emits SyntaxError.
*
* @param CodeBase $code_base
* @param Context $context
* @param ?Request $request (A daemon mode request if in daemon mode. May affect the parser used for $file_path)
* @param string $file_path file path for error reporting
* @param string $file_contents file contents to pass to parser. This may deliberately differ from what is currently on disk (e.g. for the language server mode or daemon mode)
* Emit PhanSyntaxError for ParseError|CompileError from the native parser.
*
* @param CodeBase $code_base
* @param Context $context
* @param string $file_path file path for error reporting
* @param FileCacheEntry $file_cache_entry for file contents that were passed to the polyfill parser. May be overridden to ignore what is currently on disk.
* @param ParseError|CompileError $native_parse_error (can be CompileError in 7.3+, will be ParseError in most cases)
// If the polyfill parser emits the first error on the same line as the native parser,
// mention the column that the polyfill parser found for the error.
$diagnostic=$errors[0]??null;
// $diagnostic_error_column is either 0 or the column of the error determined by the polyfill parser
if(!$diagnostic){
return0;
}
// Using FilePositionMap is much faster than substr_count to count lines if you have more than one diagnostic to report (e.g. a string has an unmatched quote).
/** Set an arbitrary limit on the number of warnings for the polyfill diagnostics to prevent excessively large errors for unmatched string quotes, etc. */
privateconstMAX_POLYFILL_WARNINGS=1000;
/**
* Parses the code with the polyfill. If $suppress_parse_errors is false, this also emits SyntaxError.
*
* @param CodeBase $code_base
* @param Context $context
* @param string $file_path file path for error reporting
* @param string $file_contents file contents to pass to parser. May be overridden to ignore what is currently on disk.