Method: Ascode::Parser::ConditionBlock#find

Defined in:
lib/ascode/parser/condition_block.rb

#find(what) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/ascode/parser/condition_block.rb', line 30

def find(what)
  level = 0
  skip = 0
  @block.split("").to_enum.each_with_index do |char, index|
    if skip > 0
      skip -= 1
      next
    elsif char == "\""
      literal = Literal.new @block, index
      literal.parse
      skip = literal.length
    else
      return index if char == what && level.zero?
      level += 1 if char == "["
      level -= 1 if char == "]"
    end
  end

  -1
end