Method: AdLint::Cpp::CodeSubstitution#execute

Defined in:
lib/adlint/cpp/subst.rb

#execute(toks) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/adlint/cpp/subst.rb', line 49

def execute(toks)
  rslt_toks = []
  idx = 0
  while first_tok = toks[idx]
    matcher = Matcher.new(@pattern)
    matched_len = matcher.match(toks, idx)
    if matcher.accepted? || idx + matched_len == toks.size
      notify_substitution(toks, idx, matched_len)
      rslt_toks.concat(@replacement.map { |tok|
        Token.new(tok.type, tok.value, first_tok.location, tok.type_hint)
      })
      idx += matched_len
    else
      rslt_toks.push(first_tok)
      idx += 1
    end
  end
  rslt_toks
end