module Haml::AttributeParser
def shift_key!(tokens)
-
(String)- - attribute name in String
Parameters:
-
tokens(Array) -- - Ripper tokens. Scanned tokens will be destructively removed from this argument.
def shift_key!(tokens) while !tokens.empty? && IGNORED_TYPES.include?(tokens.first[TYPE]) tokens.shift # ignore spaces end _, type, first_text = tokens.shift case type when :on_label # `key:` first_text.tr(':', '') when :on_symbeg # `:key =>`, `:'key' =>` or `:"key" =>` key = tokens.shift[TEXT] if first_text != ':' # `:'key'` or `:"key"` expect_string_end!(tokens.shift) end shift_hash_rocket!(tokens) key when :on_tstring_beg # `"key":`, `'key':` or `"key" =>` key = tokens.shift[TEXT] next_token = tokens.shift if next_token[TYPE] != :on_label_end # on_label_end is `":` or `':`, so `"key" =>` expect_string_end!(next_token) shift_hash_rocket!(tokens) end key else raise UnexpectedKeyError.new("unexpected token is given!: #{first_text} (#{type})") end end