Module: Sexpr::Grammar::Tagging

Included in:
Sexpr, Sexpr::Grammar
Defined in:
lib/sexpr/grammar/tagging.rb

Instance Method Summary collapse

Instance Method Details

#default_tagging_moduleObject



18
19
20
# File 'lib/sexpr/grammar/tagging.rb', line 18

def default_tagging_module
  nil
end

#looks_a_sexpr?(arg) ⇒ Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/sexpr/grammar/tagging.rb', line 41

def looks_a_sexpr?(arg)
  arg.is_a?(Array) and arg.first.is_a?(Symbol)
end

#mod2rulename(mod) ⇒ Object



9
10
11
12
# File 'lib/sexpr/grammar/tagging.rb', line 9

def mod2rulename(mod)
  mod = mod.name.to_s.split('::').last.to_sym if mod.is_a?(Module)
  mod.to_s.gsub(/[A-Z]/){|x| "_#{x.downcase}"}[1..-1].to_sym
end

#rule2modname(rule) ⇒ Object



5
6
7
# File 'lib/sexpr/grammar/tagging.rb', line 5

def rule2modname(rule)
  rule.to_s.gsub(/(^|_)([a-z])/){|x| $2.capitalize}.to_sym
end

#sexpr(input, markers = nil) ⇒ Object



31
32
33
34
35
36
37
38
39
# File 'lib/sexpr/grammar/tagging.rb', line 31

def sexpr(input, markers = nil)
  case input
  when Array
    tag_sexpr input, markers
  else
    sexpr = parser!.to_sexpr(parse(input))
    tag_sexpr sexpr, markers, true
  end
end

#tagging_module_for(rulename) ⇒ Object



22
23
24
25
26
27
28
29
# File 'lib/sexpr/grammar/tagging.rb', line 22

def tagging_module_for(rulename)
  if ref = tagging_reference
    modname = rule2modname(rulename)
    ref.const_get(modname, false) rescue default_tagging_module
  else
    default_tagging_module
  end
end

#tagging_referenceObject



14
15
16
# File 'lib/sexpr/grammar/tagging.rb', line 14

def tagging_reference
  nil
end