Module: Parsing

Defined in:
lib/parsing.rb

Class Method Summary collapse

Class Method Details

.parse_block(block, local_variables = []) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/parsing.rb', line 7

def parse_block(block, local_variables = [])
    parser = Parser::CurrentRuby.default_parser
    local_variables.each do |var|
        parser.static_env.declare(var)
    end
    
    parser_source = Parser::Source::Buffer.new('(string)', 1)
    parser_source.source = block.to_source(strip_enclosure: true)
    
    return parser.parse(parser_source)
end

.parse_method(method) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/parsing.rb', line 19

def parse_method(method)
    parser = Parser::CurrentRuby.default_parser
    method.parameters.each do |param|
        parser.static_env.declare(param[1])
    end

    parser_source = Parser::Source::Buffer.new('(string)', 1)
    # TODO: dirty hack necessary because Parser is broken
    parser_source.source = method.source.lines[1..-2].join
    
    return parser.parse(parser_source)
end