Commits

ZyX_I  committed d0fb431

@/fwc: Fixed func matcher, moved call to foreign matcher function to the constructed function, added tests for this matcher

  • Participants
  • Parent commits f7ebbbb

Comments (0)

Files changed (4)

File plugin/frawor/fwc/compiler.vim

     let r=self.getfunstatvar('matchers', s:_r.FWC_intfuncs[mname].matcher)
                 \.'('.a:ldstr.', '.a:strstr
     if len(a:matcher[1])>3
-        for arg in a:matcher[1][2:-2]
-            if type(arg)==type([]) && arg[0] is 'func'
-                let [func; args]=self.getfunc(arg)
-                let r.=', '.func.', ['.join(args, ', ').']'
-            else
-                let r.=', '.string(arg)
-            endif
-        endfor
+        let curargstr=self.argstr()
+        let r.=', '.join(map(a:matcher[1][2:-2],
+                    \        'type(v:val)=='.type([]).'?'.
+                    \           'self.getvar(v:val, 0, curargstr):'.
+                    \           'string(v:val)'),
+                    \    ', ')
     endif
     if self.type is 'check' || self.type is 'filter'
         let r.=', '.a:matcher[1][-1].')'
                 \'\V@.@', escape(this,      '&~\'), 'g'),
                 \'\V@:@', escape(curargstr, '&~\'), 'g')
 endfunction
-"▶1 getvar         :: varcontext[, splitsubs] + self → String
+"▶1 getvar         :: varcontext[, splitsubs[, dotarg]] + self → String
 function s:compiler.getvar(var, ...)
     let r=[]
+    let splitsubs=get(a:000, 0, 0)
     if a:var[0] is 'plugvar'
         let r=['@%@.p.'.a:var[1], a:var[2:]]
     elseif a:var[0] is 'expr'
             let r[0]=s:F.string(r[0])
         endif
     elseif a:var[0] is 'func'
-        let r=[self.getfunc(a:var, 0)]
+        let r=[call(self.getfunc, [a:var, 0]+a:000[1:], self)]
     elseif a:var[0] is 'this'
         let r=[self.argbase, self.subs]
     endif
-    return ((a:0)?(r):(r[0].((len(r)>1)?(self.getsubs(r[1])):(''))))
+    return ((splitsubs)?(r):(r[0].((len(r)>1)?(self.getsubs(r[1])):(''))))
 endfunction
 "▶1 getlvarid      :: varname + self → varname
 function s:compiler.getlvarid(v)

File plugin/frawor/fwc/intfuncs.vim

 " Uses some other function as matcher. Function must accept list or dictionary 
 " and return a list of strings. Additional argument determines what should be 
 " done if function returns list with more then one item
-function s:r.func.matcher(ld, str, Func, args, acceptfirst)
-    let result=call(a:Func, a:args+[a:ld, a:str], {})
+function s:r.func.matcher(ld, str, variants, acceptfirst)
     if a:acceptfirst is 2
-        return result
-    elseif a:acceptfirst || len(result)==1
-        return result[0]
+        return a:variants
+    elseif a:acceptfirst || len(a:variants)==1
+        return a:variants[0]
     else
         return 0
     endif

File test/fwccheck.ok

 plugin/frawor/fwc/compiler:nmatch
 plugin/frawor/fwc/compiler:nmatch
 plugin/frawor/fwc/compiler:nmatch
+plugin/frawor/fwc/compiler:nmatch
 ::: Section <Pipes/Built-in pipes/substitute>
 plugin/frawor/fwc/compiler:typefail
 ::: Section <Pipes/Built-in pipes/bool>

File test/fwctests.dat

 ['in list ~smart',         'filter'], ['a-d'],              0
 ['in list ~smart',         'filter'], ['b-d'],              ['abc-def']
 ['in list ~smart 1',       'filter'], ['a-d'],              ['abc-def']
+\function s:.getmatches(str, filter)
+\    return filter(s:list, a:filter)
+:endfunction
+:let s:filter="len(v:val)>len(a:str)"
+['in list ~func getmatches(. filter) 1', 'filter'], ['a'],    ['abc']
+['in list ~func getmatches(. filter) 1', 'filter'], ['----'], ['abc-def']
+['in list ~func getmatches(. filter) 0', 'filter'], ['----'], 0
 #▶3 substitute
 :let s:regex='\v.'
 :let s:replacement='def'