module Rattler::Parsers::Semantic
Semantic
describes parsers that perform a semantic action
Public Instance Methods
bind(scope)
click to toggle source
@param [ParserScope] scope the scope of captures to bind in the code @return [String] ruby code that performs the action
# File lib/rattler/parsers/semantic.rb, line 10 def bind(scope) bindable_code.bind(scope) end
bindable_code()
click to toggle source
@return an object that be bound to a parser scope to return ruby code
that performs the action
# File lib/rattler/parsers/semantic.rb, line 16 def bindable_code @bindable_code ||= create_bindable_code end
semantic?()
click to toggle source
@return true
# File lib/rattler/parsers/semantic.rb, line 21 def semantic? true end
Private Instance Methods
apply(scope)
click to toggle source
# File lib/rattler/parsers/semantic.rb, line 27 def apply(scope) code_bindings = {} scope.each_binding {|k, v| code_bindings[k] = v.inspect } code_captures = scope.captures.map {|_| _.inspect } code_scope = ParserScope.new(code_bindings, code_captures) eval(bind(code_scope)) end