Module: Condenser::ParseHelpers
- Included in:
- CSSMediaCombinerProcessor, JSAnalyzer, SVGTransformer::Template
- Defined in:
- lib/condenser/helpers/parse_helpers.rb
Instance Attribute Summary collapse
-
#matched ⇒ Object
Returns the value of attribute matched.
Instance Method Summary collapse
- #current_line ⇒ Object
- #cursor ⇒ Object
- #eos? ⇒ Boolean
- #forward(by = 1) ⇒ Object
- #gobble(r) ⇒ Object
- #next_word ⇒ Object
- #pre_match ⇒ Object
- #rewind(by = 1) ⇒ Object
- #scan_until(r) ⇒ Object
- #seek(pos) ⇒ Object
Instance Attribute Details
#matched ⇒ Object
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_line ⇒ Object
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 |
#cursor ⇒ Object
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
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 |
#gobble(r) ⇒ Object
58 59 60 61 62 63 |
# File 'lib/condenser/helpers/parse_helpers.rb', line 58 def gobble(r) m = @source.match(r, @index) if m&.begin(0) == @index scan_until(r) end end |
#next_word ⇒ Object
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_match ⇒ Object
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 |