Class: FifthedSim::Compiler

Inherits:
Object
  • Object
show all
Defined in:
lib/fifthed_sim/compiler.rb,
lib/fifthed_sim/compiler/parser.rb,
lib/fifthed_sim/compiler/transform.rb

Defined Under Namespace

Classes: CompileError, Parser, Transform, TransformError

Class Method Summary collapse

Class Method Details

.compile(str) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'lib/fifthed_sim/compiler.rb', line 12

def self.compile(str)
  tree = self.parse(str)
  transformed = Transform.new.apply(tree)
  if transformed.is_a? DiceExpression
    transformed
  else
    raise TransformError.new(transformed)
  end
end

.parse(str) ⇒ Object



3
4
5
6
7
8
9
10
# File 'lib/fifthed_sim/compiler.rb', line 3

def self.parse(str)
  begin
    Parser.new.parse(str)
  rescue Parslet::ParseFailed => e
    msg = e.message
    raise CompileError.new(e)
  end
end