class SyntaxTree::CLI::Search
in the given files.
An action of the CLI that searches for the given pattern matching pattern
def initialize(query)
def initialize(query) query = File.read(query) if File.readable?(query) pattern = begin Pattern.new(query).compile rescue Pattern::CompilationError => error warn(error.message) exit(1) end @search = SyntaxTree::Search.new(pattern) end
def run(item)
def run(item) search.scan(item.handler.parse(item.source)) do |node| location = node.location line = location.start_line bold_range = if line == location.end_line location.start_column...location.end_column else location.start_column.. end source = item.source.lines[line - 1].chomp source[bold_range] = Color.bold(source[bold_range]).to_s puts("#{item.filepath}:#{line}:#{location.start_column}: #{source}") end end