Class: Sourcify::Common::Parser::Converter

Inherits:
Object
  • Object
show all
Defined in:
lib/sourcify/lib/sourcify/common/parser/converter.rb

Constant Summary collapse

RUBY_PARSER =
RubyParser.new
RUBY_2_RUBY =
Ruby2Ruby.new

Class Method Summary collapse

Class Method Details

.to_code(sexp) ⇒ Object



21
22
23
# File 'lib/sourcify/lib/sourcify/common/parser/converter.rb', line 21

def to_code(sexp)
  RUBY_2_RUBY.process(Sexp.from_array(sexp.to_a))
end

.to_sexp(code, file = nil) ⇒ Object



10
11
12
13
14
15
16
17
18
19
# File 'lib/sourcify/lib/sourcify/common/parser/converter.rb', line 10

def to_sexp(code, file = nil)
  retried = false
  begin
    RUBY_PARSER.reset
    (retried ? RubyParser.new : RUBY_PARSER).parse(*[code, file].compact)
  rescue Racc::ParseError, SyntaxError
    return nil if retried
    retried = true; retry
  end
end