Class: CodeTools::Melbourne

Inherits:
Object
  • Object
show all
Defined in:
lib/rubinius/code/melbourne.rb,
lib/rubinius/code/melbourne/version.rb

Constant Summary collapse

VERSION =
"3.11"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, line, transforms = []) ⇒ Melbourne

Returns a new instance of Melbourne.



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

def initialize(name, line, transforms=[])
  @name = name
  @line = line
  @transforms = transforms
  @magic_handler = nil
  @data_offset = nil
  @pre_exe = []

  # There can be multiple reported, we need to track them all.
  @syntax_errors = []
end

Instance Attribute Details

#magic_handlerObject

Returns the value of attribute magic_handler.



7
8
9
# File 'lib/rubinius/code/melbourne.rb', line 7

def magic_handler
  @magic_handler
end

#pre_exeObject (readonly)

Returns the value of attribute pre_exe.



9
10
11
# File 'lib/rubinius/code/melbourne.rb', line 9

def pre_exe
  @pre_exe
end

#referencesObject

Returns the value of attribute references.



8
9
10
# File 'lib/rubinius/code/melbourne.rb', line 8

def references
  @references
end

#syntax_errorsObject (readonly)

Returns the value of attribute syntax_errors.



31
32
33
# File 'lib/rubinius/code/melbourne.rb', line 31

def syntax_errors
  @syntax_errors
end

#transformsObject

Returns the value of attribute transforms.



6
7
8
# File 'lib/rubinius/code/melbourne.rb', line 6

def transforms
  @transforms
end

Class Method Details

.parse_file(name, line = 1) ⇒ Object



15
16
17
# File 'lib/rubinius/code/melbourne.rb', line 15

def self.parse_file(name, line=1)
  new(name, line).parse_file
end

.parse_string(string, name = "(eval)", line = 1) ⇒ Object



11
12
13
# File 'lib/rubinius/code/melbourne.rb', line 11

def self.parse_string(string, name="(eval)", line=1)
  new(name, line).parse_string string
end

Instance Method Details

#add_magic_comment(str) ⇒ Object



37
38
39
40
41
# File 'lib/rubinius/code/melbourne.rb', line 37

def add_magic_comment(str)
  if @magic_handler
    @magic_handler.add_magic_comment str
  end
end

#add_pre_exe(node) ⇒ Object



33
34
35
# File 'lib/rubinius/code/melbourne.rb', line 33

def add_pre_exe(node)
  @pre_exe << node if node
end

#parse_fileObject



56
57
58
59
60
61
62
63
64
# File 'lib/rubinius/code/melbourne.rb', line 56

def parse_file
  unless @name and File.exist? @name
    raise Errno::ENOENT, @name.inspect
  end

  syntax_error unless ast = file_to_ast(@name, @line)
  ast = AST::EndData.new @data_offset, ast if @data_offset
  ast
end

#parse_string(string) ⇒ Object



51
52
53
54
# File 'lib/rubinius/code/melbourne.rb', line 51

def parse_string(string)
  syntax_error unless ast = string_to_ast(string, @name, @line)
  ast
end

#process_data(offset) ⇒ Object



43
44
45
# File 'lib/rubinius/code/melbourne.rb', line 43

def process_data(offset)
  @data_offset = offset
end

#process_transforms(line, receiver, name, arguments, privately = false) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/rubinius/code/melbourne.rb', line 66

def process_transforms(line, receiver, name, arguments, privately=false)
  @transforms.each do |transform|
    next unless transform.transform_kind == :call

    if node = transform.match?(line, receiver, name, arguments, privately)
      unless node.kind_of? AST::Node
        node = transform.new line, receiver, name, arguments, privately
      end
      return node
    end
  end
  nil
end

#syntax_errorObject



47
48
49
# File 'lib/rubinius/code/melbourne.rb', line 47

def syntax_error
  raise @syntax_errors[0] unless @syntax_errors.empty?
end