Module: HamlParser::Utils

Defined in:
lib/haml_parser/utils.rb

Class Method Summary collapse

Class Method Details

.balance(scanner, start, finish, depth = 1) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/haml_parser/utils.rb', line 5

def balance(scanner, start, finish, depth = 1)
  re = /(#{Regexp.escape(start)}|#{Regexp.escape(finish)})/
  while depth > 0 && scanner.scan_until(re)
    if scanner.matched == start
      depth += 1
    else
      depth -= 1
    end
  end
  depth
end