Commits

ZyX_I committed 0512210

@/fwc: Made conschecker and consfilter feauters pass plugdict.g dictionary to fwc_compile

Comments (0)

Files changed (5)

 
 version :: [ Integer ]                                      *frawor-t-version*
         List of integers, all integers must be nonnegative.
+
 plugdict :: {}                                             *frawor-t-plugdict*
         Dictionary which describes plugin. It has the following keys:
         Key           Description ~
                       2 - plugin is loaded
         g             Dictionary with global variables (last argument to 
                       |FraworRegister()|).
+
 checker :: Function                                         *frawor-t-checker*
         If checker is a function reference, then in order to check arguments 
         this function will be called with an argument list as an only 
         failed when this function returns 0.
         If checker is a string, then it is passed to |frawor-f-fwc_compile| 
         with "check" as a second argument, then generated function is 
-        returned. Note that script variables won't be accessible here. Use FWC 
-        decorator (|frawor-de-FWC|) if you want access to your script 
-        variables.
+        returned. Consider using FWC decorator (|frawor-de-FWC|) instead.
+
 filter :: Function                                           *frawor-t-filter*
         If filter is a function reference, then in order to filter arguments 
         this function will be called with an argument list as an only 
         argument list. Function should return 0 if some error occured.
         If filter is a string, then it is passed to |frawor-f-fwc_compile| 
         with "filter" as a second argument, then generated function is 
-        returned. Note that script variables won't be accessible here. Use FWC 
-        decorator (|frawor-de-FWC|) if you want access to your script 
-        variables.
+        returned. Consider using FWC decorator (|frawor-de-FWC|) instead.
+
 option :: {}                                                 *frawor-t-option*
         Dictionary which describes option. It has the following keys:
         Key         Description ~

plugin/frawor/checks.vim

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

plugin/frawor/fwc/compiler.vim

             \              'already defined',
             \  'umatcher': 'Unknown matcher: %s',
             \    'ucheck': 'Unknown check: %s',
+            \  'onlyforb': 'Cannot use {%s} section '.
+            \              'when option `only'' is active',
         \}
 call extend(s:_messages, map({
             \'decargnlst': 'decorator argument is not a List',
 function s:compiler.getmatcher(matcher, ldstr, strstr)
     let mname=a:matcher[1][1]
     if !has_key(s:_r.FWC_intfuncs[mname], 'matcher')
-        call self._throw('umatcher', mname)
+        call s:_f.throw('umatcher', mname)
     endif
     let r=self.getfunstatvar('matchers', s:_r.FWC_intfuncs[mname].matcher)
                 \.'('.a:ldstr.', '.a:strstr
                     \       'typefail', a:idx, string(typenames[0]),
                     \                   '@%@.m.types[type('.curargstr.')]')
     else
-        call self._throw('notypes')
+        call s:_f.throw('notypes')
     endif
     return self
 endfunction
         let desc=check[1:]
         let dname=desc[0]
         if !has_key(s:_r.FWC_intfuncs[dname], 'check')
-            call self._throw('ucheck', dname)
+            call s:_f.throw('ucheck', dname)
         endif
         call call(s:_r.FWC_intfuncs[dname].check, [desc, a:idx, 'check'], self)
         if has_key(s:_r.FWC_intfuncs[dname], 'optimize')
 "▶1 compadescr     :: adescr[, idx[, purgemax]] + self → self + self
 function s:compiler.compadescr(adescr, ...)
     let purgemax=get(a:000, 1, 0)
-    "▶2 Length checks
+    "▶2 Length checks, lagsstr and nextsub variables
     if !empty(self.subs)
+        let largsstr=self.getlargsstr()
         if !has_key(a:adescr, 'minimum')
             call s:F.getlenrange(a:adescr)
         endif
                         \                               (a:adescr.maximum)))
             let a:adescr.checkedfor=1
         endif
-    endif
-    "▲2
-    if !empty(self.subs)
         let nextsub=copy(self.subs[-1])
     endif
     "▶2 `arg' key
     endif
     "▶2 Quit if no more keys are present or if we are checking the only argument
     if empty(self.subs) || empty(a:adescr)
-                \|| !(has_key(a:adescr, 'optional')
-                \  || has_key(a:adescr, 'next')
-                \  || has_key(a:adescr, 'prefixes')
-                \  || has_key(a:adescr, 'actions'))
+                \|| empty(filter(copy(s:_r.FWC_topconstructs._order),
+                \         'has_key(a:adescr, v:val)'))
         return self
     endif
     "▲2
         call self.let(caidxstr, oldsub)
     endif
     let self.subs[-1]=[caidxstr]
-    let largsstr=self.getlargsstr()
     let idx=get(a:000, 0, '')
     "▶2 Following keys (optional, prefixes, next, actions)
     for key in s:_r.FWC_topconstructs._order
         if has_key(a:adescr, key)
