annotate runtime/autoload/pythoncomplete.vim @ 23041:139573353c6d v8.2.2067

patch 8.2.2067: cursor position in popup terminal is wrong Commit: https://github.com/vim/vim/commit/f5452691ba30e33b38c5b06c51ba40b58457d5d8 Author: Bram Moolenaar <Bram@vim.org> Date: Sat Nov 28 21:56:06 2020 +0100 patch 8.2.2067: cursor position in popup terminal is wrong Problem: Cursor position in popup terminal is wrong. Solution: Don't check the flags.
author Bram Moolenaar <Bram@vim.org>
date Sat, 28 Nov 2020 22:00:04 +0100
parents 17c4178f26ea
children 11b656e74444
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
827
fd1b3406fd1c updated for version 7.0d02
vimboss
parents:
diff changeset
1 "pythoncomplete.vim - Omni Completion for python
22565
17c4178f26ea Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 7183
diff changeset
2 " Maintainer: <vacancy>
17c4178f26ea Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 7183
diff changeset
3 " Previous Maintainer: Aaron Griffin <aaronmgriffin@gmail.com>
2120
f63ace015c63 Updated runtime and language files.
Bram Moolenaar <bram@zimbu.org>
parents: 1121
diff changeset
4 " Version: 0.9
22565
17c4178f26ea Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 7183
diff changeset
5 " Last Updated: 2020 Oct 9
1121
e63691e7c504 updated for version 7.1a
vimboss
parents: 838
diff changeset
6 "
e63691e7c504 updated for version 7.1a
vimboss
parents: 838
diff changeset
7 " Changes
e63691e7c504 updated for version 7.1a
vimboss
parents: 838
diff changeset
8 " TODO:
e63691e7c504 updated for version 7.1a
vimboss
parents: 838
diff changeset
9 " 'info' item output can use some formatting work
e63691e7c504 updated for version 7.1a
vimboss
parents: 838
diff changeset
10 " Add an "unsafe eval" mode, to allow for return type evaluation
e63691e7c504 updated for version 7.1a
vimboss
parents: 838
diff changeset
11 " Complete basic syntax along with import statements
e63691e7c504 updated for version 7.1a
vimboss
parents: 838
diff changeset
12 " i.e. "import url<c-x,c-o>"
e63691e7c504 updated for version 7.1a
vimboss
parents: 838
diff changeset
13 " Continue parsing on invalid line??
827
fd1b3406fd1c updated for version 7.0d02
vimboss
parents:
diff changeset
14 "
2120
f63ace015c63 Updated runtime and language files.
Bram Moolenaar <bram@zimbu.org>
parents: 1121
diff changeset
15 " v 0.9
f63ace015c63 Updated runtime and language files.
Bram Moolenaar <bram@zimbu.org>
parents: 1121
diff changeset
16 " * Fixed docstring parsing for classes and functions
f63ace015c63 Updated runtime and language files.
Bram Moolenaar <bram@zimbu.org>
parents: 1121
diff changeset
17 " * Fixed parsing of *args and **kwargs type arguments
f63ace015c63 Updated runtime and language files.
Bram Moolenaar <bram@zimbu.org>
parents: 1121
diff changeset
18 " * Better function param parsing to handle things like tuples and
f63ace015c63 Updated runtime and language files.
Bram Moolenaar <bram@zimbu.org>
parents: 1121
diff changeset
19 " lambda defaults args
f63ace015c63 Updated runtime and language files.
Bram Moolenaar <bram@zimbu.org>
parents: 1121
diff changeset
20 "
f63ace015c63 Updated runtime and language files.
Bram Moolenaar <bram@zimbu.org>
parents: 1121
diff changeset
21 " v 0.8
f63ace015c63 Updated runtime and language files.
Bram Moolenaar <bram@zimbu.org>
parents: 1121
diff changeset
22 " * Fixed an issue where the FIRST assignment was always used instead of
f63ace015c63 Updated runtime and language files.
Bram Moolenaar <bram@zimbu.org>
parents: 1121
diff changeset
23 " using a subsequent assignment for a variable
f63ace015c63 Updated runtime and language files.
Bram Moolenaar <bram@zimbu.org>
parents: 1121
diff changeset
24 " * Fixed a scoping issue when working inside a parameterless function
f63ace015c63 Updated runtime and language files.
Bram Moolenaar <bram@zimbu.org>
parents: 1121
diff changeset
25 "
f63ace015c63 Updated runtime and language files.
Bram Moolenaar <bram@zimbu.org>
parents: 1121
diff changeset
26 "
1121
e63691e7c504 updated for version 7.1a
vimboss
parents: 838
diff changeset
27 " v 0.7
e63691e7c504 updated for version 7.1a
vimboss
parents: 838
diff changeset
28 " * Fixed function list sorting (_ and __ at the bottom)
e63691e7c504 updated for version 7.1a
vimboss
parents: 838
diff changeset
29 " * Removed newline removal from docs. It appears vim handles these better in
e63691e7c504 updated for version 7.1a
vimboss
parents: 838
diff changeset
30 " recent patches
e63691e7c504 updated for version 7.1a
vimboss
parents: 838
diff changeset
31 "
e63691e7c504 updated for version 7.1a
vimboss
parents: 838
diff changeset
32 " v 0.6:
e63691e7c504 updated for version 7.1a
vimboss
parents: 838
diff changeset
33 " * Fixed argument completion
e63691e7c504 updated for version 7.1a
vimboss
parents: 838
diff changeset
34 " * Removed the 'kind' completions, as they are better indicated
e63691e7c504 updated for version 7.1a
vimboss
parents: 838
diff changeset
35 " with real syntax
e63691e7c504 updated for version 7.1a
vimboss
parents: 838
diff changeset
36 " * Added tuple assignment parsing (whoops, that was forgotten)
e63691e7c504 updated for version 7.1a
vimboss
parents: 838
diff changeset
37 " * Fixed import handling when flattening scope
e63691e7c504 updated for version 7.1a
vimboss
parents: 838
diff changeset
38 "
e63691e7c504 updated for version 7.1a
vimboss
parents: 838
diff changeset
39 " v 0.5:
838
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
40 " Yeah, I skipped a version number - 0.4 was never public.
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
41 " It was a bugfix version on top of 0.3. This is a complete
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
42 " rewrite.
827
fd1b3406fd1c updated for version 7.0d02
vimboss
parents:
diff changeset
43 "
fd1b3406fd1c updated for version 7.0d02
vimboss
parents:
diff changeset
44
fd1b3406fd1c updated for version 7.0d02
vimboss
parents:
diff changeset
45 if !has('python')
fd1b3406fd1c updated for version 7.0d02
vimboss
parents:
diff changeset
46 echo "Error: Required vim compiled with +python"
fd1b3406fd1c updated for version 7.0d02
vimboss
parents:
diff changeset
47 finish
fd1b3406fd1c updated for version 7.0d02
vimboss
parents:
diff changeset
48 endif
fd1b3406fd1c updated for version 7.0d02
vimboss
parents:
diff changeset
49
fd1b3406fd1c updated for version 7.0d02
vimboss
parents:
diff changeset
50 function! pythoncomplete#Complete(findstart, base)
fd1b3406fd1c updated for version 7.0d02
vimboss
parents:
diff changeset
51 "findstart = 1 when we need to get the text length
838
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
52 if a:findstart == 1
827
fd1b3406fd1c updated for version 7.0d02
vimboss
parents:
diff changeset
53 let line = getline('.')
fd1b3406fd1c updated for version 7.0d02
vimboss
parents:
diff changeset
54 let idx = col('.')
fd1b3406fd1c updated for version 7.0d02
vimboss
parents:
diff changeset
55 while idx > 0
fd1b3406fd1c updated for version 7.0d02
vimboss
parents:
diff changeset
56 let idx -= 1
838
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
57 let c = line[idx]
827
fd1b3406fd1c updated for version 7.0d02
vimboss
parents:
diff changeset
58 if c =~ '\w'
fd1b3406fd1c updated for version 7.0d02
vimboss
parents:
diff changeset
59 continue
fd1b3406fd1c updated for version 7.0d02
vimboss
parents:
diff changeset
60 elseif ! c =~ '\.'
1121
e63691e7c504 updated for version 7.1a
vimboss
parents: 838
diff changeset
61 let idx = -1
827
fd1b3406fd1c updated for version 7.0d02
vimboss
parents:
diff changeset
62 break
fd1b3406fd1c updated for version 7.0d02
vimboss
parents:
diff changeset
63 else
fd1b3406fd1c updated for version 7.0d02
vimboss
parents:
diff changeset
64 break
fd1b3406fd1c updated for version 7.0d02
vimboss
parents:
diff changeset
65 endif
fd1b3406fd1c updated for version 7.0d02
vimboss
parents:
diff changeset
66 endwhile
fd1b3406fd1c updated for version 7.0d02
vimboss
parents:
diff changeset
67
fd1b3406fd1c updated for version 7.0d02
vimboss
parents:
diff changeset
68 return idx
fd1b3406fd1c updated for version 7.0d02
vimboss
parents:
diff changeset
69 "findstart = 0 when we need to return the list of completions
fd1b3406fd1c updated for version 7.0d02
vimboss
parents:
diff changeset
70 else
838
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
71 "vim no longer moves the cursor upon completion... fix that
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
72 let line = getline('.')
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
73 let idx = col('.')
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
74 let cword = ''
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
75 while idx > 0
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
76 let idx -= 1
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
77 let c = line[idx]
2120
f63ace015c63 Updated runtime and language files.
Bram Moolenaar <bram@zimbu.org>
parents: 1121
diff changeset
78 if c =~ '\w' || c =~ '\.'
838
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
79 let cword = c . cword
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
80 continue
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
81 elseif strlen(cword) > 0 || idx == 0
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
82 break
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
83 endif
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
84 endwhile
22565
17c4178f26ea Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 7183
diff changeset
85 execute "python vimcomplete('" . escape(cword, "'") . "', '" . escape(a:base, "'") . "')"
827
fd1b3406fd1c updated for version 7.0d02
vimboss
parents:
diff changeset
86 return g:pythoncomplete_completions
fd1b3406fd1c updated for version 7.0d02
vimboss
parents:
diff changeset
87 endif
fd1b3406fd1c updated for version 7.0d02
vimboss
parents:
diff changeset
88 endfunction
fd1b3406fd1c updated for version 7.0d02
vimboss
parents:
diff changeset
89
fd1b3406fd1c updated for version 7.0d02
vimboss
parents:
diff changeset
90 function! s:DefPython()
fd1b3406fd1c updated for version 7.0d02
vimboss
parents:
diff changeset
91 python << PYTHONEOF
838
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
92 import sys, tokenize, cStringIO, types
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
93 from token import NAME, DEDENT, NEWLINE, STRING
827
fd1b3406fd1c updated for version 7.0d02
vimboss
parents:
diff changeset
94
838
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
95 debugstmts=[]
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
96 def dbg(s): debugstmts.append(s)
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
97 def showdbg():
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
98 for d in debugstmts: print "DBG: %s " % d
827
fd1b3406fd1c updated for version 7.0d02
vimboss
parents:
diff changeset
99
838
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
100 def vimcomplete(context,match):
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
101 global debugstmts
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
102 debugstmts = []
827
fd1b3406fd1c updated for version 7.0d02
vimboss
parents:
diff changeset
103 try:
838
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
104 import vim
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
105 def complsort(x,y):
1121
e63691e7c504 updated for version 7.1a
vimboss
parents: 838
diff changeset
106 try:
e63691e7c504 updated for version 7.1a
vimboss
parents: 838
diff changeset
107 xa = x['abbr']
e63691e7c504 updated for version 7.1a
vimboss
parents: 838
diff changeset
108 ya = y['abbr']
e63691e7c504 updated for version 7.1a
vimboss
parents: 838
diff changeset
109 if xa[0] == '_':
e63691e7c504 updated for version 7.1a
vimboss
parents: 838
diff changeset
110 if xa[1] == '_' and ya[0:2] == '__':
e63691e7c504 updated for version 7.1a
vimboss
parents: 838
diff changeset
111 return xa > ya
e63691e7c504 updated for version 7.1a
vimboss
parents: 838
diff changeset
112 elif ya[0:2] == '__':
e63691e7c504 updated for version 7.1a
vimboss
parents: 838
diff changeset
113 return -1
e63691e7c504 updated for version 7.1a
vimboss
parents: 838
diff changeset
114 elif y[0] == '_':
e63691e7c504 updated for version 7.1a
vimboss
parents: 838
diff changeset
115 return xa > ya
e63691e7c504 updated for version 7.1a
vimboss
parents: 838
diff changeset
116 else:
e63691e7c504 updated for version 7.1a
vimboss
parents: 838
diff changeset
117 return 1
e63691e7c504 updated for version 7.1a
vimboss
parents: 838
diff changeset
118 elif ya[0] == '_':
e63691e7c504 updated for version 7.1a
vimboss
parents: 838
diff changeset
119 return -1
e63691e7c504 updated for version 7.1a
vimboss
parents: 838
diff changeset
120 else:
e63691e7c504 updated for version 7.1a
vimboss
parents: 838
diff changeset
121 return xa > ya
e63691e7c504 updated for version 7.1a
vimboss
parents: 838
diff changeset
122 except:
e63691e7c504 updated for version 7.1a
vimboss
parents: 838
diff changeset
123 return 0
838
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
124 cmpl = Completer()
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
125 cmpl.evalsource('\n'.join(vim.current.buffer),vim.eval("line('.')"))
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
126 all = cmpl.get_completions(context,match)
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
127 all.sort(complsort)
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
128 dictstr = '['
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
129 # have to do this for double quoting
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
130 for cmpl in all:
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
131 dictstr += '{'
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
132 for x in cmpl: dictstr += '"%s":"%s",' % (x,cmpl[x])
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
133 dictstr += '"icase":0},'
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
134 if dictstr[-1] == ',': dictstr = dictstr[:-1]
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
135 dictstr += ']'
1121
e63691e7c504 updated for version 7.1a
vimboss
parents: 838
diff changeset
136 #dbg("dict: %s" % dictstr)
838
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
137 vim.command("silent let g:pythoncomplete_completions = %s" % dictstr)
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
138 #dbg("Completion dict:\n%s" % all)
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
139 except vim.error:
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
140 dbg("VIM Error: %s" % vim.error)
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
141
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
142 class Completer(object):
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
143 def __init__(self):
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
144 self.compldict = {}
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
145 self.parser = PyParser()
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
146
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
147 def evalsource(self,text,line=0):
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
148 sc = self.parser.parse(text,line)
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
149 src = sc.get_code()
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
150 dbg("source: %s" % src)
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
151 try: exec(src) in self.compldict
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
152 except: dbg("parser: %s, %s" % (sys.exc_info()[0],sys.exc_info()[1]))
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
153 for l in sc.locals:
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
154 try: exec(l) in self.compldict
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
155 except: dbg("locals: %s, %s [%s]" % (sys.exc_info()[0],sys.exc_info()[1],l))
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
156
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
157 def _cleanstr(self,doc):
1121
e63691e7c504 updated for version 7.1a
vimboss
parents: 838
diff changeset
158 return doc.replace('"',' ').replace("'",' ')
838
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
159
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
160 def get_arguments(self,func_obj):
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
161 def _ctor(obj):
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
162 try: return class_ob.__init__.im_func
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
163 except AttributeError:
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
164 for base in class_ob.__bases__:
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
165 rc = _find_constructor(base)
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
166 if rc is not None: return rc
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
167 return None
827
fd1b3406fd1c updated for version 7.0d02
vimboss
parents:
diff changeset
168
838
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
169 arg_offset = 1
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
170 if type(func_obj) == types.ClassType: func_obj = _ctor(func_obj)
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
171 elif type(func_obj) == types.MethodType: func_obj = func_obj.im_func
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
172 else: arg_offset = 0
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
173
1121
e63691e7c504 updated for version 7.1a
vimboss
parents: 838
diff changeset
174 arg_text=''
838
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
175 if type(func_obj) in [types.FunctionType, types.LambdaType]:
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
176 try:
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
177 cd = func_obj.func_code
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
178 real_args = cd.co_varnames[arg_offset:cd.co_argcount]
1121
e63691e7c504 updated for version 7.1a
vimboss
parents: 838
diff changeset
179 defaults = func_obj.func_defaults or ''
e63691e7c504 updated for version 7.1a
vimboss
parents: 838
diff changeset
180 defaults = map(lambda name: "=%s" % name, defaults)
838
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
181 defaults = [""] * (len(real_args)-len(defaults)) + defaults
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
182 items = map(lambda a,d: a+d, real_args, defaults)
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
183 if func_obj.func_code.co_flags & 0x4:
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
184 items.append("...")
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
185 if func_obj.func_code.co_flags & 0x8:
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
186 items.append("***")
1121
e63691e7c504 updated for version 7.1a
vimboss
parents: 838
diff changeset
187 arg_text = (','.join(items)) + ')'
838
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
188
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
189 except:
1121
e63691e7c504 updated for version 7.1a
vimboss
parents: 838
diff changeset
190 dbg("arg completion: %s: %s" % (sys.exc_info()[0],sys.exc_info()[1]))
838
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
191 pass
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
192 if len(arg_text) == 0:
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
193 # The doc string sometimes contains the function signature
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
194 # this works for alot of C modules that are part of the
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
195 # standard library
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
196 doc = func_obj.__doc__
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
197 if doc:
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
198 doc = doc.lstrip()
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
199 pos = doc.find('\n')
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
200 if pos > 0:
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
201 sigline = doc[:pos]
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
202 lidx = sigline.find('(')
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
203 ridx = sigline.find(')')
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
204 if lidx > 0 and ridx > 0:
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
205 arg_text = sigline[lidx+1:ridx] + ')'
1121
e63691e7c504 updated for version 7.1a
vimboss
parents: 838
diff changeset
206 if len(arg_text) == 0: arg_text = ')'
838
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
207 return arg_text
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
208
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
209 def get_completions(self,context,match):
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
210 dbg("get_completions('%s','%s')" % (context,match))
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
211 stmt = ''
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
212 if context: stmt += str(context)
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
213 if match: stmt += str(match)
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
214 try:
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
215 result = None
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
216 all = {}
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
217 ridx = stmt.rfind('.')
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
218 if len(stmt) > 0 and stmt[-1] == '(':
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
219 result = eval(_sanitize(stmt[:-1]), self.compldict)
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
220 doc = result.__doc__
2120
f63ace015c63 Updated runtime and language files.
Bram Moolenaar <bram@zimbu.org>
parents: 1121
diff changeset
221 if doc is None: doc = ''
1121
e63691e7c504 updated for version 7.1a
vimboss
parents: 838
diff changeset
222 args = self.get_arguments(result)
e63691e7c504 updated for version 7.1a
vimboss
parents: 838
diff changeset
223 return [{'word':self._cleanstr(args),'info':self._cleanstr(doc)}]
838
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
224 elif ridx == -1:
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
225 match = stmt
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
226 all = self.compldict
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
227 else:
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
228 match = stmt[ridx+1:]
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
229 stmt = _sanitize(stmt[:ridx])
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
230 result = eval(stmt, self.compldict)
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
231 all = dir(result)
827
fd1b3406fd1c updated for version 7.0d02
vimboss
parents:
diff changeset
232
838
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
233 dbg("completing: stmt:%s" % stmt)
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
234 completions = []
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
235
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
236 try: maindoc = result.__doc__
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
237 except: maindoc = ' '
2120
f63ace015c63 Updated runtime and language files.
Bram Moolenaar <bram@zimbu.org>
parents: 1121
diff changeset
238 if maindoc is None: maindoc = ' '
838
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
239 for m in all:
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
240 if m == "_PyCmplNoType": continue #this is internal
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
241 try:
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
242 dbg('possible completion: %s' % m)
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
243 if m.find(match) == 0:
2120
f63ace015c63 Updated runtime and language files.
Bram Moolenaar <bram@zimbu.org>
parents: 1121
diff changeset
244 if result is None: inst = all[m]
838
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
245 else: inst = getattr(result,m)
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
246 try: doc = inst.__doc__
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
247 except: doc = maindoc
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
248 typestr = str(inst)
2120
f63ace015c63 Updated runtime and language files.
Bram Moolenaar <bram@zimbu.org>
parents: 1121
diff changeset
249 if doc is None or doc == '': doc = maindoc
838
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
250
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
251 wrd = m[len(match):]
1121
e63691e7c504 updated for version 7.1a
vimboss
parents: 838
diff changeset
252 c = {'word':wrd, 'abbr':m, 'info':self._cleanstr(doc)}
838
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
253 if "function" in typestr:
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
254 c['word'] += '('
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
255 c['abbr'] += '(' + self._cleanstr(self.get_arguments(inst))
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
256 elif "method" in typestr:
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
257 c['word'] += '('
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
258 c['abbr'] += '(' + self._cleanstr(self.get_arguments(inst))
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
259 elif "module" in typestr:
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
260 c['word'] += '.'
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
261 elif "class" in typestr:
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
262 c['word'] += '('
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
263 c['abbr'] += '('
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
264 completions.append(c)
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
265 except:
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
266 i = sys.exc_info()
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
267 dbg("inner completion: %s,%s [stmt='%s']" % (i[0],i[1],stmt))
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
268 return completions
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
269 except:
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
270 i = sys.exc_info()
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
271 dbg("completion: %s,%s [stmt='%s']" % (i[0],i[1],stmt))
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
272 return []
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
273
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
274 class Scope(object):
2120
f63ace015c63 Updated runtime and language files.
Bram Moolenaar <bram@zimbu.org>
parents: 1121
diff changeset
275 def __init__(self,name,indent,docstr=''):
838
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
276 self.subscopes = []
2120
f63ace015c63 Updated runtime and language files.
Bram Moolenaar <bram@zimbu.org>
parents: 1121
diff changeset
277 self.docstr = docstr
838
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
278 self.locals = []
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
279 self.parent = None
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
280 self.name = name
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
281 self.indent = indent
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
282
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
283 def add(self,sub):
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
284 #print 'push scope: [%s@%s]' % (sub.name,sub.indent)
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
285 sub.parent = self
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
286 self.subscopes.append(sub)
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
287 return sub
827
fd1b3406fd1c updated for version 7.0d02
vimboss
parents:
diff changeset
288
838
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
289 def doc(self,str):
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
290 """ Clean up a docstring """
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
291 d = str.replace('\n',' ')
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
292 d = d.replace('\t',' ')
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
293 while d.find(' ') > -1: d = d.replace(' ',' ')
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
294 while d[0] in '"\'\t ': d = d[1:]
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
295 while d[-1] in '"\'\t ': d = d[:-1]
2120
f63ace015c63 Updated runtime and language files.
Bram Moolenaar <bram@zimbu.org>
parents: 1121
diff changeset
296 dbg("Scope(%s)::docstr = %s" % (self,d))
838
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
297 self.docstr = d
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
298
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
299 def local(self,loc):
2120
f63ace015c63 Updated runtime and language files.
Bram Moolenaar <bram@zimbu.org>
parents: 1121
diff changeset
300 self._checkexisting(loc)
f63ace015c63 Updated runtime and language files.
Bram Moolenaar <bram@zimbu.org>
parents: 1121
diff changeset
301 self.locals.append(loc)
838
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
302
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
303 def copy_decl(self,indent=0):
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
304 """ Copy a scope's declaration only, at the specified indent level - not local variables """
2120
f63ace015c63 Updated runtime and language files.
Bram Moolenaar <bram@zimbu.org>
parents: 1121
diff changeset
305 return Scope(self.name,indent,self.docstr)
838
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
306
2120
f63ace015c63 Updated runtime and language files.
Bram Moolenaar <bram@zimbu.org>
parents: 1121
diff changeset
307 def _checkexisting(self,test):
838
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
308 "Convienance function... keep out duplicates"
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
309 if test.find('=') > -1:
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
310 var = test.split('=')[0].strip()
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
311 for l in self.locals:
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
312 if l.find('=') > -1 and var == l.split('=')[0].strip():
2120
f63ace015c63 Updated runtime and language files.
Bram Moolenaar <bram@zimbu.org>
parents: 1121
diff changeset
313 self.locals.remove(l)
827
fd1b3406fd1c updated for version 7.0d02
vimboss
parents:
diff changeset
314
838
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
315 def get_code(self):
2120
f63ace015c63 Updated runtime and language files.
Bram Moolenaar <bram@zimbu.org>
parents: 1121
diff changeset
316 str = ""
f63ace015c63 Updated runtime and language files.
Bram Moolenaar <bram@zimbu.org>
parents: 1121
diff changeset
317 if len(self.docstr) > 0: str += '"""'+self.docstr+'"""\n'
1121
e63691e7c504 updated for version 7.1a
vimboss
parents: 838
diff changeset
318 for l in self.locals:
e63691e7c504 updated for version 7.1a
vimboss
parents: 838
diff changeset
319 if l.startswith('import'): str += l+'\n'
838
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
320 str += 'class _PyCmplNoType:\n def __getattr__(self,name):\n return None\n'
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
321 for sub in self.subscopes:
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
322 str += sub.get_code()
1121
e63691e7c504 updated for version 7.1a
vimboss
parents: 838
diff changeset
323 for l in self.locals:
e63691e7c504 updated for version 7.1a
vimboss
parents: 838
diff changeset
324 if not l.startswith('import'): str += l+'\n'
838
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
325
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
326 return str
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
327
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
328 def pop(self,indent):
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
329 #print 'pop scope: [%s] to [%s]' % (self.indent,indent)
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
330 outer = self
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
331 while outer.parent != None and outer.indent >= indent:
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
332 outer = outer.parent
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
333 return outer
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
334
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
335 def currentindent(self):
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
336 #print 'parse current indent: %s' % self.indent
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
337 return ' '*self.indent
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
338
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
339 def childindent(self):
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
340 #print 'parse child indent: [%s]' % (self.indent+1)
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
341 return ' '*(self.indent+1)
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
342
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
343 class Class(Scope):
2120
f63ace015c63 Updated runtime and language files.
Bram Moolenaar <bram@zimbu.org>
parents: 1121
diff changeset
344 def __init__(self, name, supers, indent, docstr=''):
f63ace015c63 Updated runtime and language files.
Bram Moolenaar <bram@zimbu.org>
parents: 1121
diff changeset
345 Scope.__init__(self,name,indent, docstr)
838
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
346 self.supers = supers
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
347 def copy_decl(self,indent=0):
2120
f63ace015c63 Updated runtime and language files.
Bram Moolenaar <bram@zimbu.org>
parents: 1121
diff changeset
348 c = Class(self.name,self.supers,indent, self.docstr)
838
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
349 for s in self.subscopes:
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
350 c.add(s.copy_decl(indent+1))
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
351 return c
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
352 def get_code(self):
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
353 str = '%sclass %s' % (self.currentindent(),self.name)
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
354 if len(self.supers) > 0: str += '(%s)' % ','.join(self.supers)
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
355 str += ':\n'
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
356 if len(self.docstr) > 0: str += self.childindent()+'"""'+self.docstr+'"""\n'
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
357 if len(self.subscopes) > 0:
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
358 for s in self.subscopes: str += s.get_code()
827
fd1b3406fd1c updated for version 7.0d02
vimboss
parents:
diff changeset
359 else:
838
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
360 str += '%spass\n' % self.childindent()
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
361 return str
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
362
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
363
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
364 class Function(Scope):
2120
f63ace015c63 Updated runtime and language files.
Bram Moolenaar <bram@zimbu.org>
parents: 1121
diff changeset
365 def __init__(self, name, params, indent, docstr=''):
f63ace015c63 Updated runtime and language files.
Bram Moolenaar <bram@zimbu.org>
parents: 1121
diff changeset
366 Scope.__init__(self,name,indent, docstr)
838
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
367 self.params = params
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
368 def copy_decl(self,indent=0):
2120
f63ace015c63 Updated runtime and language files.
Bram Moolenaar <bram@zimbu.org>
parents: 1121
diff changeset
369 return Function(self.name,self.params,indent, self.docstr)
838
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
370 def get_code(self):
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
371 str = "%sdef %s(%s):\n" % \
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
372 (self.currentindent(),self.name,','.join(self.params))
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
373 if len(self.docstr) > 0: str += self.childindent()+'"""'+self.docstr+'"""\n'
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
374 str += "%spass\n" % self.childindent()
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
375 return str
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
376
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
377 class PyParser:
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
378 def __init__(self):
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
379 self.top = Scope('global',0)
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
380 self.scope = self.top
7183
ffad29dc7eee commit https://github.com/vim/vim/commit/a0f849ee40cbea3c889345256786b640b0becca2
Christian Brabandt <cb@256bit.org>
parents: 2120
diff changeset
381 self.parserline = 0
838
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
382
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
383 def _parsedotname(self,pre=None):
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
384 #returns (dottedname, nexttoken)
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
385 name = []
2120
f63ace015c63 Updated runtime and language files.
Bram Moolenaar <bram@zimbu.org>
parents: 1121
diff changeset
386 if pre is None:
838
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
387 tokentype, token, indent = self.next()
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
388 if tokentype != NAME and token != '*':
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
389 return ('', token)
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
390 else: token = pre
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
391 name.append(token)
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
392 while True:
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
393 tokentype, token, indent = self.next()
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
394 if token != '.': break
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
395 tokentype, token, indent = self.next()
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
396 if tokentype != NAME: break
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
397 name.append(token)
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
398 return (".".join(name), token)
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
399
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
400 def _parseimportlist(self):
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
401 imports = []
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
402 while True:
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
403 name, token = self._parsedotname()
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
404 if not name: break
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
405 name2 = ''
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
406 if token == 'as': name2, token = self._parsedotname()
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
407 imports.append((name, name2))
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
408 while token != "," and "\n" not in token:
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
409 tokentype, token, indent = self.next()
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
410 if token != ",": break
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
411 return imports
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
412
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
413 def _parenparse(self):
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
414 name = ''
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
415 names = []
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
416 level = 1
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
417 while True:
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
418 tokentype, token, indent = self.next()
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
419 if token in (')', ',') and level == 1:
2120
f63ace015c63 Updated runtime and language files.
Bram Moolenaar <bram@zimbu.org>
parents: 1121
diff changeset
420 if '=' not in name: name = name.replace(' ', '')
f63ace015c63 Updated runtime and language files.
Bram Moolenaar <bram@zimbu.org>
parents: 1121
diff changeset
421 names.append(name.strip())
838
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
422 name = ''
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
423 if token == '(':
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
424 level += 1
2120
f63ace015c63 Updated runtime and language files.
Bram Moolenaar <bram@zimbu.org>
parents: 1121
diff changeset
425 name += "("
838
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
426 elif token == ')':
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
427 level -= 1
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
428 if level == 0: break
2120
f63ace015c63 Updated runtime and language files.
Bram Moolenaar <bram@zimbu.org>
parents: 1121
diff changeset
429 else: name += ")"
838
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
430 elif token == ',' and level == 1:
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
431 pass
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
432 else:
2120
f63ace015c63 Updated runtime and language files.
Bram Moolenaar <bram@zimbu.org>
parents: 1121
diff changeset
433 name += "%s " % str(token)
838
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
434 return names
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
435
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
436 def _parsefunction(self,indent):
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
437 self.scope=self.scope.pop(indent)
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
438 tokentype, fname, ind = self.next()
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
439 if tokentype != NAME: return None
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
440
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
441 tokentype, open, ind = self.next()
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
442 if open != '(': return None
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
443 params=self._parenparse()
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
444
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
445 tokentype, colon, ind = self.next()
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
446 if colon != ':': return None
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
447
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
448 return Function(fname,params,indent)
827
fd1b3406fd1c updated for version 7.0d02
vimboss
parents:
diff changeset
449
838
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
450 def _parseclass(self,indent):
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
451 self.scope=self.scope.pop(indent)
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
452 tokentype, cname, ind = self.next()
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
453 if tokentype != NAME: return None
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
454
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
455 super = []
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
456 tokentype, next, ind = self.next()
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
457 if next == '(':
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
458 super=self._parenparse()
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
459 elif next != ':': return None
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
460
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
461 return Class(cname,super,indent)
827
fd1b3406fd1c updated for version 7.0d02
vimboss
parents:
diff changeset
462
838
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
463 def _parseassignment(self):
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
464 assign=''
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
465 tokentype, token, indent = self.next()
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
466 if tokentype == tokenize.STRING or token == 'str':
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
467 return '""'
1121
e63691e7c504 updated for version 7.1a
vimboss
parents: 838
diff changeset
468 elif token == '(' or token == 'tuple':
e63691e7c504 updated for version 7.1a
vimboss
parents: 838
diff changeset
469 return '()'
838
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
470 elif token == '[' or token == 'list':
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
471 return '[]'
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
472 elif token == '{' or token == 'dict':
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
473 return '{}'
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
474 elif tokentype == tokenize.NUMBER:
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
475 return '0'
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
476 elif token == 'open' or token == 'file':
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
477 return 'file'
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
478 elif token == 'None':
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
479 return '_PyCmplNoType()'
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
480 elif token == 'type':
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
481 return 'type(_PyCmplNoType)' #only for method resolution
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
482 else:
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
483 assign += token
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
484 level = 0
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
485 while True:
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
486 tokentype, token, indent = self.next()
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
487 if token in ('(','{','['):
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
488 level += 1
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
489 elif token in (']','}',')'):
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
490 level -= 1
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
491 if level == 0: break
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
492 elif level == 0:
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
493 if token in (';','\n'): break
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
494 assign += token
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
495 return "%s" % assign
827
fd1b3406fd1c updated for version 7.0d02
vimboss
parents:
diff changeset
496
838
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
497 def next(self):
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
498 type, token, (lineno, indent), end, self.parserline = self.gen.next()
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
499 if lineno == self.curline:
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
500 #print 'line found [%s] scope=%s' % (line.replace('\n',''),self.scope.name)
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
501 self.currentscope = self.scope
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
502 return (type, token, indent)
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
503
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
504 def _adjustvisibility(self):
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
505 newscope = Scope('result',0)
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
506 scp = self.currentscope
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
507 while scp != None:
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
508 if type(scp) == Function:
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
509 slice = 0
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
510 #Handle 'self' params
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
511 if scp.parent != None and type(scp.parent) == Class:
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
512 slice = 1
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
513 newscope.local('%s = %s' % (scp.params[0],scp.parent.name))
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
514 for p in scp.params[slice:]:
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
515 i = p.find('=')
2120
f63ace015c63 Updated runtime and language files.
Bram Moolenaar <bram@zimbu.org>
parents: 1121
diff changeset
516 if len(p) == 0: continue
f63ace015c63 Updated runtime and language files.
Bram Moolenaar <bram@zimbu.org>
parents: 1121
diff changeset
517 pvar = ''
f63ace015c63 Updated runtime and language files.
Bram Moolenaar <bram@zimbu.org>
parents: 1121
diff changeset
518 ptype = ''
838
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
519 if i == -1:
2120
f63ace015c63 Updated runtime and language files.
Bram Moolenaar <bram@zimbu.org>
parents: 1121
diff changeset
520 pvar = p
f63ace015c63 Updated runtime and language files.
Bram Moolenaar <bram@zimbu.org>
parents: 1121
diff changeset
521 ptype = '_PyCmplNoType()'
838
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
522 else:
2120
f63ace015c63 Updated runtime and language files.
Bram Moolenaar <bram@zimbu.org>
parents: 1121
diff changeset
523 pvar = p[:i]
f63ace015c63 Updated runtime and language files.
Bram Moolenaar <bram@zimbu.org>
parents: 1121
diff changeset
524 ptype = _sanitize(p[i+1:])
f63ace015c63 Updated runtime and language files.
Bram Moolenaar <bram@zimbu.org>
parents: 1121
diff changeset
525 if pvar.startswith('**'):
f63ace015c63 Updated runtime and language files.
Bram Moolenaar <bram@zimbu.org>
parents: 1121
diff changeset
526 pvar = pvar[2:]
f63ace015c63 Updated runtime and language files.
Bram Moolenaar <bram@zimbu.org>
parents: 1121
diff changeset
527 ptype = '{}'
f63ace015c63 Updated runtime and language files.
Bram Moolenaar <bram@zimbu.org>
parents: 1121
diff changeset
528 elif pvar.startswith('*'):
f63ace015c63 Updated runtime and language files.
Bram Moolenaar <bram@zimbu.org>
parents: 1121
diff changeset
529 pvar = pvar[1:]
f63ace015c63 Updated runtime and language files.
Bram Moolenaar <bram@zimbu.org>
parents: 1121
diff changeset
530 ptype = '[]'
f63ace015c63 Updated runtime and language files.
Bram Moolenaar <bram@zimbu.org>
parents: 1121
diff changeset
531
f63ace015c63 Updated runtime and language files.
Bram Moolenaar <bram@zimbu.org>
parents: 1121
diff changeset
532 newscope.local('%s = %s' % (pvar,ptype))
838
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
533
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
534 for s in scp.subscopes:
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
535 ns = s.copy_decl(0)
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
536 newscope.add(ns)
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
537 for l in scp.locals: newscope.local(l)
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
538 scp = scp.parent
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
539
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
540 self.currentscope = newscope
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
541 return self.currentscope
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
542
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
543 #p.parse(vim.current.buffer[:],vim.eval("line('.')"))
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
544 def parse(self,text,curline=0):
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
545 self.curline = int(curline)
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
546 buf = cStringIO.StringIO(''.join(text) + '\n')
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
547 self.gen = tokenize.generate_tokens(buf.readline)
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
548 self.currentscope = self.scope
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
549
827
fd1b3406fd1c updated for version 7.0d02
vimboss
parents:
diff changeset
550 try:
838
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
551 freshscope=True
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
552 while True:
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
553 tokentype, token, indent = self.next()
1121
e63691e7c504 updated for version 7.1a
vimboss
parents: 838
diff changeset
554 #dbg( 'main: token=[%s] indent=[%s]' % (token,indent))
827
fd1b3406fd1c updated for version 7.0d02
vimboss
parents:
diff changeset
555
1121
e63691e7c504 updated for version 7.1a
vimboss
parents: 838
diff changeset
556 if tokentype == DEDENT or token == "pass":
838
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
557 self.scope = self.scope.pop(indent)
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
558 elif token == 'def':
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
559 func = self._parsefunction(indent)
2120
f63ace015c63 Updated runtime and language files.
Bram Moolenaar <bram@zimbu.org>
parents: 1121
diff changeset
560 if func is None:
838
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
561 print "function: syntax error..."
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
562 continue
2120
f63ace015c63 Updated runtime and language files.
Bram Moolenaar <bram@zimbu.org>
parents: 1121
diff changeset
563 dbg("new scope: function")
838
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
564 freshscope = True
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
565 self.scope = self.scope.add(func)
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
566 elif token == 'class':
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
567 cls = self._parseclass(indent)
2120
f63ace015c63 Updated runtime and language files.
Bram Moolenaar <bram@zimbu.org>
parents: 1121
diff changeset
568 if cls is None:
838
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
569 print "class: syntax error..."
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
570 continue
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
571 freshscope = True
2120
f63ace015c63 Updated runtime and language files.
Bram Moolenaar <bram@zimbu.org>
parents: 1121
diff changeset
572 dbg("new scope: class")
838
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
573 self.scope = self.scope.add(cls)
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
574
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
575 elif token == 'import':
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
576 imports = self._parseimportlist()
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
577 for mod, alias in imports:
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
578 loc = "import %s" % mod
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
579 if len(alias) > 0: loc += " as %s" % alias
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
580 self.scope.local(loc)
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
581 freshscope = False
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
582 elif token == 'from':
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
583 mod, token = self._parsedotname()
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
584 if not mod or token != "import":
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
585 print "from: syntax error..."
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
586 continue
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
587 names = self._parseimportlist()
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
588 for name, alias in names:
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
589 loc = "from %s import %s" % (mod,name)
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
590 if len(alias) > 0: loc += " as %s" % alias
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
591 self.scope.local(loc)
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
592 freshscope = False
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
593 elif tokentype == STRING:
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
594 if freshscope: self.scope.doc(token)
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
595 elif tokentype == NAME:
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
596 name,token = self._parsedotname(token)
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
597 if token == '=':
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
598 stmt = self._parseassignment()
2120
f63ace015c63 Updated runtime and language files.
Bram Moolenaar <bram@zimbu.org>
parents: 1121
diff changeset
599 dbg("parseassignment: %s = %s" % (name, stmt))
838
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
600 if stmt != None:
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
601 self.scope.local("%s = %s" % (name,stmt))
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
602 freshscope = False
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
603 except StopIteration: #thrown on EOF
827
fd1b3406fd1c updated for version 7.0d02
vimboss
parents:
diff changeset
604 pass
838
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
605 except:
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
606 dbg("parse error: %s, %s @ %s" %
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
607 (sys.exc_info()[0], sys.exc_info()[1], self.parserline))
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
608 return self._adjustvisibility()
827
fd1b3406fd1c updated for version 7.0d02
vimboss
parents:
diff changeset
609
838
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
610 def _sanitize(str):
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
611 val = ''
827
fd1b3406fd1c updated for version 7.0d02
vimboss
parents:
diff changeset
612 level = 0
838
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
613 for c in str:
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
614 if c in ('(','{','['):
827
fd1b3406fd1c updated for version 7.0d02
vimboss
parents:
diff changeset
615 level += 1
838
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
616 elif c in (']','}',')'):
827
fd1b3406fd1c updated for version 7.0d02
vimboss
parents:
diff changeset
617 level -= 1
fd1b3406fd1c updated for version 7.0d02
vimboss
parents:
diff changeset
618 elif level == 0:
838
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
619 val += c
8e5830943bff updated for version 7.0e04
vimboss
parents: 827
diff changeset
620 return val
827
fd1b3406fd1c updated for version 7.0d02
vimboss
parents:
diff changeset
621
fd1b3406fd1c updated for version 7.0d02
vimboss
parents:
diff changeset
622 sys.path.extend(['.','..'])
fd1b3406fd1c updated for version 7.0d02
vimboss
parents:
diff changeset
623 PYTHONEOF
fd1b3406fd1c updated for version 7.0d02
vimboss
parents:
diff changeset
624 endfunction
fd1b3406fd1c updated for version 7.0d02
vimboss
parents:
diff changeset
625
fd1b3406fd1c updated for version 7.0d02
vimboss
parents:
diff changeset
626 call s:DefPython()
fd1b3406fd1c updated for version 7.0d02
vimboss
parents:
diff changeset
627 " vim: set et ts=4: