ZyX_I avatar ZyX_I committed 1a628c7

@/fwc: Added variants filtering optimization

Comments (0)

Files changed (3)

plugin/frawor/fwc/compiler.vim

     endif
     return self
 endfunction
+"▶1 optgetconds     :: () + self → Maybe vimlexpr
+function s:compiler.optgetconds()
+    if len(self.l)==2
+                \&& len(self.l[0])>2
+                \&& self.l[0][0] is 'if'
+                \&& ((self.l[0][-1] is 'endif'
+                \  && self.l[0][-3] isnot 'else')
+                \ || (self.l[0][-2] isnot 'else'))
+        let conditions=[]
+        let iftree=copy(self.l[0])
+        while !empty(iftree)
+            let type=remove(iftree, 0)
+            if type is 'if' || type is 'elseif'
+                let [condition, block]=remove(iftree, 0, 1)
+                if block!=#[['throw', s:cfstr]]
+                    return 0
+                endif
+                call add(conditions, condition)
+            elseif type is 'endif'
+                break
+            else
+                return 0
+            endif
+        endwhile
+        return conditions
+    endif
+    return 0
+endfunction
+"▶1 optimizecompf   :: &self
+" XXX low-level hacks here
+function s:compiler.optimizecompf()
+    call self.down(self.l[2][-1][1])
+    let conditions=self.optgetconds()
+    call self.up()
+    if type(conditions)==type([])
+        call self.down(self.l[2])
+        let argidxstr=self.l[-1][1][-1][1]
+        let removestr=self.l[-1][-1][0][1]
+        let condition=join(conditions, ' || ')
+        let chargstr='@-@['.argidxstr.']'
+        if condition=~#'\v^%([^@]|\V'.chargstr.'\v)+$'
+            call self.up().up()
+            call remove(self.l, -2, -1)
+            let condition=substitute(condition, '\V'.chargstr, 'v:val', 'g')
+            call self.call('filter(@-@, '.string('!('.condition.')').')')
+        else
+            call remove(self.l, -1)
+            call self.if(condition)
+                        \.call(removestr)
+                    \.up().addif()
+                        \.increment(argidxstr)
+                    \.up()
+                \.up()
+        endif
+    endif
+    return self
+endfunction
 "▶1 compilemsg      :: &self(msgcontext, idx, type)
 function s:compiler.compilemsg(msg, idx, type)
     if a:type is 'complete'
                 \.up().catch(s:cfreg)
                     \.call('remove(@-@, '.argidxstr.')')
                 \.up()
-            \.up()
+            \.up().up()
+            \.optimizecompf()
     endif
     return self
 endfunction

plugin/frawor/fwc/intfuncs.vim

 "▶2 optimize
 " XXX low-level hacks here
 function s:r.not.optimize(idx, type)
-    if len(self.l[1])==2
-                \&& len(self.l[1][0])>2
-                \&& self.l[1][0][0] is 'if'
-                \&& ((self.l[1][0][-1] is 'endif'
-                \  && self.l[1][0][-3] isnot 'else')
-                \ || (self.l[1][0][-2] isnot 'else'))
-        let conditions=[]
-        let iftree=copy(self.l[1][0])
-        while !empty(iftree)
-            let type=remove(iftree, 0)
-            if type is 'if' || type is 'elseif'
-                let [condition, block]=remove(iftree, 0, 1)
-                if block!=#[['throw', s:cfstr]]
-                    return self
-                endif
-                call add(conditions, condition)
-            elseif type is 'endif'
-                break
-            else
-                return self
-            endif
-        endwhile
+    call self.down(self.l[1])
+    let conditions=self.optgetconds()
+    call self.up()
+    if type(conditions)==type([])
         call remove(self.l, 0, -1)
         call self.add('if', 0, [])
         call self.nextthrow('!('.join(conditions, ' || ').')', 'notfail', a:idx)

test/fwccompletetests.dat

 :let s:list=['abc', 'ab-c', 'def-ghi', 'adb']
 :let s:list2=['abc', 'def-b', 'geh']
 :let s:list3=['foo', 'bar', 'baz']
+:let s:listr=['\v(', '\v)', 'abc']
 :let s:dict={'abc': 1, 'adb': 1, 'aef': 1}
 #▶1 Built-in completion functions
 #▶2 in
 `(in list match /^a/)
   @+
   =filter(copy(s:list), 'v:val[0] is "a"')
+
 `(in list match /^a/ match /d/)
   @+
   =filter(copy(s:list), 'v:val[0] is "a" && stridx(v:val, "d")!=-1')
+
+`(in listr isreg)
+  @+
+  abc
 #▶1 Different sections
 #▶2 {required}
 `in list
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.