Skip to content

Commit 161cc46

Browse files
authored
Merge pull request #45 from blueyed/pycompiler
[RDY] pycompiler: handle all reserved keywords
2 parents c278c26 + bf3f988 commit 161cc46

File tree

3 files changed

+458
-175
lines changed

3 files changed

+458
-175
lines changed

js/vimlparser.js

Lines changed: 221 additions & 84 deletions
Large diffs are not rendered by default.

py/pycompiler.vim

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,42 @@ let s:opprec[s:NODE_CURLYNAME] = 9
5858
let s:opprec[s:NODE_ENV] = 9
5959
let s:opprec[s:NODE_REG] = 9
6060

61+
" Reserved Python keywords (dict for faster lookup).
62+
let s:reserved_keywords = {
63+
\ 'False': 1,
64+
\ 'None': 1,
65+
\ 'True': 1,
66+
\ 'and': 1,
67+
\ 'as': 1,
68+
\ 'assert': 1,
69+
\ 'break': 1,
70+
\ 'class': 1,
71+
\ 'continue': 1,
72+
\ 'def': 1,
73+
\ 'del': 1,
74+
\ 'elif': 1,
75+
\ 'else': 1,
76+
\ 'except': 1,
77+
\ 'finally': 1,
78+
\ 'for': 1,
79+
\ 'from': 1,
80+
\ 'global': 1,
81+
\ 'if': 1,
82+
\ 'import': 1,
83+
\ 'in': 1,
84+
\ 'is': 1,
85+
\ 'lambda': 1,
86+
\ 'nonlocal': 1,
87+
\ 'not': 1,
88+
\ 'or': 1,
89+
\ 'pass': 1,
90+
\ 'raise': 1,
91+
\ 'return': 1,
92+
\ 'try': 1,
93+
\ 'while': 1,
94+
\ 'with': 1,
95+
\ 'yield': 1}
96+
6197
let s:PythonCompiler = {}
6298

6399
function s:PythonCompiler.new(...)
@@ -678,9 +714,6 @@ endfunction
678714
function s:PythonCompiler.compile_dot(node)
679715
let left = self.compile(a:node.left)
680716
let right = self.compile(a:node.right)
681-
if right =~ '^\(else\|finally\)$'
682-
let right = '_' . right
683-
endif
684717
return printf('%s.%s', left, right)
685718
endfunction
686719

@@ -748,6 +781,9 @@ function s:PythonCompiler.compile_identifier(node)
748781
elseif name =~ '^[sa]:'
749782
let name = name[2:]
750783
endif
784+
if has_key(s:reserved_keywords, name)
785+
let name .= '_'
786+
endif
751787
return name
752788
endfunction
753789

0 commit comments

Comments
 (0)