Class: Grammoire::EvaluationContext

Inherits:
Object
  • Object
show all
Defined in:
lib/grammoire/evaluation_context.rb

Instance Method Summary collapse

Constructor Details

#initialize(grammar) ⇒ EvaluationContext

Returns a new instance of EvaluationContext.



5
6
7
8
# File 'lib/grammoire/evaluation_context.rb', line 5

def initialize(grammar)
  @grammar = grammar
  with_data_points({})
end

Instance Method Details

#data(name) ⇒ Object

Raises:



14
15
16
17
18
# File 'lib/grammoire/evaluation_context.rb', line 14

def data(name)
  raise GrammarError.new("Data point '#{name}' doesn't exist in the evaluation context.") unless @data.has_key? name

  return @data[name]
end

#eval(rule) ⇒ Object



20
21
22
# File 'lib/grammoire/evaluation_context.rb', line 20

def eval(rule)
  @grammar.evaluate(rule, @data)
end

#with_data_points(data) ⇒ Object



10
11
12
# File 'lib/grammoire/evaluation_context.rb', line 10

def with_data_points(data)
  @data = data
end