@staticmethod<EOL><INDENT>def parse_instructions(inst, hierarchy=None):<DEDENT>
dirstack = []<EOL>data_tree = {}<EOL>data_files = {}<EOL>hierarchies = hierarchy if hierarchy else []<EOL>if len(hierarchies) > <NUM_LIT:0> and pimms.is_str(hierarchies[<NUM_LIT:0>]): hierarchies = [hierarchies]<EOL>known_filekeys = ('<STR_LIT>','<STR_LIT>','<STR_LIT>','<STR_LIT>','<STR_LIT>')<EOL>hierarchies = list(hierarchies)<EOL>def handle_file(inst):<EOL><INDENT>if isinstance(inst, tuple):<EOL><INDENT>for ii in inst: handle_file(ii)<EOL>return None<EOL><DEDENT>dat = None<EOL>for hrow in hierarchies:<EOL><INDENT>if not all(h in inst for h in hrow): continue<EOL>dat = data_tree<EOL>for h in hrow:<EOL><INDENT>v = inst[h]<EOL>if h not in dat: dat[h] = {}<EOL>dat = dat[h]<EOL>if v not in dat: dat[v] = {}<EOL>dat = dat[v]<EOL><DEDENT>break<EOL><DEDENT>if dat is None:<EOL><INDENT>hh = []<EOL>dat = data_tree<EOL>for (k,v) in six.iteritems(inst):<EOL><INDENT>if k in known_filekeys: continue<EOL>hh.append(k)<EOL>if k not in dat: dat[k] = {}<EOL>dat = dat[k]<EOL>if v not in dat: dat[v] = {}<EOL>dat = dat[v]<EOL><DEDENT>hierarchies.append(hh)<EOL><DEDENT>flnm = os.path.join(*dirstack)<EOL>dat[flnm] = pyr.pmap(inst).set('<STR_LIT>', flnm)<EOL>data_files[flnm] = inst<EOL>return None<EOL><DEDENT>def handle_dir(inst):<EOL><INDENT>dnm = None<EOL>for k in inst:<EOL><INDENT>if dnm: dnm = handle_inst(k, dnm)<EOL>elif pimms.is_str(k): dnm = k<EOL>elif not isinstance(k, tuple) or len(k) != <NUM_LIT:2>: raise ValueError('<STR_LIT>')<EOL>else: dnm = handle_inst(k, dnm)<EOL><DEDENT>return None<EOL><DEDENT>def handle_inst(inst, k=None):<EOL><INDENT>if k: dirstack.append(k)<EOL>if pimms.is_map(inst): handle_file(inst)<EOL>elif isinstance(inst, (list, tuple)):<EOL><INDENT>if len(inst) == <NUM_LIT:0> or not pimms.is_map(inst[<NUM_LIT:0>]): handle_dir(inst)<EOL>else: handle_file(inst)<EOL><DEDENT>else: raise ValueError('<STR_LIT>' % (inst,))<EOL>if k: dirstack.pop()<EOL>return None<EOL><DEDENT>handle_inst(inst)<EOL>return (data_files, data_tree)<EOL>
FileMap.parse_instructions(inst) yields the tuple (data_files, data_tree); data_files is a
  map whose keys are relative filenames and whose values are the instruction data for the
  given file; data_tree is a lazy/nested map structure of the instruction data using 'type'
  as the first-level keys.

The optional argument hierarchy specifies the hierarchy of the data to return in the
data_tree. For example, if hierarchy is ['hemi', 'surface', 'roi'] then a file with the
instructions {'type':'property', 'hemi':'lh', 'surface':'white', 'roi':'V1', 'name':'x'}
would appear at data_tree['hemi']['lh']['surface']['white']['roi']['V1']['property']['x']
whereas if hierarchy were ['roi', 'hemi', 'surface'] it would appear at
data_tree['roi']['V1']['surface']['white']['hemi']['lh']['property']['x']. By default the
ordering is undefined.