ZyX_I avatar ZyX_I committed 9d2f61d

@/fwc: Made `range' check be aware of -onlystrings option

Comments (0)

Files changed (6)

                           | "sign"
     Completer: completes list of possible variants.
 
-range {number} {number} {one}   (|FWC-{one}|)                    *FWC-c-range*
+range {number} {number} {one}   (|FWC-{one}|)      *FWC-f-range* *FWC-c-range*
     Checker: check whether current argument is a number or float and is in 
              given range. Floating-point values are not allowed unless one of 
              {float} arguments is floating-point (infinity is not 
              a floating-point value, it is a special case) or user explicitely 
              allowed floating-point values by setting {one} argument to 1.
+    Filter: same unless |FWC-o-onlystrings| option is given. In this case it 
+            will transform its argument to either a floating-point value (only 
+            if it contains a dot) or to a number (see |str2float()| and 
+            |str2nr()|).
                        (|FWC-{float}|, |FWC-{var}|)
                          {number} :: {float}
                                    | "$" {var}
 @/fwc:
     0.1: (intfuncs-0.1) Added |FWC-c-idof|
     0.2: (intfuncs-0.2) Made |FWC-f-path| filter expand argument
+    0.3: (intfuncs-0.3) Added -onlystrings support for |FWC-c-range|
 @/os:
     0.1: Added |frawor-r-os.path.relpath|
          Made |frawor-r-os.path.normpath| also simplify its argument

plugin/frawor/fwc.vim

 "▶1 Header
 scriptencoding utf-8
-execute frawor#Setup('0.2', {'@/fwc/compiler': '0.0',
+execute frawor#Setup('0.3', {'@/fwc/compiler': '0.0',
             \                '@/decorators'  : '0.0'}, 1)
 "▶1 Define messages
 if v:lang=~?'ru'

plugin/frawor/fwc/intfuncs.vim

 "▶1 Header
 scriptencoding utf-8
-execute frawor#Setup('0.2', {'@/resources': '0.0',
+execute frawor#Setup('0.3', {'@/resources': '0.0',
             \                '@/os':        '0.0',
             \                '@/signs':     '0.0',}, 1)
 let s:r={}
     let acceptfloat=has('float') &&
                 \(a:desc[3] || a:desc[1][0] is# 'float'
                 \           || a:desc[2][0] is# 'float')
-    if acceptfloat
-        call self.addtypecond([type(0), type(0.0)], a:idx)
+    if self.o.onlystrings
+        if acceptfloat
+            let astr='((stridx('.curargstr.', ".")==-1)?'.
+                        \'(str2float('.curargstr.'):'.
+                        \'(str2nr('.   curargstr.'))))'
+        else
+            let astr='str2nr('.curargstr.')'
+        endif
+        if a:type is# 'pipe'
+            call self.let(curargstr, astr)
+        else
+            let curargstr=astr
+        endif
     else
-        call self.addtypecond([type(0)], a:idx)
+        if acceptfloat
+            call self.addtypecond([type(0), type(0.0)], a:idx)
+        else
+            call self.addtypecond([type(0)], a:idx)
+        endif
     endif
     "▶2 Obtain range borders
     let range=map(a:desc[1:2],
     endif
     "▶2 Add condition to result
     if !empty(cond)
+        let r0=((range[0] is# '')?('"inf"'):(string(range[0])))
+        let r1=((range[1] is# '')?('"inf"'):(string(range[1])))
         call self.nextthrow(cond, 'nrange', a:idx,
                     \                       'string('.curargstr.')',
-                    \                       'string('.range[0].')',
-                    \                       'string('.range[1].')')
+                    \                       'string('.r0.')',
+                    \                       'string('.r1.')')
     endif
     "▲2
     return self
 endfunction
+let s:r.range.pipe=s:r.range.check
 "▶1 `match'
 " Checks whether {argument} is a string that matches {reg}
 let s:r.match={'args': ['reg']}
 ::: Section <Option `onlystrings'>
 plugin/frawor/fwc/compiler:nbool
 plugin/frawor/fwc/compiler:nbool
+plugin/frawor/fwc/compiler:nrange
+plugin/frawor/fwc/compiler:nrange
 ::: Section <Optional arguments>
 plugin/frawor/fwc/compiler:lennmatch
 plugin/frawor/fwc/compiler:nbool

test/fwctests.dat

 ['-onlystrings bool',                   'filter'], ['yes'],    [1]
 ['-onlystrings bool',                   'filter'], ['ok'],     [1]
 ['-onlystrings bool',                   'filter'], ['tRuE'],   [1]
+['-onlystrings range 0 inf',             'check'], ['-1'],     0
+['-onlystrings range 0 inf',             'check'], ['+1'],     1
+['-onlystrings range 0 inf',            'filter'], ['-1'],     0
+['-onlystrings range 0 inf',            '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
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.