maetl / calyx

A Ruby library for generating text with recursive template grammars.
MIT License
61 stars 5 forks source link

Filters fail when you try to use Calyx classes #17

Closed tra38 closed 8 years ago

tra38 commented 8 years ago
class Greeting < Calyx::Grammar
  filter :shoutycaps do |input|
    input.upcase
  end

  start '{hello.shoutycaps} there.', 'Why, {hello} there.'
  hello 'hello'
end

p Greeting.new.generate

#/Users/tariq.ali/.rvm/gems/ruby-2.1.1/gems/calyx-0.11.2/lib/calyx/registry.rb:32:
#in `mapping': wrong number of arguments (1 for 2) (ArgumentError)
#   from /Users/tariq.ali/.rvm/gems/ruby-2.1.1/gems/calyx-0.11.2/lib/calyx
#      /grammar.rb:52:in `filter'
#   from grammar.rb:4:in `<class:Greeting>'
#   from grammar.rb:3:in `<main>'

The code, however, works fine when you use the block syntax though...

greeting = Calyx::Grammar.new do
  filter :shoutycaps do |input|
    input.upcase
  end

  start '{hello.upcase} there.', 'Why, {hello} there.'
  hello 'hello'
end

p greeting.generate
#"Why, hello there."
#"HELLO there."

I was attempting to see whether filters could be used as a good way to simulate "tagging" as implemented in Improv, a JavaScript library inspired by Tracery but uses "models" to help guide text-generation. I may explore this bug in the future and see if I can submit a PR later on. This is just me submitting it so that I remember this problem exists.

maetl commented 8 years ago

Was a typo in the original code. Closed by #18.

Thanks for picking this up.