Commits

ZyX_I committed f649edd

@/fwc/*: Added support for numbers where variables can be used. Fixes #2

  • Participants
  • Parent commits 30f3340

Comments (0)

Files changed (4)

 Integer and floating-point numbers format in FWC is more permissive then vim 
 own format: it allows to use underscore to separate digits to make them more 
 readable, omit numbers before and after the dot, put spaces after sign, ...
-    {float} :: [+-]? " "* ( "inf" | [0-9_]* "."? [0-9_]* ("e" [+-]? [0-9]+)? )
+    {float} :: ( "+" | "-" ) ( "nan" | "inf" | {unum} | {hnum} | {onum} )
+    {unum}  :: ( [1-9] {d}* | 0 )? ( "." {d}* )? ( "e" ( "+" | "-" )? [0-9]+ )?
+       {d}  :: [0-9] | "_"
+    {hnum}  :: "0x" ( [0-9] | [a-f] | [A-F] | "_" )*
+    {onum}  :: "0" ( [0-7] | "_" )+
 All elements are optional (but there must be at least one element), case does 
 not matter:
     FWC       Vim  | FWC      Vim~
 4. A function call (with dot argument undefined), see |FWC-{func}|.
 5. A list, see |FWC-{list}|.
 6. A string, see |FWC-{str}|.
+7. A number, see |FWC-{float}|.
 You can also use parenthesis around variable and use "$" to evaluate {var} at 
 compile time and insert the results: for example, to convert current argument 
 to a string using built-in |string()| function you cannot do `|*string', but 
                  | "*" {func}
                  | {list}
                  | {str}
+                 | ( {float} & ! ( [+-] "inf" | "nan" ) )
                                                                 *FWC-{subscr}*
 Each subscript must start with a dot and be followed by
 1. A word: `.string' will try to access key "string".
     Filter: calls current argument with {var} as an arguments list and 
             replaces it with the result of the call. |self| will be set to 
             a new empty dictionary for this call.
+    Completer: completes to function name which accepts required number of 
+               arguments.
 
 earg                                                             *FWC-f-earg*
     Filter: replaces argument with the result of evaluating itself.
+    Completer: ignored.
 
 not {arg}    (|FWC-{arg}|)                                        *FWC-c-not*
     Checker: fails if processing argument using {arg} succeeds.
             with \, [, ], ? and * escaped). This means that you can use 
             ~ directory shortcut, |:_%|, |:_#|, enviroment variables, 
             |`-expansion| and |`=|.
+    Completer: tries to do something like zsh pathname completion. Always 
+               completes directories.
                     {pathspec} :: [df]? "r"? [wWp]? "x"?
                                 & ! ( "d" | ^ ) "r"
                                 & ! "d" [wWp]? "x"
              (dict.key).
     Filter: checks argument with above rules and if check succeeds, transforms 
             it into a function reference (unless it is a reference already).
+    Completer: completes function names.
 
 isreg                                                            *FWC-c-isreg*
     Checker: checks whether argument is a valid regular expression.
+    Completer: ignored.
 
 bool                                                 *FWC-c-bool* *FWC-f-bool*
     Checker: checks whether argument is 0 or 1 (if |FWC-o-onlystrings| is 

plugin/frawor/fwc/compiler.vim

         let r=[self.getexpr(a:var)]
     elseif a:var[0] is# 'string'
         let r=[self.string(a:var[1])]
+    elseif a:var[0] is# 'number'
+        let r=[''.a:var[1]]
+    elseif a:var[0] is# 'float'
+        let r=[string(a:var[1])]
     elseif a:var[0] is# 'argument'
         let r=[self.argbase, [s:F.incrementsub(self.subs[0], a:var[1])]+
                     \        a:var[2:]]

plugin/frawor/fwc/intfuncs.vim

         if acceptfloat
             let astr='((stridx('.curargstr.', ".")==-1)?'.
                         \'(str2float('.curargstr.'):'.
-                        \'(str2nr('.   curargstr.'))))'
+                        \'(+('.   curargstr.'))))'
         else
             let astr='str2nr('.curargstr.')'
         endif

plugin/frawor/fwc/parser.vim

     return c
 endfunction
 "▶1 readflt    :: () + self → String|0 + self(s)
-"  {flt} :: ( "+" | "-" ) ( "nan" | "inf" | {unum} )
-" {unum} :: {d}* "."? {d}* ( "e" ( "+" | "-" )? [0-9]+ )?
+"  {flt} :: ( "+" | "-" ) ( "nan" | "inf" | {unum} | {hnum} | {onum} )
+" {unum} :: ( [1-9] {d}* | 0 )? ( "." {d}* )? ( "e" ( "+" | "-" )? [0-9]+ )?
 "    {d} :: [0-9] | "_"
+" {hnum} :: "0x" ( [0-9] | [a-f] | [A-F] | "_" )*
+" {onum} :: "0" ( [0-7] | "_" )+
 function s:parser.readflt()
     if !empty(self.ungot)
         call self.ungotjoin()
     endif
     call self.delblanks()
     let c=matchstr(self.s,
-                \'\v\c^[+-]? *%(nan|inf|[0-9_]*\.?[0-9_]*%(e[+-]?\d+)?)')
+                \'\v\c^[+-]?\ *%(nan|inf|0[0-7_]+|'.
+                \               '%(0|[1-9][0-9_]*)?%(\.[0-9_]*)?%(e[+-]?\d+)?|'.
+                \               '0x[0-9a-fA-F_]+)')
     call self.removestr(len(c))
     if empty(c)
         return 0
         if c is# '$'
             return self.getvar()
         else
-            call self.ungetc(c)
+            return self.ungetc(c)
         endif
     elseif f[-3:] is# 'inf'
         let sign=f[0]
             let sign='+'
         endif
         return self.addcon('inf', sign).conclose()
-    elseif f is# 'nan'
+    elseif f[-3:] is# 'nan'
         return self.addcon('nan').conclose()
     endif
     let r=eval(f)
 "       | {chvar}
 "       | {expr}
 "       | {list}
+"       | {number}
 "       | context(evaluate, {var})
 "       | context(string, String)
 function s:parser.getvar()
     let c=self.readc()
-    if c=~#'^\w'
+    if c=~#'^\d' || c is# '+' || c is# '-'
+        call self.ungetc(c)
+        return self.getnumber()
+    elseif c=~#'^\w'
         call self.addcon('plugvar')
         call self.ungetc(c)
         call self.getsubscr()