Commits

ZyX_I committed 4f7b18e

@/checks: Added possibility to use FWC to generate checker functions
@/fwc: Fixed messages, added messages tests

  • Participants
  • Parent commits 5de9704

Comments (0)

Files changed (6)

File plugin/frawor/checks.vim

             call s:_f.throw('chkncall', a:plugdict.id)
         endif
         return a:Chk
+    elseif type(a:Chk)==type('')
+        return s:_f.fwc_compile(a:Chk, 'check')
     else
         call s:_f.throw('uchecker', a:plugdict.id)
     endif
             call s:_f.throw('filncall', a:plugdict.id)
         endif
         return a:Fil
+    elseif type(a:Fil)==type('')
+        return s:_f.fwc_compile(a:Fil, 'filter')
     else
         call s:_f.throw('ufilter', a:plugdict.id)
     endif

File plugin/frawor/fwc/compiler.vim

         let args=map(args[:(curidx-1)], 'string(v:val)')+[self.argstr(1)]+
                     \args[(curidx+1):]
     endif
+    if !empty(self.pmsgs)
+        call self.add('call add(@$@pmessages, ['.self.pmsgs[-1].'])')
+    endif
     return self.add('call add(@$@messages, ['.string(a:msg).', '.
                 \                             join(args, ', ').'])',
                 \   'throw "CHECKFAILED"').up()
 endfunction
 "▶1 compilemsg     :: msgcontext, _ + self → self + self
 function s:compiler.compilemsg(msg, idx)
-    let msg=[a:msg[1]]
+    let msg=[]
+    let curargstr=self.argstr()
     for msgarg in a:msg[2:]
         if msgarg[0] is 'curval'
-            call add(msg, self.argstr())
+            call add(msg, curargstr)
         elseif msgarg[0] is 'curarg'
-            call add(msg, self.subs[0])
+            call add(msg, string(curargstr))
         else
-            call add(msg, substitute(s:compiler.getvar(msgarg), '@#@',
-                        \            escape(self.argstr(), '\&~'), 'g'))
+            call add(msg, substitute(self.getvar(msgarg), '@#@',
+                        \            escape(curargstr, '\&~'), 'g'))
         endif
     endfor
+    let msgstr=string(a:msg[1]).', '.join(msg, ', ')
+    call add(self.pmsgs, msgstr)
     return self
 endfunction
 "▶1 compilestring  :: {string} + self → self + self
     else
         let arg=a:argcon
     endif
+    let pmsgnum=len(self.pmsgs)
     let check=['check']
     let msg=[]
     let i=0
         call self.compilecheck(check, a:idx.'.'.(i+1-len(check)))
         call remove(check, 1, -1)
     endif
+    if len(self.pmsgs)>pmsgnum
+        call remove(self.pmsgs, pmsgnum, -1)
+    endif
     return self
 endfunction
 "▶1 getlenrange    :: adescr → (minlen, maxlen) + adescr
     let a:adescr.maximum=maximum
     return [minimum, maximum]
 endfunction
-"▶1 addlencheck   :: minlen, maxlen + self → self + self
+"▶1 addlencheck    :: minlen, maxlen + self → self + self
 function s:compiler.addlencheck(minimum, maximum)
     let largsstr=self.getlvarid('largs')
     call self.add('let '.largsstr.'=len('.self.argstr(0, self.subs[:-2]).')')
                 \   'vars': a:vars,
                 \   'vids': {},
                 \'argbase': '@@@',
+                \  'pmsgs': [],
             \})
     call extend(t, s:compiler, 'error')
     let t.throw=s:_f.throw
     endif
     return t.tolstofstr()
 endfunction
+"▶1 createvars     :: plugdict → id + s:lastid, s:vars
+function s:F.createvars(plugdict)
+    return {
+                \ 'F': {'warn': s:_f.warn, 'matchers': s:F.matchers},
+                \ 'p': a:plugdict.g,
+                \ 'm': {'types': s:_messages._types},
+                \'os': s:_r.os,
+            \}
+endfunction
 "▶1 makefunc       :: {f}, String, type → Fref + s:lastid, s:vars
 let s:lastid=0
 let s:vars={}
     let d={}
     let id=printf('%s%X', a:type, s:lastid)
     let s:lastid+=1
-    let s:vars[id]={
-                \ 'F': {'warn': s:_f.warn, 'matchers': s:F.matchers},
-                \ 'p': a:plugdict.g,
-                \ 'm': {'types': s:_messages._types},
-                \'os': s:_r.os,
-            \}
+    let s:vars[id]=s:F.createvars(a:plugdict)
     call add(a:fdict.ids, id)
     execute "function d.f(args)\n    ".
                 \substitute(substitute(substitute(
                 \join(s:F.compilestr(s:vars[id], a:string, a:type), "\n    "),
-                \'@@@', ((a:type is 'completer')?
+                \'@@@', ((a:type is 'complete')?
                 \           ('variants'):
                 \           ('a:args')), 'g'),
                 \'@%@', 's:vars.'.id,    'g'),

File plugin/frawor/fwc/parser.vim

                 elseif c is '%'
                     call self.addcon('curarg').conclose()
                 else
-                    call self.getvar()
+                    call self.ungetc(c).getvar()
                 endif
             endwhile
         else

File test/fwccheck.ok

 plugin/frawor/fwc/compiler:exprfail
 plugin/frawor/fwc/compiler:exprfail
 plugin/frawor/fwc/compiler:exprfail
+::: Section <Messages>
+plugin/frawor/fwc/compiler:nbool
+Frawor:plugin/fwccheck:str:a:args[0]<
+plugin/frawor/fwc/compiler:nreg
+Frawor:plugin/fwccheck:str:\v(<
+plugin/frawor/fwc/compiler:nbool
+Frawor:plugin/fwccheck:str:0<
+plugin/frawor/fwc/compiler:nbool
+Frawor:plugin/fwccheck:str:1<
 <<< messages

File test/fwctests.dat

 ['?=!empty(@.@)?=(type(@.@)==type(""))?=(@.@[0]=="a")', 'check'], ['bac'], 0
 #▶2 Checks and pipes composition
 #▶1 Messages
+:let s:_messages={}
+:let s:_messages.str='%s<'
+['#str(%) bool',                         'check'], [2],        0
+['#str(%) bool (type "" #str(.) isreg)', 'check'], [1, '\v('], 0
+['#str(*$"type"(@)) bool',               'check'], [2],        0
+['#str(*$"type"(@)) bool',               'check'], [""],       0
 # vim: cms=#%s fmr=▶,▲
     return ""
 endfunction
 function PurgeFrawor(str)
+    if a:str[-1:] is '<'
+        return a:str
+    endif
     return substitute(a:str,
                 \'^Frawor:\(\%(\\.\|[^:]\)\+:\%(\\.\|[^:]\)\+\):.*', '\1', '')
 endfunction