Sha256: 1e91614328f3313d4fe58ec51c0bc43138a127610e26ea155faadff722c9fb39

Contents?: true

Size: 555 Bytes

Versions: 1

Compression:

Stored size: 555 Bytes

Contents

grammar Sentence
  rule phrase
    token* {
      def to_s(env = {})
        elements.collect { |x| x.to_s(env) }.join
      end
    }
  end

  rule token
    literal / variable
  end

  rule literal
    (space / word / punctuation) {
      def to_s(env = {})
        text_value
      end
    }
  end

  rule variable
    "(" word ")" {
      def to_s(env = {})
        arr = env[word.text_value]
        arr[rand(arr.length)]
      end
    }
  end

  rule space
    ' '+
  end

  rule word
    [a-zA-Z0-9]+
  end

  rule punctuation
    [,.!?]
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
roflbot-0.0.0 lib/roflbot/sentence.tt