Commits

ZyX_I committed 65eb4c6

@/fwc/compiler: Removed need of supplying "@#@" argument to nextthrow, added `needcurarg' argument to addthrow

Comments (0)

Files changed (2)

 ------------------------------------------------------------------------------
 3.6. plugin/frawor/checks features                    *frawor-f-frawor/checks*
 
-                                                        *frawor-f-conschecker*
-conschecker : function ({checker})
+conschecker : function ({checker})                      *frawor-f-conschecker*
         Creates a checker function. Constructed function takes exactly one 
         argument: |List| containing checked arguments. For {checker} 
         description see |frawor-t-checker| >
                 " check failed
             endif
 <
-                                                         *frawor-f-consfilter*
-consfilter : function ({filter})
+consfilter : function ({filter})                         *frawor-f-consfilter*
         Like |frawor-f-conschecker|, but for filters, see |frawor-t-filter|.
 
 ------------------------------------------------------------------------------

plugin/frawor/fwc/compiler.vim

     call remove(self.msgs.statuses, -1)
     return self
 endfunction
-"▶1 addthrow       :: msg::String, msgarg, ... + self → self + self
-function s:compiler.addthrow(msg, ...)
+"▶1 addthrow       :: msg::String, msgarg, needcurarg, ... + self → self + self
+function s:compiler.addthrow(msg, needcurarg, ...)
     let args=string(a:msg).', '
-    let curidx=index(a:000, '@#@')
-    if curidx!=-1
-        let args.=join(map(a:000[:(curidx-1)],
-                    \      'string(v:val)')+
-                    \  [self.argstr(1)]+
-                    \  a:000[(curidx+1):], ', ')
+    if a:needcurarg
+        let args.=string(a:1).', '.self.argstr(1).', '.join(a:000[1:], ', ')
     else
         let args.=join(a:000, ', ')
     endif
 endfunction
 "▶1 nextthrow      :: condition::expr, throwargs + self → self + self
 function s:compiler.nextthrow(cond, ...)
-    return call(self.addif(a:cond).addthrow, a:000, self)
+    return call(self.addif(a:cond).addthrow, [a:1, 1]+a:000[1:], self)
 endfunction
 "▶1 addsavemsgs    :: &self
 function s:compiler.addsavemsgs()
     if len(a:dic[1])==1
         let curargstr=self.argstr()
         return self.nextthrow('!empty('.curargstr.')',
-                    \         'keynmatch',a:idx,'@#@', 'keys('.curargstr.')[0]')
+                    \         'keynmatch', a:idx, 'keys('.curargstr.')[0]')
     endif
     let keystr=self.getlvarid('key')
     call self.for(keystr, 'keys('.self.argstr().')')
     if hascheck
         call remove(self.msgs.savevars, -1)
     endif
-    call self.addthrow('keynmatch', a:idx, '@#@', keystr)
+    call self.addthrow('keynmatch', 1, a:idx, keystr)
     call remove(self.subs, -1)
     return self
 endfunction
     return self.getvar(a:str)
 endfunction
 "▶1 compilepipe    :: pipecontext, idx + self → self + self
+let s:pipechecks={
+            \'substitute': ['intfunc', 'type',   [type('')]],
+            \      'take': ['intfunc', 'type',   [type('')]],
+            \       'run': ['intfunc', 'isfunc', 0         ],
+            \      'earg': ['intfunc', 'type',   [type('')]],
+            \     'tuple': ['intfunc', 'type',   [type([])]],
+            \      'list': ['intfunc', 'type',   [type([])]],
+            \      'dict': ['intfunc', 'type',   [type({})]],
+        \}
 function s:compiler.compilepipe(pipe, idx)
     let curargstr=self.argstr()
     "▶2 `func' pipe
     "▶2 Built-in pipes
     elseif a:pipe[1][0] is 'intfunc'
         let desc=a:pipe[1][1:]
-        if a:0 && has_key(s:pipechecks, desc[0])
+        if has_key(s:pipechecks, desc[0])
             call self.compilecheck(['check', s:pipechecks[desc[0]]], a:idx)
         endif
         "▶3 `func', `eval'
                         \.let(curargstr, 'call('.curargstr.', '.
                         \                          self.getvar(desc[1]).', {})')
                     \.up().catch()
-                        \.addthrow('runfail', a:idx, '@#@', 'v:exception')
+                        \.addthrow('runfail', 1, a:idx, 'v:exception')
         "▶3 `earg'
         elseif desc[0] is 'earg'
             call self.try()
                         \.let(curargstr, 'eval('.curargstr.')')
                     \.up().catch()
