Module: Fop::Compiler

Defined in:
lib/fop/compiler.rb

Defined Under Namespace

Modules: Instructions, Validations

Class Method Summary collapse

Class Method Details

.compile(src) ⇒ Object



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

def self.compile(src)
  parser = Parser.new(src)
  nodes, errors = parser.parse

  instructions = nodes.map { |node|
    case node
    when Nodes::Text, Nodes::Regex
      Instructions.regex_match(node.regex)
    when Nodes::Expression
      arg_error = Validations.validate_args(node)
      errors << arg_error if arg_error
      Instructions::ExpressionMatch.new(node)
    else
      raise "Unknown node type #{node}"
    end
  }

  return nil, errors if errors.any?
  return instructions, nil
end