Commits

ZyX_I committed bae621b

@/fwc: Added `value' check and pipe

Comments (0)

Files changed (4)

plugin/frawor/fwc/compiler.vim

     call remove(self.subs, -1)
     call self.up().close()
 endfunction
+"▶1 witharg        :: argbase, [subscript] + self → self + self
+function s:compiler.witharg(argbase, subscripts)
+    call add(self.preva, [self.argbase, self.subs])
+    let self.argbase=a:argbase
+    let self.subs=a:subscripts
+    return self
+endfunction
+"▶1 without        :: &self
+function s:compiler.without()
+    let [self.argbase, self.subs]=remove(self.preva, -1)
+    return self
+endfunction
 "▶1 adddict        :: dicdesc, idx, defaultArgType + self → self + self
 function s:compiler.adddict(dic, idx, default)
     if len(a:dic[1])==1
                 call self.addsavemsgs(msglenstr, pmsglenstr)
             endif
             let hascheck=1
-            let savedargbase=self.argbase
-            let self.argbase=keystr
-            let savedsubs=remove(self.subs, 0, -1)
             call self.add('try').deeper()
                             \.add('let '.foundstr.'=0')
+                            \.witharg(keystr, [])
                             \.compilearg(check[1], a:idx.'.'.i.'(key)', 'check')
-            let self.argbase=savedargbase
-            let self.subs+=savedsubs
-            call self.add('let '.foundstr.'=1')
+                            \.without()
+                            \.add('let '.foundstr.'=1')
                             \.compilearg(check[2],a:idx.'.'.i.'(val)',a:default)
                             \.up()
                         \.add('catch /^CHECKFAILED$/').deeper()
         "▶3 `bool'
         elseif desc[0] is 'bool'
             call self.add('let '.curargstr.'=!empty('.curargstr.')')
+        "▶3 `value'
+        elseif desc[0] is 'value'
+            call self.witharg(self.getvar(desc[1]), [])
+                        \.compilearg(desc[2], a:idx.'(value)', 'pipe')
+                        \.without()
         "▲3
         else
             call self.compilecheck(['check', a:pipe[1]], a:idx)
                 call self.nextthrow(curargstr.' isnot '.var,
                             \       'isnot', idx, '@#@', var,
                             \                'string('.curargstr.')')
+            "▶3 `value'
+            elseif desc[0] is 'value'
+                if addedcond
+                    call self.close()
+                    let addedcond=0
+                endif
+                call self.witharg(self.getvar(desc[1]), [])
+                            \.compilearg(desc[2], idx.'(value)', 'check')
+                            \.without()
             "▶3 `_', `any'
             elseif desc[0] is '_' || desc[0] is 'any'
                 " Just do nothing here
                 \   'vids': {},
                 \'argbase': '@@@',
                 \  'pmsgs': [],
+                \  'preva': [],
             \})
     call extend(t, s:compiler, 'error')
     let t.throw=s:_f.throw

plugin/frawor/fwc/parser.vim

 "▶3 pipe.bool
 " Transforms {argument} to 0 if it is empty and to 1 otherwise
 let s:args.pipe.bool=[]
+"▶3 pipe.value
+" Overrides current value
+let s:args.pipe.value=['var', 'arg']
 "▶2 check
 let s:args.check={}
 "▶3 check.func
 "▶3 check.is
 " Checks whether {argument} is {var}
 let s:args.check.is=['var']
+"▶3 check.value
+" Overrides current value
+let s:args.check.value=['var', 'arg']
 "▶3 check._, check.any
 " Unconditionally accepts {argument}
 let s:args.check._=[]
 plugin/frawor/fwc/compiler:nsfunc
 plugin/frawor/fwc/compiler:nmatch
 plugin/frawor/fwc/compiler:typefail
+1
 ::: Section <Pipes/Built-in pipes/dict>
 plugin/frawor/fwc/compiler:keynmatch
 plugin/frawor/fwc/compiler:keynmatch
 plugin/frawor/fwc/compiler:typefail
 plugin/frawor/fwc/compiler:notfail
 plugin/frawor/fwc/compiler:isnot
+plugin/frawor/fwc/compiler:isnot
 ::: Section <Checks/Built-in checks/in>
 plugin/frawor/fwc/compiler:ninlist
 plugin/frawor/fwc/compiler:ninlist

test/fwctests.dat

 ['take ={"abc": 1} start', 'filter'], ['a'],                [1]
 ['take ={"abc": 1} start', 'filter'], ['b'],                0
 ['take ={"abc": 1} start', 'filter'], [0],                  0
+:let s:notbool=2
+['value notbool bool',     'filter'], [0],                  [0]
+:echom s:notbool
 #▶3 dict
 ['dict {abc bool}',        'filter'], [{'abc': {}}],        [{'abc': 0}]
 ['dict {abc bool}',        'filter'], [{'ab': {}}],         0
 ['not bool',        'check'], [2],                  1
 ['is =2',           'check'], [2],                  1
 ['is =2',           'check'], [[]],                 0
+['value "a" is "a"','check'], [[]],                 1
+['value "a" is "b"','check'], [[]],                 0
 ['_',               'check'], [[[[]]]],             1
 ['any',             'check'], [[[[]]]],             1
 #▶3 in