module CodeRay module Scanners # YAML Scanner # # $Id$ # # See http://yaml.org for information about YAML. class YAML < Scanner include Streamable register_for :yaml private def setup @state = :initial end def scan_tokens tokens, options state = @state start_of_line = true until eos? kind = :error match = nil if match = scan(/\s+/m) if match.index ?\n # contains newline start_of_line = true end kind = :space else case state when :initial if bol? and scan(/---(\s*.+)/m) kind = :preprocessor else raise_inspect '[BUG] else-case reached with state %p' % [state], tokens end when :attribute if scan(/#{TAG_END}/) kind = :tag state = :initial elsif scan(/#{ATTR_NAME}/o) kind = :attribute_name state = :attribute_equal else getch end else raise_inspect 'Unknown state: %p' % [state], tokens end start_of_line = false end match ||= matched if $DEBUG and (not kind or kind == :error) raise_inspect 'Error token %p in line %d' % [[match, kind], line], tokens end raise_inspect 'Empty token', tokens unless match tokens << [match, kind] end if options[:keep_state] @state = state end tokens end end end end