class RuboCop::AST::ProcessedSource
def create_parser(ruby_version, parser_engine, prism_result)
def create_parser(ruby_version, parser_engine, prism_result) builder = builder_class(parser_engine).new parser_class = parser_class(ruby_version, parser_engine) parser_instance = if prism_result # NOTE: Since it is intended for use with Ruby LSP, it targets only Prism. # If there is no reuse of a pre-parsed result, such as in Ruby LSP, # regular parsing with Prism occurs, and `else` branch will be executed. prism_reparsed = PrismPreparsed.new(prism_result) parser_class.new(builder, parser: prism_reparsed) else parser_class.new(builder) end parser_instance.tap do |parser| # On JRuby there's a risk that we hang in tokenize() if we # don't set the all errors as fatal flag. The problem is caused by a bug # in Racc that is discussed in issue #93 of the whitequark/parser # project on GitHub. parser.diagnostics.all_errors_are_fatal = (RUBY_ENGINE != 'ruby') parser.diagnostics.ignore_warnings = false parser.diagnostics.consumer = lambda do |diagnostic| @diagnostics << diagnostic end end end