-                        \.addthrow('evalfail', a:idx, '@#@', 'v:exception')
+                        \.addthrow('evalfail', 1, a:idx, 'v:exception')
         "▶3 `tuple'
         elseif desc[0] is 'tuple'
             call self.nextthrow('len('.curargstr.')!='.len(desc[1]),
-                        \       'invlstlen', a:idx, '@#@', len(desc[1]),
+                        \       'invlstlen', a:idx, len(desc[1]),
                         \                    'len('.curargstr.')')
                         \.addtuple(desc, a:idx, 'pipe')
         "▶3 `list'
                             \                              self.getvar(desc[1]),
                             \                              curargstr))
                             \.nextthrow(matchstr.' is 0',
-                            \           'nmatch', a:idx, '@#@', curargstr)
+                            \           'nmatch', a:idx, curargstr)
                             \.let(curargstr, matchstr)
             endif
         "▶3 `take'
             call self.addtypecond([type('')], a:idx)
                         \.let(matchstr, self.getmatcher(desc[2], varstr,
                         \                               curargstr))
-                        \.nextthrow(matchstr.' is 0',
-                        \           'nmatch', a:idx, '@#@', curargstr)
+                        \.nextthrow(matchstr.' is 0', 'nmatch',a:idx,curargstr)
                         \.let(curargstr, varstr.'['.matchstr.']')
         "▶3 `substitute'
         elseif desc[0] is 'substitute'
                     \.let(prevdirstr, dirnamestr)
                     \.let(dirnamestr, '@%@.os.path.dirname('.dirnamestr.')')
                 \.up()
-                \.nextthrow('!'.foundstr, 'nowrite', a:idx, '@#@', curargstr)
+                \.nextthrow('!'.foundstr, 'nowrite', a:idx, curargstr)
             \.up().up()
     return self
 endfunction
     if len(a:types)>=2
         call self.nextthrow('index('.string(a:types).', '.
                     \            'type('.curargstr.'))==-1',
-                    \       'typesfail', a:idx, '@#@',
-                    \                    string(join(typenames, '/')),
+                    \       'typesfail', a:idx, string(join(typenames, '/')),
                     \                    '@%@.m.types[type('.curargstr.')]')
     elseif len(a:types)==1
         call self.nextthrow('type('.curargstr.')!='.a:types[0],
-                    \       'typefail', a:idx, '@#@', string(typenames[0]),
+                    \       'typefail', a:idx, string(typenames[0]),
                     \                   '@%@.m.types[type('.curargstr.')]')
     else
         call self._throw('notypes')
         endwhile
         call remove(self.l, 0, -1)
         call self.add('if', 0, [])
-        call self.nextthrow('!('.join(conditions, ' || ').')',
-                    \       'notfail', a:idx, '@#@')
+        call self.nextthrow('!('.join(conditions, ' || ').')', 'notfail', a:idx)
         call remove(self.l, 1, 3)
     endif
     return self
     "▶2 `func' check
     if check[0] is 'func'
         call self.nextthrow(self.getfunc(check, 0, curargstr).' is 0',
-                    \       'funcfail', a:idx, '@#@')
+                    \       'funcfail', a:idx)
     "▶2 `expr' check
     elseif check[0] is 'expr'
         call self.nextthrow(self.getexpr(check, curargstr).' is 0',
-                    \       'exprfail', a:idx, '@#@')
+                    \       'exprfail', a:idx)
     "▶2 `intfunc' check
     else
         let desc=check[1:]
         "▶3 `func'
         if desc[0] is 'func'
             call self.nextthrow(self.getfunc(desc[1], 0, curargstr).' is 0',
-                        \       'funcfail', a:idx, '@#@')
+                        \       'funcfail', a:idx)
         "▶3 `eval'
         elseif desc[0] is 'eval'
             call self.nextthrow(self.getexpr(desc[1], curargstr).' is 0',
-                        \       'exprfail', a:idx, '@#@')
+                        \       'exprfail', a:idx)
         "▶3 `not'
         elseif desc[0] is 'not'
             call self.try()
                         \.throw("'NOTFAIL'")
                     \.catch(s:cfreg).up()
                     \.catch('\v^NOTFAIL$')
-                        \.addthrow('notfail', a:idx, '@#@')
+                        \.addthrow('notfail', 1, a:idx)
                         \.optnot(a:idx)
         "▶3 `either'
         elseif desc[0] is 'either'
                 let i+=1
             endfor
             call self.addif(sucstr).addrestmsgs().up().popms()
