Class: LuceneQueryParser::Parser

Inherits:
Parslet::Parser
  • Object
show all
Defined in:
lib/lucene_query_parser/parser.rb

Instance Method Summary collapse

Instance Method Details

#error_location(query) ⇒ Object

Public: find and explain errors in a query, if any

query - the query to check

Returns nil if the query is parseable, or a hash containing information about the invalid query if not.



10
11
12
13
14
15
16
17
# File 'lib/lucene_query_parser/parser.rb', line 10

def error_location(query)
  parse query
  nil
rescue Parslet::ParseFailed => error
  cause = error.cause.ascii_tree
  cause =~ /line (\d+) char (\d+)/
  {:line => $1.to_i, :column => $2.to_i, :message => cause}
end