def scan_tags
return unless @scanner.scan(regexp(otag))
current_ctag = self.ctag
type = @scanner.scan(/#|\^|\/|=|!|<|>|&|\{/)
@scanner.skip(/\s*/)
if ANY_CONTENT.include?(type)
r = /\s*#{regexp(type)}?#{regexp(current_ctag)}/
content = scan_until_exclusive(r)
else
content = @scanner.scan(ALLOWED_CONTENT)
end
error "Illegal content in tag" if content.empty?
case type
when '#'
block = [:multi]
@result << [:mustache, :section, content, block]
@sections << [content, position, @result]
@result = block
when '^'
block = [:multi]
@result << [:mustache, :inverted_section, content, block]
@sections << [content, position, @result]
@result = block
when '/'
section, pos, result = @sections.pop
@result = result
if section.nil?
error "Closing unopened #{content.inspect}"
elsif section != content
error "Unclosed section #{section.inspect}", pos
end
when '!'
when '='
self.otag, self.ctag = content.split(' ', 2)
when '>', '<'
@result << [:mustache, :partial, content]
when '{', '&'
type = "}" if type == "{"
@result << [:mustache, :utag, content]
else
@result << [:mustache, :etag, content]
end
@scanner.skip(/\s+/)
@scanner.skip(regexp(type)) if type
unless close = @scanner.scan(regexp(current_ctag))
error "Unclosed tag"
end
@scanner.skip(/\s+/) if SKIP_WHITESPACE.include?(type)
end