Class: Syntax::CssTokenizer

Inherits:
Tokenizer show all
Defined in:
lib/zena/code/default_syntax.rb

Instance Method Summary collapse

Instance Method Details

#stepObject



213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
# File 'lib/zena/code/default_syntax.rb', line 213

def step
  if comments = scan(/\s*\/\*.*?\*\/\s*/m)
    start_group :comment, comments
  elsif variables = scan(/[^\{]*?\{[^\}]*?\}/m)
    variables =~ /(\s*)([^\{]*?)\{([^\}]*?)\}/m
    start_group :normal, $1
    vars = $3
    selectors = $2.split(',').map { |s| s.strip }
    selectors.each_index do |i|
      selectors[i].gsub('.','|.').gsub('#','|#').split('|').each do |g|
        g = g.split(' ')
        g.each do |s|
          if s[0..0] == '#'
            start_group :id, s
          elsif s[0..0] == '.'
            start_group :class, s
          else
            start_group :tag, s
          end
          start_group :normal, ' '
        end
      end
      unless i == selectors.size - 1
        start_group :punct, ', '
      end
    end
    start_group :punct, '{ '

    rest = vars
    while rest != '' && rest =~ /([\w-]+)\s*:\s*(.*?)\s*;(.*)/m
      start_group :variable, $1
      start_group :punct, ':'
      start_group :normal, $2
      start_group :punct, '; '
      rest = $3
    end
    start_group :punct, "#{rest}}"
  else
    start_group :normal, scan(/./m)
  end
end