-                        \.addif().addthrow('eitherfail',a:idx,'@#@').up().up()
+                        \.addif().addthrow('eitherfail', 1, a:idx).up().up()
         "▶3 `tuple'
         elseif desc[0] is 'tuple'
             call self.addtypecond([type([])], a:idx)
                         \.nextthrow('len('.curargstr.')!='.len(desc[1]),
-                        \           'invlstlen', a:idx, '@#@', len(desc[1]),
+                        \           'invlstlen', a:idx, len(desc[1]),
                         \                        'len('.curargstr.')')
                         \.addtuple(desc, a:idx, 'check')
         "▶3 `list'
         elseif desc[0] is 'in'
             call self.nextthrow('index('.self.getvar(desc[1]).', '.
                         \                curargstr.')==-1',
-                        \       'ninlist', a:idx, '@#@')
+                        \       'ninlist', a:idx)
         "▶3 `key'
         elseif desc[0] is 'key'
             call self.addtypecond([type('')], a:idx)
                         \.nextthrow('!has_key('.self.getvar(desc[1]).', '.
                         \                       curargstr.')',
-                        \           'nindict', a:idx, '@#@', curargstr)
+                        \           'nindict', a:idx, curargstr)
         "▶3 `haskey'
         elseif desc[0] is 'haskey'
             call self.addtypecond([type({})], a:idx)
                             \          string('!has_key('.curargstr.', '.
                             \                           'v:val)').')'
                 call self.nextthrow('!empty('.absentkeys.')',
-                            \       'keysmis', a:idx, '@#@',
+                            \       'keysmis', a:idx,
                             \                  'join('.absentkeys.', ", ")')
             elseif !empty(desc[1])
                 let keystr=((type(desc[1][0])==type(''))?
                             \       (s:F.string(desc[1][0])):
                             \       (self.getvar(desc[1][0])))
                 call self.nextthrow('!has_key('.curargstr.', '.keystr.')',
-                            \       'keymis', a:idx, '@#@', keystr)
+                            \       'keymis', a:idx, keystr)
             endif
         "▶3 `range'
         elseif desc[0] is 'range'
             endif
             "▶4 Add condition to result
             if !empty(cond)
-                call self.nextthrow(cond, 'nrange', a:idx, '@#@',
+                call self.nextthrow(cond, 'nrange', a:idx,
                             \                       'string('.curargstr.')',
                             \                       'string('.range[0].')',
                             \                       'string('.range[1].')')
                         \(self.getvar(desc[1][1])))
             call self.addtypecond([type('')], a:idx)
                         \.nextthrow(curargstr.'!~#'.regex,
-                        \           'nregmatch',a:idx,'@#@', curargstr, regex)
+                        \           'nregmatch', a:idx, curargstr, regex)
         "▶3 `path'
         elseif desc[0] is 'path'
             call self.addtypecond([type('')], a:idx)
                 let spec=spec[1:]
                 if spec[0] is 'w'
                     call self.nextthrow('filewritable('.curargstr.')!=2',
-                                \       'nwrite', a:idx, '@#@', curargstr)
+                                \       'nwrite', a:idx, curargstr)
                     let spec=spec[1:]
                 elseif spec[0] is 'W'
                     call self.nextthrow('filewritable('.curargstr.')!=2 &&'.
                                 \       '|| filewritable('.
                                 \               '@%@.os.path.dirname('.
                                 \                        curargstr.'))!=2)',
-                                \      'nowrite', a:idx, '@#@', curargstr)
+                                \      'nowrite', a:idx, curargstr)
                     let spec=spec[1:]
                 elseif spec[0] is 'p'
                     call self.addpathp(a:idx)
                                 \.nextthrow('!@%@.os.path.isdir('.
                                 \                             curargstr.')',
-                                \           'isdir', a:idx, '@#@', curargstr)
+                                \           'isdir', a:idx, curargstr)
                     let spec=spec[1:]
                 else
                     call self.nextthrow('!@%@.os.path.isdir('.curargstr.')',
-                                \       'isdir', a:idx, '@#@', curargstr)
+                                \       'isdir', a:idx, curargstr)
                 endif
             else
                 let fileonly=0
                 if fileonly
                     if spec[0] is 'r'
                         call self.nextthrow('!filereadable('.curargstr.')',
-                                    \       'nread', a:idx, '@#@', curargstr)
+                                    \       'nread', a:idx, curargstr)
                         let spec=spec[1:]
                     elseif spec[-1:] isnot 'x'
                         call self.nextthrow('@%@.os.path.isdir('.
                                     \                         curargstr.')',
-                                    \       'isfile', a:idx, '@#@', curargstr)
+                                    \       'isfile', a:idx, curargstr)
                     endif
                 endif
                 if spec[0] is 'w'
                     call self.nextthrow('!filewritable('.curargstr.')',
-                                \       'nwrite', a:idx, '@#@', curargstr)
+                                \       'nwrite', a:idx, curargstr)
                     let spec=spec[1:]
                 elseif spec[0] is 'W'
                     call self.nextthrow('!filewritable('.curargstr.') &&'.
                                 \       '|| filewritable('.
                                 \               '@%@.os.path.dirname('.
                                 \                        curargstr.'))!=2)',
-                                \      'nowrite', a:idx, '@#@', curargstr)
+                                \      'nowrite', a:idx, curargstr)
                     let spec=spec[1:]
                 elseif spec[0] is 'p'
                     call self.addpathp(a:idx)
                 endif
                 if spec is 'x'
                     call self.nextthrow('!executable('.curargstr.')',
-                                \       'nexecable', a:idx, '@#@', curargstr)
+                                \       'nexecable', a:idx, curargstr)
                 endif
             endif
         "▶3 `type'
                 call self.addtypecond([2], a:idx)
                 call self.nextthrow('!exists('.string('*'.curargstr).') ||'.
                             \                       frefpref.' is "s:"',
-                            \       'nfunc', a:idx, '@#@',
+                            \       'nfunc', a:idx,
                             \                'string('.curargstr.')[10:-3]')
             else
                 call self.nextthrow('!((type('.curargstr.')==2 && '.
                             \                    '%(s@!\w:)?\w+|'.
                             \                    '%(<SNR>\w+))$'''.
                             \            '&& exists("*".'.curargstr.')))',
-                            \       'nsfunc', a:idx, '@#@',
-                            \                 'string('.curargstr.')')
+                            \       'nsfunc', a:idx, 'string('.curargstr.')')
             endif
         "▶3 `isreg'
         elseif desc[0] is 'isreg'
             call self.addtypecond([type('')], a:idx)
                         \.try().call('matchstr("", '.curargstr.')').up()
