Module: Condenser::ParseHelpers

Included in:
CSSMediaCombinerProcessor, JSAnalyzer, SVGTransformer::Template
Defined in:
lib/condenser/helpers/parse_helpers.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#matchedObject

Returns the value of attribute matched.



3
4
5
# File 'lib/condenser/helpers/parse_helpers.rb', line 3

def matched
  @matched
end

Instance Method Details

#current_lineObject



45
46
47
48
49
# File 'lib/condenser/helpers/parse_helpers.rb', line 45

def current_line
  start = (@source.rindex(/(\n|\z)/, @old_index) || 0) + 1
  uptop = @source.index(/(\n|\z)/, @index) || (@old_index + @matched.length)
  @source[start..uptop]
end

#cursorObject



51
52
53
54
55
56
# File 'lib/condenser/helpers/parse_helpers.rb', line 51

def cursor
  start = (@source.rindex("\n", @old_index) || 0) + 1
  uptop = @source.index("\n", @index) || (@old_index + @matched.length)
  lineno = @source[0..start].count("\n") + 1
  "#{lineno.to_s.rjust(4)}: " + @source[start..uptop] + "\n      #{'-'* (@index-1-start)}#{'^'*(@matched.length)}"
end

#eos?Boolean

Returns:

  • (Boolean)


5
6
7
# File 'lib/condenser/helpers/parse_helpers.rb', line 5

def eos?
  @index >= (@source.size - 1)
end

#forward(by = 1) ⇒ Object



30
31
32
# File 'lib/condenser/helpers/parse_helpers.rb', line 30

def forward(by=1)
  @index += by
end

#next_wordObject



40
41
42
43
# File 'lib/condenser/helpers/parse_helpers.rb', line 40

def next_word
  nw = @source.match(/\s*(\S+)/, @index)
  nw.nil? ? nil : nw[1]
end

#pre_matchObject



22
23
24
# File 'lib/condenser/helpers/parse_helpers.rb', line 22

def pre_match
  @source[@old_index...(@index-@matched.size)]
end

#rewind(by = 1) ⇒ Object



26
27
28
# File 'lib/condenser/helpers/parse_helpers.rb', line 26

def rewind(by=1)
  @index -= by
end

#scan_until(r) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/condenser/helpers/parse_helpers.rb', line 9

def scan_until(r)
  index = @source.index(r, @index)
  match = @source.match(r, @index)
  if match
    @matched = match.to_s
    @old_index = @index
    @index = index + @matched.size
  else
    @matched = nil
  end
  match
end

#seek(pos) ⇒ Object



34
35
36
37
38
# File 'lib/condenser/helpers/parse_helpers.rb', line 34

def seek(pos)
  @old_index = nil
  @matched = nil
  @index = pos
end