def match(tokens, definitions)
      token_index = 0

      @pattern.each do |element|
        name = element.to_s
        optional = name[-1, 1] == '?'
        name = name.chop if optional

        case element
        when Symbol
          if tags_match?(name, tokens, token_index)
            token_index += 1
            next
          else
            if optional
              next
            else
              return false
            end
          end
        when String
          return true if optional && token_index == tokens.size

          if definitions.key?(name.to_sym)
            sub_handlers = definitions[name.to_sym]
          else
            raise ChronicPain, "Invalid subset #{name} specified"
          end

          sub_handlers.each do |sub_handler|
            return true if sub_handler.match(tokens[token_index..tokens.size], definitions)
          end
        else
          raise ChronicPain, "Invalid match type: #{element.class}"
        end
      end

      return false if token_index != tokens.size
      return true
    end
def match(tokens, definitions)
      token_index = 0

      @pattern.each do |element|
        name = element.to_s
        optional = name[-1, 1] == '?'
        name = name.chop if optional

        case element
        when Symbol
          if tags_match?(name, tokens, token_index)
            token_index += 1
            next
          else
            if optional
              next
            else
              return false
            end
          end
        when String
          return true if optional && token_index == tokens.size

          if definitions.key?(name.to_sym)
            sub_handlers = definitions[name.to_sym]
          else
            raise ChronicPain, "Invalid subset #{name} specified"
          end

          sub_handlers.each do |sub_handler|
            return true if sub_handler.match(tokens[token_index..tokens.size], definitions)
          end
        else
          raise ChronicPain, "Invalid match type: #{element.class}"
        end
      end

      return false if token_index != tokens.size
      return true
    end
pattern        - An Array of patterns to match tokens against.
 handler_method - A Symbole representing the method to be invoked
   when patterns are matched.
 tokens - An Array of tokens to process.
 definitions - A Hash of definitions to check against.

 Returns true if a match is found.