Commits

ZyX_I committed e2bd55c

@/fwc: Fixed some bugs:
- readexpr was not returning last closing bracket if it was not related to the expression
- constructor.if() should have either a call to toblock() or a condition, not both (left toblock())
- optional arguments are not working if they are preceded by nothing

Comments (0)

Files changed (7)

plugin/frawor/decorators.vim

             \'"Ошибка создания обвязки %s для дополнения %s: ".v:val'))
 else
     let s:_messages={
-                \       'nodec': 'Decorator `%s'' does not exist'
+                \       'nodec': 'Decorator `%s'' does not exist',
                 \    'deidnstr': 'Error while creating decorator '.
                 \                'for plugin %s: its identifier is not '.
                 \                'a String',

plugin/frawor/fwc/compiler.vim

                     \.call('remove(@$@messages, '.msglenstr.', -1)')
                 \.up().if('len(@$@pmessages)>'.pmsglenstr)
                     \.call('remove(@$@pmessages, '.pmsglenstr.', -1)')
-                \.up().endif()
+                \.endif()
 endfunction
 "▶1 witharg        :: (argbase[, [subscript]]) + self → self + self
 function s:compiler.witharg(newarg)
         endif
     endif
     if !empty(self.subs)
-        let subinit=copy(self.subs[-1])
+        let nextsub=copy(self.subs[-1])
     endif
     if has_key(a:adescr, 'arg')
         let i=0
             call self.incsub()
             let i+=1
         endfor
+        if !empty(self.subs)
+            let nextsub=copy(self.subs[-1])
+        endif
     endif
-    if empty(self.subs)
+    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'))
         return self
     endif
+    let addedsavemsgs=0
+    let caidxstr=self.getlvarid('caidx')
+    let caidx=[caidxstr]
+    let oldsub=s:F.getsub(nextsub)
+    call self.let(caidxstr, oldsub)
+    let self.subs[-1]=copy(caidx)
     if has_key(a:adescr, 'optional')
-        let caidxstr=self.getlvarid('caidx')
-        let caidx=[caidxstr]
-        let failstr=self.getlvarid('fail')
-        let self.subs[-1]=copy(subinit)
-        call     self.let(caidxstr, s:F.getsub(self.subs[-1]))
-                    \.let(failstr, 1)
-        let self.subs[-1]=copy(caidx)
-        call self.incsub()
+        let lopt=len(a:adescr.optional)
+        if lopt>1
+            let failstr=self.getlvarid('fail')
+            call self.let(failstr, 1)
+        endif
+        let addedsavemsgs=1
         call self.addsavemsgs()
                     \.try()
                         \.pushms('throw')
                         \.compileadesc(a:adescr.optional[0],
-                        \              get(a:000, 0, '').'.(optional)')
+                        \              get(a:000, 0, '').'.0(optional)')
                         \.popms()
-                        \.let(failstr, 0)
-            let newsub=s:F.getsub(self.subs[-1])
-            if newsub isnot caidxstr
-                call self.let(caidxstr, newsub)
-            endif
-        call self.catch(s:cfreg)
-                        \.let(caidxstr, s:F.getsub(s:F.incrementsub(subinit,1)))
-                    \.up().addrestmsgs()
+                        \.addrestmsgs(1)
+        if lopt>1
+            call self.let(failstr, 0)
+        endif
+        let newsub=s:F.getsub(self.subs[-1])
+        if newsub isnot caidxstr
+            call self.let(caidxstr, newsub)
+        endif
+        call self.catch(s:cfreg).up()
         let self.subs[-1]=copy(caidx)
-        let largsstr=self.getlargsstr()
+        if lopt>1
+            let i=1
+            for opt in a:adescr.optional[1:]
+                call self.if(failstr)
+                            \.try()
+                                \.pushms('throw')
+                                \.compileadesc(opt,
+                                \          get(a:000, 0, '').'.'.i.'(optional)')
+                                \.popms()
+                                \.addrestmsgs(1)
+                                \.let(failstr, 0)
+                let newsub=s:F.getsub(self.subs[-1])
+                if newsub isnot caidxstr
+                    call self.let(caidxstr, newsub)
+                endif
+                call self.catch(s:cfreg)
+                    \.endif()
+                let self.subs[-1]=copy(caidx)
+                let i+=1
+            endfor
+        endif
     endif
     " TODO
     " XXX a:0 is checked here
         call self.addif(proclen.' isnot '.largsstr)
                     \.addthrow('lennmatch', 0, proclen, largsstr)
     endif
