1. ZyX_I
  2. frawor

Commits

ZyX_I  committed 77b412b

@/fwc: Improved `run' and `earg' filters: they now check for exceptions during running/evaluating, improved isfunc check: it now omits situations where exists() may throw an exception

  • Participants
  • Parent commits bab80a1
  • Branches default

Comments (0)

Files changed (3)

File plugin/frawor/fwc/compiler.vim

View file
             \   'nmatch': "string `%s' does not match regular expression `%s'",
             \  'keysmis': 'the following required keys are missing: %s',
             \   'keymis': 'key `%s'' is missing',
+            \  'runfail': 'running argument failed with exception %s',
+            \ 'evalfail': 'evaluating argument failed with exception %s',
         \}, '"Error while processing check %u for %s: ".v:val'))
 let s:_messages._types=['number', 'string', 'function reference', 'list',
             \           'dictionary']
     endif
     return self.getvar(a:str)
 endfunction
-"▶1 compilepipe    :: pipecontext, _ + self → self + self
+"▶1 compilepipe    :: pipecontext, idx + self → self + self
 function s:constructor.compilepipe(pipe, idx)
     let curargstr=self.argstr()
     if a:pipe[1][0] is 'func'
         elseif desc[0] is 'func' || desc[0] is 'eval'
             call self.compilepipe(desc, a:idx)
         elseif desc[0] is 'run'
-            call self.add('let '.curargstr.'=call('.curargstr.', '.
-                        \                         self.getvar(desc[1]).', {})')
+            call self.add('try')
+                        \.deeper('let '.curargstr.'=call('.curargstr.', '.
+                        \                          self.getvar(desc[1]).', {})')
+                        \.up().add('catch /.*/').deeper()
+                        \.addthrow('runfail', a:idx, '@#@', 'v:exception')
+                        \.up().close()
         elseif desc[0] is 'earg'
-            call self.add('let '.curargstr.'=eval('.curargstr.')')
+            call self.add('try')
+                        \.deeper('let '.curargstr.'=eval('.curargstr.')')
+                        \.up().add('catch /.*/').deeper()
+                        \.addthrow('evalfail', a:idx, '@#@', 'v:exception')
+                        \.up().close()
         elseif desc[0] is 'bool'
             call self.add('let '.curargstr.'=!empty('.curargstr.')')
         else
                                 \         'exists('.string('*'.curargstr).')&&'.
                                 \          frefpref.' isnot "s:") '.
                                 \        '|| (type('.curargstr.')=='.type("").
-                                \            '&& exists("*".'.curargstr.'))'.
-                                \            '&& '.curargstr.'[:1] isnot "s:")')
+                                \            '&& '.curargstr.'=~#'.
+                                \             '''\v^%(%([sla]@!\w:)?%(\w|\.)+|'.
+                                \                    '%(s@!\w:)?\w+)$'''.
+                                \            '&& exists("*".'.curargstr.')))')
                                 \.addthrow('nsfunc', idx, '@#@',
                                 \                    'string('.curargstr.')')
                                 \.up()

File test/fwccheck.ok

View file
 ::: Section <Pipes/Expression pipes>
 ::: Section <Pipes/Built-in pipes>
 plugin/frawor/fwc/compiler:nsfunc
+plugin/frawor/fwc/compiler:runfail
+plugin/frawor/fwc/compiler:evalfail
+plugin/frawor/fwc/compiler:nsfunc
 ::: Section <Pipes/Built-in pipes/Substitute>
 plugin/frawor/fwc/compiler:typefail
 ::: Section <Pipes/Built-in pipes/Bool>
 plugin/frawor/fwc/compiler:nsfunc
 plugin/frawor/fwc/compiler:typefail
 plugin/frawor/fwc/compiler:nfunc
+plugin/frawor/fwc/compiler:nsfunc
+plugin/frawor/fwc/compiler:nsfunc
 ::: Section <Checks/Built-in checks/Match>
 plugin/frawor/fwc/compiler:nmatch
 plugin/frawor/fwc/compiler:typefail

File test/fwctests.dat

View file
 ['eval string(@.@)',       'filter'], ['abc'],              ["'abc'"]
 ['run [abc]',              'filter'], ['string'],           ["'abc'"]
 ['run [abc]',              'filter'], [function("string")], ["'abc'"]
+['run []',                 'filter'], ['()'],               0
+['run [$[abc def]]',       'filter'], [s:.revstring],       0
 ['earg',                   'filter'], ['string("abc")'],    ["'abc'"]
+['earg',                   'filter'], ['('],                0
 ['isfunc',                 'filter'], [0],                  0
 ['isfunc',                 'filter'], [function("tr")],     [function("tr")]
 #▶3 Substitute
 ['haskey $k1',      'check'], [{'abc': 1}],         0
 ['haskey $k1',      'check'], [{'def': 1}],         1
 #▶3 isfunc
-['isfunc',          'check'], [function("tr")],     1
-['isfunc',          'check'], [function("s:Eval")], 0
-['isfunc',          'check'], ["tr"],               1
-['isfunc',          'check'], ["s:Eval"],           0
-['isfunc 1',        'check'], [function("tr")],     1
-['isfunc 1',        'check'], ["tr"],               0
-['isfunc 1',        'check'], [function("s:Eval")], 0
+['isfunc',          'check'], [function('tr')],     1
+['isfunc',          'check'], [function('s:Eval')], 0
+['isfunc',          'check'], ['tr'],               1
+['isfunc',          'check'], ['s:Eval'],           0
+['isfunc 1',        'check'], [function('tr')],     1
+['isfunc 1',        'check'], ['tr'],               0
+['isfunc 1',        'check'], [function('s:Eval')], 0
+# The following may throw an exception
+['isfunc',          'check'], ['()'],               0
+['isfunc',          'check'], ['g:[xx]'],           0
 #▶3 Match
 ['match/\vb@<!a/',  'check'], ['abc'],              1
 ['match/\vb@<!a/',  'check'], ['bac'],              0