1 ! Copyright (C) 2008 Alex Chapman
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: kernel semantic-db sequences sequences.lib splitting ;
9 : create-root ( -- node ) "" create-node ;
11 : get-root ( -- node )
12 in-directory-relation ultimate-objects ?1node-result ;
14 : ensure-root ( -- node ) get-root [ create-root ] unless* ;
16 : create-file ( parent name -- node )
17 create-node swap dupd in-directory ;
19 : files-in-directory ( node -- nodes ) in-directory-subjects ;
21 : file-in-directory ( name node -- node )
22 in-directory-relation subjects-with-cor ?1node-result ;
24 : parent-directory ( file-node -- dir-node )
25 in-directory-objects ?first ;
27 : (path>node) ( node name -- node )
28 swap [ file-in-directory ] [ drop f ] if* ;
30 : path>node ( path -- node )
31 ensure-root swap [ (path>node) ] each ;
33 : path>file ( path -- file )
34 path>node [ has-filename-subjects ?first ] [ f ] if* ;
36 : (node>path) ( root seq node -- seq )
40 dup node-content pick push
48 : node>path* ( root node -- path )
49 V{ } clone swap (node>path) dup empty?
50 [ drop f ] [ <reversed> ] if ;
52 : node>path ( node -- path )
53 ensure-root swap node>path* ;
55 : file>path ( node -- path )
56 has-filename-objects ?first [ node>path ] [ f ] if* ;