+    if addedsavemsgs
+        call self.addrestmsgs()
+    endif
     return self
 endfunction
 "▶1 compilestr     :: vars, String, type, doreturn → [String]

plugin/frawor/fwc/constructor.vim

 endfunction
 "▶1 endif      :: &self
 function s:constructor.endif()
-    if get(self.l, 0) is 'if'
-        return self.toblock('if').add('endif').up()
-    endif
-    return self
+    return self.toblock('if').add('endif').up()
 endfunction
 "▶1 addif      :: &self(condition?)
 function s:constructor.addif(...)

plugin/frawor/fwc/parser.vim

                 let close.=remove(parens, -1)
             endwhile
             let c.=close
-            if !empty(parens)
+            if empty(parens)
+                let chunk=chunk[:-2]
+            else
                 call remove(parens, -1)
             endif
         elseif stopsym is '"'
 plugin/frawor/fwc/compiler:isnot
 ::: Section <Optional arguments>
 plugin/frawor/fwc/compiler:lennmatch
+plugin/frawor/fwc/compiler:nbool
+plugin/frawor/fwc/compiler:invlen
 plugin/frawor/fwc/compiler:lennmatch
+plugin/frawor/fwc/compiler:invlen
+plugin/frawor/fwc/compiler:nbool
+plugin/frawor/fwc/compiler:lennmatch
+plugin/frawor/fwc/compiler:nbool
+plugin/frawor/fwc/compiler:isnot
+::: Section <Optional arguments/Complex length checks>
+plugin/frawor/fwc/compiler:lennmatch
+plugin/frawor/fwc/compiler:invlen
+plugin/frawor/fwc/compiler:lennmatch
+plugin/frawor/fwc/compiler:lennmatch
+plugin/frawor/fwc/compiler:invlen
+plugin/frawor/fwc/compiler:invlen
 <<< messages

test/fwctests.dat

 ['-(only) bool',                        'filter'], [],         0
 ['-(only) bool',                        'filter'], [1],        1
 #▶1 Optional arguments
+['bool [bool] [bool bool bool]',         'check'], [0, 2],       0
+['bool [bool] [bool bool bool]',         'check'], [0, 0, 2, 0], 0
+['[bool] [is=2]',                        'check'], [],           1
+['[bool] [is=2]',                        'check'], [0],          1
+['[bool] [is=2]',                        'check'], [1],          1
+['[bool] [is=2]',                        'check'], [2],          1
+['[bool] [is=2]',                        'check'], [3],          0
+#▶2 Complex length checks
+['bool bool [bool]',                    'filter'], [0, {}, {}],  [0, 0, 0]
 ['bool [bool bool]',                    'filter'], [0, {}, {}],  [0, 0, 0]
 ['bool [bool [bool]]',                  'filter'], [0, {}, {}],  [0, 0, 0]
 ['bool [bool [bool]]',                  'filter'], [0, {}],      [0, 0]
 ['bool [bool [bool bool]]',             'filter'], [0, 0],       [0, 0]
 ['bool [bool [bool bool]]',             'filter'], [0, 0, 0],    0
 ['bool [bool [bool bool]]',             'filter'], [0, 0, 0, 0], [0, 0, 0, 0]
+['bool [bool] [bool bool bool]',         'check'], [0],          1
+['bool [bool] [bool bool bool]',         'check'], [0, 0],       1
+['bool [bool] [bool bool bool]',         'check'], [0, 0, 0],    0
+['bool [bool] [bool bool bool]',         'check'], [0, 0, 0, 0], 1
 # vim: cms=#%s fmr=▶,▲

test/rtp/plugin/fwccheck.vim

     elseif line[0] is '\'
         let toexecute.="\n".line[1:]
         continue
-    elseif !empty($DEBUGTEST) && j!=$DEBUGTEST
+    elseif       (!empty($DEBUGTEST) && j!=$DEBUGTEST) ||
+                \(!empty($STARTFROM) && j<$STARTFROM)
         let i+=1
         let j+=1
         continue
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.