Class: CodeTools::Compiler::Parser

Inherits:
Stage
  • Object
show all
Defined in:
lib/rubinius/code/compiler/stages.rb

Overview

source -> AST

Direct Known Subclasses

FileParser, StringParser

Instance Attribute Summary collapse

Attributes inherited from Stage

#next_stage, #printer

Instance Method Summary collapse

Methods inherited from Stage

#create_next_stage, #input, #insert, next_stage, next_stage_class, #processor, #run_next, stage, stage_name

Constructor Details

#initialize(compiler, last) ⇒ Parser

Returns a new instance of Parser.



163
164
165
166
167
168
# File 'lib/rubinius/code/compiler/stages.rb', line 163

def initialize(compiler, last)
  super
  compiler.parser = self
  @transforms = []
  @processor = Melbourne
end

Instance Attribute Details

#transformsObject

Returns the value of attribute transforms.



161
162
163
# File 'lib/rubinius/code/compiler/stages.rb', line 161

def transforms
  @transforms
end

Instance Method Details

#add_magic_comment(str) ⇒ Object



200
201
202
203
204
# File 'lib/rubinius/code/compiler/stages.rb', line 200

def add_magic_comment(str)
  if m = /-\*-\s*(.*?)\s*(-\*-)$/.match(str)
    enable_transform(m[1].to_sym)
  end
end

#createObject



194
195
196
197
198
# File 'lib/rubinius/code/compiler/stages.rb', line 194

def create
  @parser = @processor.new(@file, @line, @transforms)
  @parser.magic_handler = self
  @parser
end

#default_transformsObject



174
175
176
# File 'lib/rubinius/code/compiler/stages.rb', line 174

def default_transforms
  @transforms.concat AST::Transforms.category(:default)
end

#enable_category(name) ⇒ Object



184
185
186
187
# File 'lib/rubinius/code/compiler/stages.rb', line 184

def enable_category(name)
  transforms = AST::Transforms.category name
  @transforms.concat transforms if transforms
end

#enable_transform(name) ⇒ Object



189
190
191
192
# File 'lib/rubinius/code/compiler/stages.rb', line 189

def enable_transform(name)
  transform = AST::Transforms[name]
  @transforms << transform if transform
end


178
179
180
181
182
# File 'lib/rubinius/code/compiler/stages.rb', line 178

def print(klass=ASTPrinter)
  @printer = klass.new
  @printer.insert self
  @printer
end

#root(klass) ⇒ Object



170
171
172
# File 'lib/rubinius/code/compiler/stages.rb', line 170

def root(klass)
  @root = klass
end

#runObject



206
207
208
209
210
211
# File 'lib/rubinius/code/compiler/stages.rb', line 206

def run
  @output = @root.new parse
  @output.file = @file
  @output.pre_exe = @parser.pre_exe
  run_next
end