diff -ur v5/inc_ut.py v6/inc_ut.py --- v5/inc_ut.py 2020-09-16 08:36:04.000000000 +0900 +++ v6/inc_ut.py 2020-09-24 21:32:53.000000000 +0900 @@ -7,6 +7,38 @@ import nkf import dbg +def buf_new(): + dic = {} + ks = [] + + def set(s): + get_k = lambda : s[ 2 : ] + + if s.startswith( '@>' ): + ks.append( get_k() ) + return True + if s.startswith( '@<' ): + if ks: + ks.pop() + return True + if s.startswith( '@!' ): + k = get_k() + if k in dic: + dic.pop( k ) + return True + if ks: + k = ks[ -1 ] + if k not in dic: + dic[ k ] = '' + dic[ k ] += s + '\n' + return True + + return False + + get = dic.get + + return empty.new( locals() ) + def read_str(path): r = False with open( path, 'rb' ) as f: @@ -32,6 +64,8 @@ ] pat_lst = list( map( re.compile, lst ) ) + buf = buf_new() + def match_path(s): for p in pat_lst: m = p.match( s ) @@ -55,10 +89,18 @@ search_dirs = [ os.path.dirname( __file__ ) ] def inc_text(s): + if buf.set( s ): + return True + (path, opts) = match_path( s ) if path == None: return None + r = buf.get( path ) + if r != None: + paths.append( path ) + return empty.new( s=cut_tail_nl( r ), opts=opts ) + path_lst = [ path ] if not path.startswith( '/' ): path_lst += list( map( lambda dir_: os.path.join( dir_, path ), search_dirs ) ) @@ -81,14 +123,17 @@ if r == None: return s if r == True: - return '' + return True s = cvt_opts( r.s, r.opts ) if '-nr' not in r.opts: s = exp( s ) paths.pop() return s - exp = lambda s: '\n'.join( map( lambda i_s: exp_line( *i_s ), enumerate( s.split( '\n' ) ) ) ) + def exp(s): + f_map = lambda i_s: exp_line( *i_s ) + f_filter = lambda s: s != True + return '\n'.join( filter( f_filter, map( f_map, enumerate( s.split( '\n' ) ) ) ) ) return empty.new( locals() )