Module: KeywordSearch
- Defined in:
- lib/keyword_search.rb,
lib/keyword_search/grammar.rb,
lib/keyword_search/evaluator.rb,
lib/keyword_search/definition.rb
Defined Under Namespace
Classes: Definition, Evaluator, Grammar, ParseError, Parser
Constant Summary collapse
- VERSION =
'1.2.0'
Class Method Summary collapse
Class Method Details
.search(input_string, definition = nil, &block) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/keyword_search.rb', line 15 def search(input_string, definition=nil, &block) @evaluator ||= Evaluator.new definition ||= Definition.new(&block) parse_result = Parser.parse(Lexer.lex(input_string)) unless parse_result.has_error? results = @evaluator.evaluate(parse_result.parse_tree) results.each do |key, terms| definition.handle(key, terms) end results else raise ParseError, "Unexpected token #{parse_result.unexpected_token.inspect}" end end |