+            if self.o.only && !get(s:_r.FWC_topconstructs[key], 'allowonly', 0)
+                call s:_f.throw('onlyforb', key)
+            endif
             let [newnextsub, addedsavemsgs]=
                         \call(s:_r.FWC_topconstructs[key].compile,
                         \     [a:adescr, idx, caidxstr, largsstr, purgemax,
             \})
     let tree=s:_r.fwc_parser(a:string, a:type)[1:]
     call extend(t, s:compiler, 'error')
-    let t._throw=s:_f.throw
     "▲2
     if a:doreturn is 1
         let t.failcal=['return', 0]
         if !t.o.only
             call add(t.subs, 0)
         endif
-        if t.type is 'check' || t.type is 'filter'
-            call t.compadescr(tree[0])
-        else
-        endif
-        call t.up().finally()
+        call t.compadescr(tree[0])
+                \.up().finally()
                     \.for('@$@targs', '@$@messages')
                         \.call('call(@%@.F.warn, @$@targs, {})').up()
                     \.for('@$@targs', '@$@pmessages')
                         \.call('call(@%@.p._f.warn, @$@targs, {})').up()
-                \.up()
-                \.up()
+                \.up().up()
     else
-        call t.let('@@@', '[]')
+        call t.let('@-@', '[]')
     endif
     if a:doreturn is 1
         if t.type is 'check'
         elseif t.type is 'filter'
             call t.return('@@@')
         else
-            call t.return('@@@')
+            call t.return('@-@')
         endif
     endif
     return [t.o, t.tolist()]
 endfunction
-"▶1 createvars     :: plugdict → id + s:lastid, s:vars
-function s:F.createvars(plugdict)
+"▶1 createvars     :: gdict → id + s:lastid, s:vars
+function s:F.createvars(gdict)
     return {
                 \ 'F': {'warn': s:_f.warn, 'throw': s:_f.throw},
-                \ 'p': a:plugdict.g,
+                \ 'p': a:gdict,
                 \ 'm': {'types': s:_messages._types},
                 \'os': s:_r.os,
             \}
 endfunction
-"▶1 makefunc       :: {f}, String, type → Fref + s:lastid, s:vars
+"▶1 makefunc       :: {f}, String, type[, gdict] → Fref + s:lastid, s:vars
 let s:lastid=0
 let s:vars={}
-function s:F.makefunc(plugdict, fdict, string, type)
+function s:F.makefunc(plugdict, fdict, string, type, ...)
     let d={}
     let id=printf('%s%X', a:type, s:lastid)
     let s:lastid+=1
-    let s:vars[id]=s:F.createvars(a:plugdict)
+    let s:vars[id]=s:F.createvars(get(a:000, 0, a:plugdict.g))
     call add(a:fdict.ids, id)
     let [opts, lines]=s:F.compstr(s:vars[id], a:string, a:type, 1)
     if opts.only
         call insert(lines, 'let d={}')
     endif
     execute "function d.f(args)\n    ".
-                \substitute(substitute(substitute(
+                \substitute(substitute(substitute(substitute(
                 \join(lines, "\n    "),
                 \'@@@', ((opts.only)?('d.arg'):
                 \                    ('a:args')), 'g'),
                 \'@%@', 's:vars.'.id,    'g'),
+                \'@-@', 'variants',      'g'),
                 \'@$@', '',              'g')."\n".
             \"endfunction"
     return d.f
         call s:_f.throw('invtype', a:fname, a:plugdict.id, string(a:arg[1]))
     endif
     "▲2
-    let vars=s:F.createvars(a:plugdict)
+    let vars=s:F.createvars(a:plugdict.g)
     let a='"FWCfail", '.self.string(a:fname).', '.self.string(a:plugdict.id)
     let [opts, lines]=s:F.compstr(vars, a:arg[0], a:arg[1], a)
     if opts.only

plugin/frawor/fwc/parser.vim

     "▶2 optional, prefixes, actions, next
     let c=self.readc()
     let type=get(self.l, 0, '')
-    if type is 'top' || type is 'optional'
-                \|| (type is 'action' && len(self.l)>1)
+    if !self.o.only && (type is 'top' || type is 'optional'
+                \    || type is 'action')
         if has_key(s:_r.FWC_topconstructs._chars, c)
             return call(s:_r.FWC_topconstructs[s:_r.FWC_topconstructs._chars[c]]
                         \.scan, [], self)

plugin/frawor/fwc/topconstructs.vim

 "▶1 _order
 let s:r._order=['optional', 'prefixes', 'next', 'actions']
 let s:r._chars={}
-call map(filter(copy(s:r), 'v:key[0] isnot "_"'),
+call map(filter(copy(s:r), 'v:key[0] isnot "_" && has_key(v:val, "char")'),
             \'extend(s:r._chars, {v:val.char : v:key})')
 "▶1 Register resource
 call s:_f.postresource('FWC_topconstructs', s:r, 1)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.