Class: Expression

Inherits:
Object
  • Object
show all
Defined in:
lib/glark/match/expression.rb

Overview

An expression, which can be applied (processed) against a Glark::File.

Direct Known Subclasses

CompoundExpression, RegexpExpression

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeExpression

Returns a new instance of Expression.



11
12
13
14
# File 'lib/glark/match/expression.rb', line 11

def initialize
  @match_line_number = nil
  @matches = Array.new
end

Instance Attribute Details

#matchesObject

Returns the value of attribute matches.



9
10
11
# File 'lib/glark/match/expression.rb', line 9

def matches
  @matches
end

Instance Method Details

#add_match(lnum) ⇒ Object



16
17
18
# File 'lib/glark/match/expression.rb', line 16

def add_match lnum
  @matches.push lnum
end

#end_positionObject



24
25
26
# File 'lib/glark/match/expression.rb', line 24

def end_position
  start_position
end

#process(file, formatter) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/glark/match/expression.rb', line 33

def process file, formatter
  reset_file file.fname

  rgstart = file.get_range_start
  rgend = file.get_range_end
  
  lastmatch = 0
  lnum = 0
  file.each_line do |line|
    if ((!rgstart || lnum >= rgstart) && 
        (!rgend   || lnum < rgend)   &&
        evaluate(line, lnum, file, formatter))

      break if formatter.process_match start_position, end_position, lastmatch, lnum
      lastmatch = lnum + 1
    end
    lnum += 1
  end

  formatter.process_end lnum
end

#reset_file(file) ⇒ Object



28
29
30
31
# File 'lib/glark/match/expression.rb', line 28

def reset_file file
  @match_line_number = nil
  @matches = Array.new
end

#start_positionObject



20
21
22
# File 'lib/glark/match/expression.rb', line 20

def start_position
  @match_line_number
end

#to_sObject



55
56
57
# File 'lib/glark/match/expression.rb', line 55

def to_s
  inspect
end