Commits

ZyX_I committed 3ad6408

@/fwc: Added `if pipe

Comments (0)

Files changed (4)

plugin/frawor/fwc/compiler.vim

         "▶3 `func', `eval'
         if desc[0] is 'func' || desc[0] is 'eval'
             call self.compilepipe(desc, a:idx)
+        "▶3 `if'
+        elseif desc[0] is 'if'
+            let msglenstr=self.getlvarid('msglen')
+            let pmsglenstr=self.getlvarid('pmsglen')
+            let condstr=self.getlvarid('cond')
+            call self.add('try').deeper()
+                        \.addsavemsgs(msglenstr, pmsglenstr)
+                        \.compilearg(desc[1], a:idx.'(cond)', 'check')
+                        \.add('let '.condstr.'=1').up()
+                    \.add('catch /^CHECKFAILED$/')
+                        \.deeper('let '.condstr.'=0')
+                    \.up().close()
+                    \.addrestmsgs(msglenstr, pmsglenstr)
+            if len(desc[2])>1
+                call self.nextcond(condstr).compilearg(desc[2], a:idx.'(if)',
+                            \                          'pipe').up()
+                if len(desc[3])>1
+                    call self.nextcond().compilearg(desc[3], a:idx.'(else)',
+                                \                   'pipe').up()
+                endif
+            else
+                call self.nextcond('!'.condstr).compilearg(desc[3],
+                            \                              a:idx.'(else)',
+                            \                              'pipe').up()
+            endif
+            call self.close()
         "▶3 `run'
         elseif desc[0] is 'run'
             call self.add('try')

plugin/frawor/fwc/parser.vim

 "▶3 pipe.eval
 " Replaces {argument} with the result of evaluating {expr}
 let s:args.pipe.eval=['expr']
+"▶3 pipe.if
+" Processes argument if condition is met. Third argument describes the `else' 
+" clause.
+let s:args.pipe.if=['arg', 'arg', 'arg']
 "▶3 pipe.run
 " Replaces {argument} with the result of calling itself with {var} as argument 
 " list
 plugin/frawor/fwc/compiler:nmatch
 plugin/frawor/fwc/compiler:typefail
 1
+::: Section <Pipes/Built-in pipes/if>
+plugin/frawor/fwc/compiler:isnot
+plugin/frawor/fwc/compiler:isnot
 ::: Section <Pipes/Built-in pipes/dict>
 plugin/frawor/fwc/compiler:keynmatch
 plugin/frawor/fwc/compiler:keynmatch

test/fwctests.dat

 :let s:notbool=2
 ['value notbool bool',     'filter'], [0],                  [0]
 :echom s:notbool
+#▶3 if
+['if bool () is =2',       'filter'], [2],                  [2]
+['if bool () is =2',       'filter'], [1],                  [1]
+['if bool () is =2',       'filter'], [3],                  0
+['if bool |=(!@.@) ()',    'filter'], [0],                  [1]
+['if bool |=(!@.@) ()',    'filter'], [1],                  [0]
+['if bool |=(!@.@) ()',    'filter'], [2],                  [2]
+['if bool (|=(!@.@)) is=2','filter'], [0],                  [1]
+['if bool (|=(!@.@)) is=2','filter'], [1],                  [0]
+['if bool (|=(!@.@)) is=2','filter'], [2],                  [2]
+['if bool (|=(!@.@)) is=2','filter'], [3],                  0
 #▶3 dict
 ['dict {abc bool}',        'filter'], [{'abc': {}}],        [{'abc': 0}]
 ['dict {abc bool}',        'filter'], [{'ab': {}}],         0