Commits

ZyX_I committed b49e49f

Replaced some expressions with `nextthrow' call

Comments (0)

Files changed (1)

plugin/frawor/fwc/compiler.vim

                 \                             join(args, ', ').'])',
                 \   'throw "CHECKFAILED"')
 endfunction
+"▶1 nextthrow      :: condition::expr, throwargs + self → self + self
+function s:constructor.nextthrow(cond, ...)
+    return call(self.nextcond(a:cond).addthrow, a:000, self).up()
+endfunction
 "▶1 cleanup        :: list::[_, {arg}*] → + list
 function s:F.cleanup(list)
     if len(a:list)>1
 "▶1 lencheck       :: minlen, maxlen + self → self + self
 function s:constructor.lencheck(minimum, maximum)
     if a:maximum==a:minimum
-        call self.nextcond('@$@largs isnot '.a:maximum)
-                    \.addthrow('invlen', a:minimum, '@$@largs')
-                    \.up()
+        call self.nextthrow('@$@largs isnot '.a:maximum,
+                    \       'invlen', a:minimum, '@$@largs')
     else
         if a:minimum>0
-            call self.nextcond('@$@largs<'.a:minimum)
-                        \.addthrow('tooshort', a:minimum, '@$@largs')
-                        \.up()
+            call self.nextthrow('@$@largs<'.a:minimum,
+                        \       'tooshort', a:minimum, '@$@largs')
         endif
         if a:maximum!=-1
-            call self.nextcond('@$@largs>'.a:maximum)
-                        \.addthrow('toolong',  a:maximum, '@$@largs')
-                        \.up()
+            call self.nextthrow('@$@largs>'.a:maximum,
+                        \       'toolong',  a:maximum, '@$@largs')
         endif
     endif
     return self.close()
     let curargstr=self.argstr()
     let typenames=map(copy(a:types), 's:_messages._types[v:val]')
     if len(a:types)>=2
-        call self.nextcond('index('.string(a:types).', '.
-                    \            'type('.curargstr.'))==-1')
-                    \.addthrow('typesfail', a:idx, '@#@',
-                    \          string(join(typenames, '/')),
-                    \          '@%@.m.types[type('.curargstr.')]')
-                    \.up()
+        call self.nextthrow('index('.string(a:types).', '.
+                    \            'type('.curargstr.'))==-1',
+                    \       'typesfail', a:idx, '@#@',
+                    \                    string(join(typenames, '/')),
+                    \                    '@%@.m.types[type('.curargstr.')]')
     elseif len(a:types)==1
-        call self.nextcond('type('.curargstr.')!='.a:types[0])
-                    \.addthrow('typefail', a:idx, '@#@',
-                    \          string(typenames[0]),
-                    \          '@%@.m.types[type('.curargstr.')]')
-                    \.up()
+        call self.nextthrow('type('.curargstr.')!='.a:types[0],
+                    \       'typefail', a:idx, '@#@', string(typenames[0]),
+                    \                   '@%@.m.types[type('.curargstr.')]')
     else
         call self.throw('notypes')
     endif
     for check in a:check[1:]
         if check[0] is 'func'
             let addedcond=1
-            call self.nextcond(self.getfunc(check, curargstr).' is 0')
-                        \.addthrow('funcfail', idx, '@#@')
-                        \.up()
+            call self.nextthrow(self.getfunc(check, curargstr).' is 0',
+                        \       'funcfail', idx, '@#@')
         elseif check[0] is 'expr'
             let addedcond=1
-            call self.nextcond(substitute(check[1], '\V@.@', curargstr, 'g').
-                        \      ' is 0')
-                        \.addthrow('exprfail', idx, '@#@')
-                        \.up()
+            call self.nextthrow(substitute(check[1], '\V@.@', curargstr, 'g').
+                        \                                           ' is 0',
+                        \       'exprfail', idx, '@#@')
         else
             let desc=check[1:]
             if desc[0] is 'func'
                 let addedcond=1
-                call self.nextcond(self.getfunc(desc[1], curargstr).' is 0')
-                            \.addthrow('funcfail', idx, '@#@')
-                            \.up()
+                call self.nextthrow(self.getfunc(desc[1], curargstr).' is 0',
+                            \       'funcfail', idx, '@#@')
             elseif desc[0] is 'eval'
                 let addedcond=1
-                call self.nextcond(substitute(desc[1][1],'\V@.@',curargstr,'g').
-                            \      ' is 0')
-                            \.addthrow('exprfail', idx, '@#@')
-                            \.up()
+                call self.nextthrow(substitute(desc[1][1],
+                            \                  '\V@.@', curargstr, 'g').' is 0',
+                            \       'exprfail', idx, '@#@')
             elseif desc[0] is 'type'
                 let addedcond=1
                 call self.addtypecond(desc[1], idx)
             elseif desc[0] is 'bool'
                 let addedcond=1
-                call self.nextcond('index([0, 1], '.curargstr.')==-1')
-                            \.addthrow('nbool', idx, '@#@',
-                            \                   'string('.curargstr.')')
-                            \.up()
+                call self.nextthrow('index([0, 1], '.curargstr.')==-1',
+                            \       'nbool', idx,'@#@', 'string('.curargstr.')')
             elseif desc[0] is 'range'
+                let acceptfloat=has('float') &&
+                            \(desc[1][0] is 'float' || desc[1][1] is 'float')
+                if acceptfloat
+                    call self.addtypecond([type(0), type(0.0)], idx)
+                else
+                    call self.addtypecond([type(0)], idx)
+                endif
+                if desc[1][0] isnot 'inf'
+                    call self.nextcond('')
+                endif
                 " TODO
             elseif desc[0] is 'key'
                 " TODO
                     let absentkeys='filter('.keys.', '.
                                 \          string('!has_key('.curargstr.', '.
                                 \                           'v:val)').')'
-                    call self.nextcond('!empty('.absentkeys.')')
-                                \.addthrow('keysmis', idx, '@#@',
-                                \          'join('.absentkeys.', ", ")')
-                                \.up()
+                    call self.nextthrow('!empty('.absentkeys.')',
+                                \       'keysmis', idx, '@#@',
+                                \                  'join('.absentkeys.', ", ")')
                 elseif !empty(desc[1])
                     let keystr=((type(desc[1][0])==type(""))?
                                 \       (s:F.string(desc[1][0])):
                                 \       (self.getvar(desc[1][0])))
-                    call self.nextcond('!has_key('.curargstr.', '.keystr.')')
-                                \.addthrow('keymis', idx, '@#@', keystr)
-                                \.up()
+                    call self.nextthrow('!has_key('.curargstr.', '.keystr.')',
+                                \       'keymis', idx, '@#@', keystr)
                 endif
             elseif desc[0] is 'isfunc'
                 let addedcond=1
                 let frefpref='string('.curargstr.')[10:11]'
                 if desc[1]
                     call self.addtypecond([2], idx)
-                    call self.nextcond('!exists('.string('*'.curargstr).') || '.
-                                \      frefpref.' is "s:"')
-                                \.addthrow('nfunc', idx, '@#@',
-                                \          'string('.curargstr.')[10:-3]')
-                                \.up()
+                    call self.nextthrow('!exists('.string('*'.curargstr).') ||'.
+                                \                       frefpref.' is "s:"',
+                                \       'nfunc', idx, '@#@',
+                                \                'string('.curargstr.')[10:-3]')
                 else
-                    call self.nextcond('!((type('.curargstr.')==2 && '.
+                    call self.nextthrow('!((type('.curargstr.')==2 && '.
                                 \         'exists('.string('*'.curargstr).')&&'.
                                 \          frefpref.' isnot "s:") '.
                                 \        '|| (type('.curargstr.')=='.type("").
                                 \            '&& '.curargstr.'=~#'.
                                 \             '''\v^%(%([sla]@!\w:)?%(\w|\.)+|'.
                                 \                    '%(s@!\w:)?\w+)$'''.
-                                \            '&& exists("*".'.curargstr.')))')
-                                \.addthrow('nsfunc', idx, '@#@',
-                                \                    'string('.curargstr.')')
-                                \.up()
+                                \            '&& exists("*".'.curargstr.')))',
+                                \       'nsfunc', idx, '@#@',
+                                \                 'string('.curargstr.')')
                 endif
             elseif desc[0] is 'isreg'
                 call self.addtypecond([type('')], idx)
                 let regex=((type(desc[1][1])==type(""))?
                             \(s:F.string(desc[1][1])):
                             \(self.getvar(desc[1][1])))
-                call self.nextcond(curargstr.'!~#'.regex)
-                            \.addthrow('nmatch', idx, '@#@', curargstr, regex)
-                            \.up()
+                call self.nextthrow(curargstr.'!~#'.regex,
+                            \       'nmatch', idx, '@#@', curargstr, regex)
             elseif desc[0] is 'dict'
                 " TODO
             elseif desc[0] is 'tuple'
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.