Commits

ZyX_I committed db2c931

@/fwc/parser: Made it possible to specify getter function inside FWC_intfuncs.func dictionary

  • Participants
  • Parent commits 11fa476

Comments (0)

Files changed (2)

File plugin/frawor/fwc/intfuncs.vim

 " specification
 let s:r.list.pipe=s:r.list.check
 "▶1 `dict'
-let s:r.dict={'args': ['ddescr']}
+let s:r.dict={'args': ['get']}
+"▶2 getddescr  :: &self
+" Gets dictionary description:
+" Input: "{" ({keydescr} {arg})* "}"
+"        {keydescr} :: {str}
+"                    | "/" {reg}(endstr=/)
+"                    | "?" {arg}
+"                    | "*" {func}
+"                    | "=" {expr}
+"                    | "-"
+"                    | {wordchar}+
+" Output: context(ddescr, {keycon}*)
+"         {keycon} :: context(eq,    String, {arg})
+"                   | context(regex, String, {arg})
+"                   | context(check, {arg},  {arg})
+"                   | context(func,  {func}, {arg})
+"                   | context(expr,  {expr}, {arg})
+"                   | context(any,           {arg})
+function s:r.dict.get()
+    call self.addcon('ddescr')
+    if self.len
+        let c=self.readc()
+        if c isnot '{'
+            call self.ungetc(c)
+        endif
+        let prevlen=-1
+        while self.len && self.len!=prevlen
+            let prevlen=self.len
+            let c=self.readc()
+            if c is '}'
+                break
+            elseif c is '/'
+                call self.addcon('regex', self.readreg('/')).scan().conclose()
+            elseif c is '*'
+                call self.addcon('func').getfunc().scan().conclose()
+            elseif c is '='
+                call self.addcon('expr').getexpr().scan().conclose()
+            elseif c is '?'
+                call self.addcon('check').scan().scan().conclose()
+            elseif c is '-'
+                call self.addcon('any').scan().conclose()
+            elseif c is '"'
+                call self.addcon('eq', self.readstr()).scan().conclose()
+            elseif c is "'"
+                call self.addcon('eq', self.readsstr()).scan().conclose()
+            elseif c=~#'^\w'
+                call self.addcon('eq', c).scan().conclose()
+            endif
+        endwhile
+    endif
+    return self.conclose()
+endfunction
+"▲2
 " Checks whether {argument} is a dictionary matching given {ddescr}
 function s:r.dict.check(desc, idx, type)
     return self.addtypecond([type({})], a:idx).adddict(a:desc, a:idx, a:type)
 endfunction
 "▶1 `path'
 " Checks whether {argument} is a path matching given specification
-let s:r.path={'args': ['path']}
+let s:r.path={'args': ['get']}
+"▶2 getpath    :: &self!
+" Gets path specification:
+" Input: [( "d" | "f" )] [ "r" ] [( "w" | "W" | "p" )] [ "x" ]
+"        & ! ( "d" | ^ ) "r"
+"        & ! ( "d" ) ( "w" | "W" | "p" )? "x"
+" 1. "d" for directory and "f" for regular file, otherwise both may be accepted
+" 2. "r" for readable file (not directory)
+" 3. "w" for writeable file or directory (unless "f" is specified),
+"    "W" for writeable file or directory (unless "f" is specified) or
+"        non-existant file in writeable directory (unless "d" is specified),
+"    "p" like "W", but also accepts any path that can be created (for example,
+"        if you have directory /a and you can write to it, then path /a/b/c/d 
+"        will be accepted),
+" 4. "x" for executable file (not directory)
+" Output: add({pathspec})
+function s:r.path.get()
+    let c=self.readc()
+    if c=~#'\v^[df]?r?[wWp]?x?$' && c!~#'\v^%(d%(.{,2}x|r)|r)'
+        call self.add(c)
+    else
+        call self.add('r').ungetc(c)
+    endif
+    return self
+endfunction
+"▲2
 function s:r.path.check(desc, idx, type)
     let curargstr=self.argstr()
     call self.addtypecond([type('')], a:idx)

File plugin/frawor/fwc/parser.vim

         if farg[0] is '*'
             call self.scanlist(farg[1:])
         else
-            call call(self['get'.farg], [], self)
+            call call(((farg[:2] is 'get')?
+                        \(s:_r.FWC_intfuncs[func][farg]):
+                        \(self['get'.farg])), [], self)
         endif
+        unlet farg
     endfor
     return self.conclose()
 endfunction