Skip to content
class method

Prism::Translation::Parser.new

new(builder = Prism::Translation::Parser::Builder.new, parser: Prism)

The builder argument is used to create the parser using our custom builder class by default.

By using the :parser keyword argument, you can translate in a way that is compatible with the Parser gem using any parser.

For example, in RuboCop for Ruby LSP, the following approach can be used to improve performance by reusing a pre-parsed Prism::ParseLexResult:

class PrismPreparsed def initialize(prism_result) @prism_result = prism_result end

Example
def parse_lex(source, **options)
  @prism_result
end

end

prism_preparsed = PrismPreparsed.new(prism_result)

Prism::Translation::Ruby34.new(builder, parser: prism_preparsed)

In an object passed to the :parser keyword argument, the parse and parse_lex methods should be implemented as needed.