Class: RaddDjur::Grammar::Derivs

Inherits:
Object
  • Object
show all
Includes:
Immutable
Defined in:
lib/radd_djur/grammar.rb

Instance Method Summary collapse

Constructor Details

#initialize(grammar, str) ⇒ Derivs

Returns a new instance of Derivs.



35
36
37
38
39
# File 'lib/radd_djur/grammar.rb', line 35

def initialize(grammar, str)
  @grammar = grammar
  @str = str
  @memo = {}
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(mid, *args) ⇒ Object



52
53
54
# File 'lib/radd_djur/grammar.rb', line 52

def method_missing(mid, *args)
  @memo[mid] ||= @grammar.parser(mid).parse(self)
end

Instance Method Details

#charObject



41
42
43
44
45
46
47
48
49
50
# File 'lib/radd_djur/grammar.rb', line 41

def char
  @memo[:char] ||=
    Promise.delay {
      if @str.empty?
        NO_PARSE
      else
        Parsed.new(@str[0], Derivs.new(@grammar, @str[1..-1]))
      end
    }
end