module Leftovers::Parser

Constants

PARSER

Public Class Methods

parse_with_comments(string, file = '(string)', line = 1) click to toggle source

mostly copied from github.com/whitequark/parser/blob/master/lib/parser/base.rb but with our parser

# File lib/leftovers/parser.rb, line 11
def parse_with_comments(string, file = '(string)', line = 1)
  PARSER.reset
  source_buffer = ::Parser::CurrentRuby.send(
    :setup_source_buffer, file, line, string, PARSER.default_encoding
  )
  PARSER.parse_with_comments(source_buffer)
end

Private Class Methods

parser() click to toggle source

mostly copied from github.com/whitequark/parser/blob/master/lib/parser/base.rb but with our builder

# File lib/leftovers/parser.rb, line 23
def parser
  p = ::Parser::CurrentRuby.new(Leftovers::AST::Builder.new)
  p.diagnostics.all_errors_are_fatal = true
  p.diagnostics.ignore_warnings = true

  p.diagnostics.consumer = lambda do |diagnostic|
    diagnostic
  end

  p
end