-                        \.catch().addthrow('nreg', a:idx, '@#@', curargstr,
+                        \.catch().addthrow('nreg', 1, a:idx, curargstr,
                         \                  'v:exception')
         "▶3 `bool'
         elseif desc[0] is 'bool'
             call self.nextthrow('index([0, 1], '.curargstr.')==-1',
-                        \       'nbool', a:idx,'@#@', 'string('.curargstr.')')
+                        \       'nbool', a:idx, 'string('.curargstr.')')
         "▶3 `is'
         elseif desc[0] is 'is'
             let var=self.getvar(desc[1])
             call self.nextthrow(curargstr.' isnot '.var,
-                        \       'isnot', a:idx, '@#@', var,
+                        \       'isnot', a:idx, var,
                         \                'string('.curargstr.')')
         "▶3 `value'
         elseif desc[0] is 'value'
     return self
 endfunction
 "▶1 compilearg     :: argcontext, idx[, defcomptype] + self → self + self
-let s:pipechecks={
-            \'substitute': ['intfunc', 'type',   [type('')]],
-            \      'take': ['intfunc', 'type',   [type('')]],
-            \       'run': ['intfunc', 'isfunc', 0         ],
-            \      'earg': ['intfunc', 'type',   [type('')]],
-            \     'tuple': ['intfunc', 'type',   [type([])]],
-            \      'list': ['intfunc', 'type',   [type([])]],
-            \      'dict': ['intfunc', 'type',   [type({})]],
-        \}
 function s:compiler.compilearg(argcon, idx, ...)
     let type=get(a:000, 0, self.type)
     if a:argcon[0] is 'arg'
     let msg=[]
     let i=0
     for proc in arg
-        if proc[0] is 'pipe' && proc[1][0] is 'intfunc'
-                    \&& has_key(s:pipechecks, proc[1][1])
-            call self.compilecheck(['check', s:pipechecks[proc[1][1]]],
-                        \          a:idx.'(pipe)')
-        elseif self.type is 'filter' && proc[0] is 'intfunc'
-                    \&& has_key(s:pipechecks, proc[1])
-            call self.compilecheck(['check', s:pipechecks[proc[1]]],
-                        \          a:idx.'(pipe)')
-        endif
         let compargs=[proc, a:idx.'.'.i]
         let comptype=proc[0]
         if comptype is 'intfunc'
     let largsstr=self.getlvarid('largs')
     call self.let(largsstr, 'len('.self.argstr(0, self.subs[:-2]).')')
     if a:maximum==a:minimum
-        call self.nextthrow(largsstr.' isnot '.a:maximum,
-                    \       'invlen', a:minimum, largsstr)
+        call self.addif(largsstr.' isnot '.a:maximum)
+                    \.addthrow('invlen', 0, a:minimum, largsstr)
     else
         if a:minimum>0
-            call self.nextthrow(largsstr.'<'.a:minimum,
-                        \       'tooshort', a:minimum, largsstr)
+            call self.addif(largsstr.'<'.a:minimum)
+                        \.addthrow('tooshort', 0, a:minimum, largsstr)
         endif
         if a:maximum!=-1
-            call self.nextthrow(largsstr.'>'.a:maximum,
-                        \       'toolong',  a:maximum, largsstr)
+            call self.addif(largsstr.'>'.a:maximum)
+                        \.addthrow('toolong', 0,  a:maximum, largsstr)
         endif
     endif
     return self