Sha256: fa6f27396b617bd64744666d76e1e6ed65887972e7fa2faf5b7b0ec33505dc0c

Contents?: true

Size: 938 Bytes

Versions: 3

Compression:

Stored size: 938 Bytes

Contents

# frozen_string_literal: true

module Cel
  class Environment
    def initialize(declarations = nil)
      @declarations = declarations
      @parser = Parser.new
      @checker = Checker.new(@declarations)
    end

    def compile(expr)
      ast = @parser.parse(expr)
      @checker.check(ast)
      ast
    end

    def check(expr)
      ast = @parser.parse(expr)
      @checker.check(ast)
    end

    def program(expr)
      expr = compile(expr) if expr.is_a?(::String)
      Runner.new(expr)
    end

    def evaluate(expr, bindings = nil)
      context = Context.new(bindings)
      expr = compile(expr) if expr.is_a?(::String)
      Program.new(context).evaluate(expr)
    end

    private

    def validate(ast, structs); end
  end

  class Runner
    def initialize(ast)
      @ast = ast
    end

    def evaluate(bindings = nil)
      context = Context.new(bindings)
      Program.new(context).evaluate(@ast)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
cel-0.1.2 lib/cel/environment.rb
cel-0.1.1 lib/cel/environment.rb
cel-0.1.0 lib/cel/environment.rb