Class: Refill::Compiler

Inherits:
Object
  • Object
show all
Defined in:
lib/refill/compiler.rb

Instance Method Summary collapse

Instance Method Details

#compile(source, output: :nil) ⇒ Object

TODOC

Parameters:

  • source (String, Pathname, File)


5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/refill/compiler.rb', line 5

def compile source, output: :nil
  source = File.read source

  # TODO logger
  puts "source:\n#{source.inspect}"

  ast_root = Refill::Parser::parse(Refill::Lexer::lex(source), parse_tree: File.open('./parse_tree.dot', 'w'), verbose: false)

  # TODO
  # dot -Tpng ./parse_tree.dot -o parse_tree.png

  # TODO proper output option
  output = StringIO.new
  Refill::Translator.new(output: output).translate(ast_root)

  output.rewind
  puts "output:\n#{output.read}"
end