Commits

ZyX_I committed 19d2246

@/fwc: Rearranged code blocks

Comments (0)

Files changed (2)

plugin/frawor/fwc/compiler.vim

 "▶1 compilepipe    :: pipecontext, idx + self → self + self
 function s:constructor.compilepipe(pipe, idx)
     let curargstr=self.argstr()
+    "▶2 `func' pipe
     if a:pipe[1][0] is 'func'
-        call self.add('let '.curargstr.'='.
-                    \       self.getfunc(a:pipe[1], curargstr))
+        call self.add('let '.curargstr.'='.self.getfunc(a:pipe[1], curargstr))
+    "▶2 `expr' pipe
     elseif a:pipe[1][0] is 'expr'
-        call self.add('let '.curargstr.'='.
-                    \       substitute(a:pipe[1][1],
-                    \                  '\V@.@', curargstr, 'g'))
+        call self.add('let '.curargstr.'='.substitute(a:pipe[1][1],
+                    \                                 '\V@.@', curargstr, 'g'))
+    "▶2 Built-in pipes
     elseif a:pipe[1][0] is 'intfunc'
         let desc=a:pipe[1][1:]
-        if desc[0] is 'substitute'
-            call self.add('let '.curargstr.'=substitute('.curargstr.', '.
-                        \((type(desc[1][1])==type(''))?
-                        \       (s:F.string(desc[1][1])):
-                        \       (self.getvar(desc[1][1]))).', '.
-                        \join(map(desc[2:], 'self.compilestring(v:val)'), ', ').
-                        \')')
+        "▶3 `func', `eval'
+        if desc[0] is 'func' || desc[0] is 'eval'
+            call self.compilepipe(desc, a:idx)
+        "▶3 `run'
+        elseif desc[0] is 'run'
+            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()
+        "▶3 `earg'
+        elseif desc[0] is 'earg'
+            call self.add('try')
+                        \.deeper('let '.curargstr.'=eval('.curargstr.')')
+                        \.up().add('catch /.*/').deeper()
+                        \.addthrow('evalfail', a:idx, '@#@', 'v:exception')
+                        \.up().close()
+        "▶3 `tuple'
         elseif desc[0] is 'tuple'
             call self.nextthrow('len('.curargstr.')!='.len(desc[1]),
                         \       'invlstlen', a:idx, '@#@', len(desc[1]),
                 call remove(self.subs, -1)
                 let i+=1
             endfor
+        "▶3 `list'
+        elseif desc[0] is 'list'
+            " TODO
+        "▶3 `dict'
+        elseif desc[0] is 'dict'
+            " TODO
+        "▶3 `in'
         elseif desc[0] is 'in'
             if len(desc)==2 || (desc[2][1][0] is 'intfunc' &&
                         \       desc[2][1][1] is 'exact' &&
                 call self.addtypecond([type('')], idx)
                 " TODO
             endif
+        "▶3 `key'
         elseif desc[0] is 'key'
             if len(desc)==2 || (desc[2][1][0] is 'intfunc' &&
                         \       desc[2][1][1] is 'exact' &&
                 call self.addtypecond([type('')], idx)
                 " TODO
             endif
+        "▶3 `take'
         elseif desc[0] is 'take'
             " TODO
-        elseif desc[0] is 'func' || desc[0] is 'eval'
-            call self.compilepipe(desc, a:idx)
-        elseif desc[0] is 'run'
-            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('try')
-                        \.deeper('let '.curargstr.'=eval('.curargstr.')')
-                        \.up().add('catch /.*/').deeper()
-                        \.addthrow('evalfail', a:idx, '@#@', 'v:exception')
-                        \.up().close()
+        "▶3 `substitute'
+        elseif desc[0] is 'substitute'
+            call self.add('let '.curargstr.'=substitute('.curargstr.', '.
+                        \((type(desc[1][1])==type(''))?
+                        \       (s:F.string(desc[1][1])):
+                        \       (self.getvar(desc[1][1]))).', '.
+                        \join(map(desc[2:], 'self.compilestring(v:val)'), ', ').
+                        \')')
+        "▶3 `bool'
         elseif desc[0] is 'bool'
             call self.add('let '.curargstr.'=!empty('.curargstr.')')
+        "▲3
         else
             call self.compilecheck(['check', a:pipe[1]], a:idx)
         endif
                 call self.nextthrow(substitute(desc[1][1],
                             \                  '\V@.@', curargstr, 'g').' is 0',
                             \       'exprfail', idx, '@#@')
-            "▶3 `type'
-            elseif desc[0] is 'type'
+            "▶3 `either'
+            elseif desc[0] is 'either'
+                " TODO
+            "▶3 `tuple'
+            elseif desc[0] is 'tuple'
+                call self.addtypecond([type([])], idx)
+                call self.nextthrow('len('.curargstr.')!='.len(desc[1]),
+                            \       'invlstlen', idx, '@#@', len(desc[1]),
+                            \                    'len('.curargstr.')')
+                let i=0
+                for arg in desc[1]
+                    call add(self.subs,  i)
+                    call self.compilecheck(arg, idx.'.'.i)
+                    call remove(self.subs, -1)
+                    let i+=1
+                endfor
+            "▶3 `list'
+            elseif desc[0] is 'list'
+                " TODO
+            "▶3 `dict'
+            elseif desc[0] is 'dict'
+                " TODO
+            "▶3 `in'
+            elseif desc[0] is 'in'
                 let addedcond=1
-                call self.addtypecond(desc[1], idx)
-            "▶3 `bool'
-            elseif desc[0] is 'bool'
+                call self.nextthrow('index('.self.getvar(desc[1]).', '.
+                            \                curargstr.')==-1',
+                            \       'ninlist', idx, '@#@')
+            "▶3 `key'
+            elseif desc[0] is 'key'
                 let addedcond=1
-                call self.nextthrow('index([0, 1], '.curargstr.')==-1',
-                            \       'nbool', idx,'@#@', 'string('.curargstr.')')
+                call self.addtypecond([type('')], idx)
+                call self.nextthrow('!has_key('.self.getvar(desc[1]).', '.
+                            \                   curargstr.')',
+                            \       'nindict', idx, '@#@', curargstr)
+            "▶3 `haskey'
+            elseif desc[0] is 'haskey'
+                let addedcond=1
+                call self.addtypecond([type({})], idx)
+                if len(desc[1])>1
+                    let keys='['.join(map(copy(desc[1]),
+                                \         'type(v:val)==type("")?'.
+                                \               's:F.string(v:val):'.
+                                \               'self.getvar(v:val)'),
+                                \', ').']'
+                    let absentkeys='filter('.keys.', '.
+                                \          string('!has_key('.curargstr.', '.
+                                \                           'v:val)').')'
+                    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.nextthrow('!has_key('.curargstr.', '.keystr.')',
+                                \       'keymis', idx, '@#@', keystr)
+                endif
             "▶3 `range'
             elseif desc[0] is 'range'
                 let addedcond=1
                                 \                       'string('.range[0].')',
                                 \                       'string('.range[1].')')
                 endif
-            "▶3 `key'
-            elseif desc[0] is 'key'
+            "▶3 `match'
+            elseif desc[0] is 'match'
                 let addedcond=1
                 call self.addtypecond([type('')], idx)
-                call self.nextthrow('!has_key('.self.getvar(desc[1]).', '.
-                            \                   curargstr.')',
-                            \       'nindict', idx, '@#@', curargstr)
-            "▶3 `in'
-            elseif desc[0] is 'in'
+                let regex=((type(desc[1][1])==type(''))?
+                            \(s:F.string(desc[1][1])):
+                            \(self.getvar(desc[1][1])))
+                call self.nextthrow(curargstr.'!~#'.regex,
+                            \       'nmatch', idx, '@#@', curargstr, regex)
+            "▶3 `path'
+            elseif desc[0] is 'path'
+                call self.addtypecond([type('')], idx)
+                " TODO
+            "▶3 `type'
+            elseif desc[0] is 'type'
                 let addedcond=1
-                call self.nextthrow('index('.self.getvar(desc[1]).', '.
-                            \                curargstr.')==-1',
-                            \       'ninlist', idx, '@#@')
-            "▶3 `haskey'
-            elseif desc[0] is 'haskey'
-                let addedcond=1
-                call self.addtypecond([type({})], idx)
-                if len(desc[1])>1
-                    let keys='['.join(map(copy(desc[1]),
-                                \         'type(v:val)==type("")?'.
-                                \               's:F.string(v:val):'.
-                                \               'self.getvar(v:val)'),
-                                \', ').']'
-                    let absentkeys='filter('.keys.', '.
-                                \          string('!has_key('.curargstr.', '.
-                                \                           'v:val)').')'
-                    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.nextthrow('!has_key('.curargstr.', '.keystr.')',
-                                \       'keymis', idx, '@#@', keystr)
-                endif
+                call self.addtypecond(desc[1], idx)
             "▶3 `isfunc'
             elseif desc[0] is 'isfunc'
                 let addedcond=1
                           \.addthrow('nreg', idx, '@#@', curargstr,
                           \                  'v:exception')
                         \.up().close()
-            "▶3 `match'
-            elseif desc[0] is 'match'
+            "▶3 `bool'
+            elseif desc[0] is 'bool'
                 let addedcond=1
-                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.nextthrow(curargstr.'!~#'.regex,
-                            \       'nmatch', idx, '@#@', curargstr, regex)
-            "▶3 `dict'
-            elseif desc[0] is 'dict'
-                " TODO
-            "▶3 `tuple'
-            elseif desc[0] is 'tuple'
-                call self.addtypecond([type([])], idx)
-                call self.nextthrow('len('.curargstr.')!='.len(desc[1]),
-                            \       'invlstlen', idx, '@#@', len(desc[1]),
-                            \                    'len('.curargstr.')')
-                let i=0
-                for arg in desc[1]
-                    call add(self.subs,  i)
-                    call self.compilecheck(arg, idx.'.'.i)
-                    call remove(self.subs, -1)
-                    let i+=1
-                endfor
-            "▶3 `either'
-            elseif desc[0] is 'either'
-                " TODO
-            "▶3 `path'
-            elseif desc[0] is 'path'
-                call self.addtypecond([type('')], idx)
-                " TODO
+                call self.nextthrow('index([0, 1], '.curargstr.')==-1',
+                            \       'nbool', idx,'@#@', 'string('.curargstr.')')
             "▶3 `_', `any'
             elseif desc[0] is '_' || desc[0] is 'any'
                 " Just do nothing here

plugin/frawor/fwc/parser.vim

 let s:args={}
 "▶2 pipe
 let s:args.pipe={}
-"▶3 pipe.substitute
-" Runs substitute on {argument}
-let s:args.pipe.substitute=['reg', 'string', 'string']
-"▶3 pipe.tuple
-" Checks whether {argument} is a list with a fixed length and then process given 
-" pipes for each of the arguments
-let s:args.pipe.tuple=['*arg']
-"▶3 pipe.in
-" Picks up first element from {var}::List that matches {argument}. If {matcher} 
-" is absent then {argument} may be of any type. In other case it should be 
-" string.
-let s:args.pipe.in=['var', '?omtchr']
-"▶3 pipe.key
-" Picks up first key from {var}::Dictionary that matches {argument}
-let s:args.pipe.key=['var', '?omtchr']
-"▶3 pipe.take
-" Replaces {argument} with value of the first key from {var}::Dictionary that 
-" matches {argument}
-let s:args.pipe.take=['var', '?omtchr']
 "▶3 pipe.func
 " Replaces {argument} with the result of running {func}({argument})
 let s:args.pipe.func=['func']
 "▶3 pipe.earg
 " Replaces {argument} with the result of evaluating itself
 let s:args.pipe.earg=[]
+"▶3 pipe.tuple
+" Checks whether {argument} is a list with a fixed length and then process given 
+" pipes for each of the arguments
+let s:args.pipe.tuple=['*arg']
+"▶3 pipe.list
+" Checks whether {argument} is a list and then filter each item using given 
+" specification
+let s:args.pipe.list=['arg']
+"▶3 pipe.dict
+" Checks whether {argument} is a dictionary and transform it using given 
+" {ddescr}
+let s:args.pipe.dict=['ddescr']
+"▶3 pipe.in
+" Picks up first element from {var}::List that matches {argument}. If {matcher} 
+" is absent then {argument} may be of any type. In other case it should be 
+" string.
+let s:args.pipe.in=['var', '?omtchr']
+"▶3 pipe.key
+" Picks up first key from {var}::Dictionary that matches {argument}
+let s:args.pipe.key=['var', '?omtchr']
+"▶3 pipe.take
+" Replaces {argument} with value of the first key from {var}::Dictionary that 
+" matches {argument}
+let s:args.pipe.take=['var', '?omtchr']
+"▶3 pipe.substitute
+" Runs substitute on {argument}
+let s:args.pipe.substitute=['reg', 'string', 'string']
+"▶3 pipe.bool
+" Transforms {argument} to 0 if it is empty and to 1 otherwise
+let s:args.pipe.bool=[]
 "▶2 check
 let s:args.check={}
 "▶3 check.func
 "▶3 check.eval
 " Checks whether result of running eval({expr}) isnot 0
 let s:args.check.eval=['expr']
+"▶3 check.either
+" Checks whether {argument} matches one of given specifications
+let s:args.check.either=['*check']
+"▶3 check.tuple
+" Checks whether {argument} is a list with a fixed length and each element 
+" matching given specification
+let s:args.check.tuple=['*arg']
+"▶3 check.list
+" Checks whether {argument} is a list where each item matches given 
+" specification
+let s:args.check.list=['arg']
+"▶3 check.dict
+" Checks whether {argument} is a dictionary matching given {ddescr}
+let s:args.check.dict=['ddescr']
+"▶3 check.in
+" Checks whether {argument} is inside list {var}. Matcher is ignored
+let s:args.check.in=['var', '?omtchr']
+"▶3 check.key
+" Checks whether {argument} is a key of {var}. Matcher is ignored
+let s:args.check.key=['var', '?omtchr']
+"▶3 check.haskey
+" Checks whether {argument} is a dictionary with given keys
+let s:args.check.haskey=['*string']
+"▶3 check.range
+" Checks whether {argument} is in given range
+let s:args.check.range=['number', 'number']
+"▶3 check.match
+" Checks whether {argument} is a string that matches {reg}
+let s:args.check.match=['reg']
+"▶3 check.path
+" Checks whether {argument} is a path matching given specification
+let s:args.check.path=['path']
 "▶3 check.type
 " Checks whether {argument} has one of given types
 let s:args.check.type=['*type']
-"▶3 check.bool
-" Checks whether {argument} is either 0 or 1
-let s:args.check.bool=[]
-"▶3 check.range
-" Checks whether {argument} is in given range
-let s:args.check.range=['number', 'number']
-"▶3 check.key
-" Checks whether {argument} is a key of {var}. Matcher is ignored
-let s:args.check.key=['var', '?omtchr']
-"▶3 check.in
-" Checks whether {argument} is inside list {var}. Matcher is ignored
-let s:args.check.in=['var', '?omtchr']
-"▶3 check.haskey
-" Checks whether {argument} is a dictionary with given keys
-let s:args.check.haskey=['*string']
 "▶3 check.isfunc
 " Checks whether {argument} is a callable function reference. Additional 
 " argument determines whether strings should not be accepted
 "▶3 check.isreg
 " Checks whether {argument} is a valid regular expression
 let s:args.check.isreg=[]
-"▶3 check.match
-" Checks whether {argument} is a string that matches {reg}
-let s:args.check.match=['reg']
-"▶3 check.dict
-" Checks whether {argument} is a dictionary matching given {ddescr}
-let s:args.check.dict=['ddescr']
-"▶3 check.tuple
-" Checks whether {argument} is a list with a fixed length and each element 
-" matching given specification
-let s:args.check.tuple=['*arg']
-"▶3 check.either
-" Checks whether {argument} matches one of given specifications
-let s:args.check.either=['*check']
-"▶3 check.path
-" Checks whether {argument} is a path matching given specification
-let s:args.check.path=['path']
+"▶3 check.bool
+" Checks whether {argument} is either 0 or 1
+let s:args.check.bool=[]
 "▶3 check._, check.any
 " Unconditionally accepts {argument}
 let s:args.check._=[]