# File lib/liquid/block.rb, line 5
    def parse(tokens)
      @nodelist ||= []
      @nodelist.clear

      while token = tokens.shift 

        case token
        when /^#{TagStart}/                   
          if token =~ /^#{TagStart}\s*(\w+)\s*(.*)?#{TagEnd}$/

            # if we found the proper block delimitor just end parsing here and let the outer block
            # proceed                               
            if block_delimiter == $1
              end_tag
              return
            end

            # fetch the tag from registered blocks
            if tag = Template.tags[$1]
              @nodelist << tag.new($1, $2, tokens)
            else
              # this tag is not registered with the system 
              # pass it to the current block for special handling or error reporting
              unknown_tag($1, $2, tokens)
            end              
          else
            raise SyntaxError, "Tag '#{token}' was not properly terminated with regexp: #{TagEnd.inspect} "
          end
        when /^#{VariableStart}/
          @nodelist << create_variable(token)
        when ''
          # pass
        else
          @nodelist << token
        end
      end       
      
      # Make sure that its ok to end parsing in the current block. 
      # Effectively this method will throw and exception unless the current block is 
      # of type Document 
      assert_missing_delimitation!
    end