Skip to content

Commit 67c3322

Browse files
committed
Scope python2-only builtins with variable.legacy.builtin.python
1 parent 513d84c commit 67c3322

File tree

6 files changed

+129
-36
lines changed

6 files changed

+129
-36
lines changed

grammars/MagicPython.cson

+30-15
Original file line numberDiff line numberDiff line change
@@ -1461,21 +1461,36 @@ repository:
14611461
14621462
'''
14631463
"builtin-functions":
1464-
name: "support.function.builtin.python"
1465-
match: '''
1466-
(?x)
1467-
(?<!\\.)\\b(
1468-
__import__ | abs | all | any | apply | ascii | bin | callable | chr
1469-
| compile | copyright | credits | delattr | dir | divmod
1470-
| enumerate | eval | exec | exit | filter | format | getattr
1471-
| globals | hasattr | hash | help | hex | id | input
1472-
| isinstance | issubclass | iter | len | license | locals | map
1473-
| max | memoryview | min | next | oct | open | ord | pow | print
1474-
| quit | range | reload | repr | reversed | round
1475-
| setattr | sorted | sum | vars | zip
1476-
)\\b
1477-
1478-
'''
1464+
patterns: [
1465+
{
1466+
name: "support.function.builtin.python"
1467+
match: '''
1468+
(?x)
1469+
(?<!\\.)\\b(
1470+
__import__ | abs | all | any | apply | ascii | bin | callable
1471+
| chr | compile | copyright | credits | delattr | dir | divmod
1472+
| enumerate | eval | exec | exit | filter | format | getattr
1473+
| globals | hasattr | hash | help | hex | id | input
1474+
| isinstance | issubclass | iter | len | license | locals | map
1475+
| max | memoryview | min | next | oct | open | ord | pow | print
1476+
| quit | range | reload | repr | reversed | round
1477+
| setattr | sorted | sum | vars | zip
1478+
)\\b
1479+
1480+
'''
1481+
}
1482+
{
1483+
name: "variable.legacy.builtin.python"
1484+
match: '''
1485+
(?x)
1486+
(?<!\\.)\\b(
1487+
file | reduce | intern | raw_input | unicode | cmp | basestring
1488+
| execfile | long | xrange
1489+
)\\b
1490+
1491+
'''
1492+
}
1493+
]
14791494
"builtin-types":
14801495
name: "support.type.python"
14811496
match: '''

grammars/MagicPython.syntax.yaml

+23-13
Original file line numberDiff line numberDiff line change
@@ -973,19 +973,29 @@ repository:
973973
)\b
974974
975975
builtin-functions:
976-
name: support.function.builtin.python
977-
match: |
978-
(?x)
979-
(?<!\.)\b(
980-
__import__ | abs | all | any | apply | ascii | bin | callable | chr
981-
| compile | copyright | credits | delattr | dir | divmod
982-
| enumerate | eval | exec | exit | filter | format | getattr
983-
| globals | hasattr | hash | help | hex | id | input
984-
| isinstance | issubclass | iter | len | license | locals | map
985-
| max | memoryview | min | next | oct | open | ord | pow | print
986-
| quit | range | reload | repr | reversed | round
987-
| setattr | sorted | sum | vars | zip
988-
)\b
976+
patterns:
977+
- name: support.function.builtin.python
978+
match: |
979+
(?x)
980+
(?<!\.)\b(
981+
__import__ | abs | all | any | apply | ascii | bin | callable
982+
| chr | compile | copyright | credits | delattr | dir | divmod
983+
| enumerate | eval | exec | exit | filter | format | getattr
984+
| globals | hasattr | hash | help | hex | id | input
985+
| isinstance | issubclass | iter | len | license | locals | map
986+
| max | memoryview | min | next | oct | open | ord | pow | print
987+
| quit | range | reload | repr | reversed | round
988+
| setattr | sorted | sum | vars | zip
989+
)\b
990+
991+
- name: variable.legacy.builtin.python
992+
match: |
993+
(?x)
994+
(?<!\.)\b(
995+
file | reduce | intern | raw_input | unicode | cmp | basestring
996+
| execfile | long | xrange
997+
)\b
998+
989999
builtin-types:
9901000
name: support.type.python
9911001
match: |

grammars/MagicPython.tmLanguage

+22-6
Original file line numberDiff line numberDiff line change
@@ -2349,13 +2349,16 @@ it&apos;s not tokenized as ellipsis.
23492349
</dict>
23502350
<key>builtin-functions</key>
23512351
<dict>
2352-
<key>name</key>
2353-
<string>support.function.builtin.python</string>
2354-
<key>match</key>
2355-
<string>(?x)
2352+
<key>patterns</key>
2353+
<array>
2354+
<dict>
2355+
<key>name</key>
2356+
<string>support.function.builtin.python</string>
2357+
<key>match</key>
2358+
<string>(?x)
23562359
(?&lt;!\.)\b(
2357-
__import__ | abs | all | any | apply | ascii | bin | callable | chr
2358-
| compile | copyright | credits | delattr | dir | divmod
2360+
__import__ | abs | all | any | apply | ascii | bin | callable
2361+
| chr | compile | copyright | credits | delattr | dir | divmod
23592362
| enumerate | eval | exec | exit | filter | format | getattr
23602363
| globals | hasattr | hash | help | hex | id | input
23612364
| isinstance | issubclass | iter | len | license | locals | map
@@ -2364,6 +2367,19 @@ it&apos;s not tokenized as ellipsis.
23642367
| setattr | sorted | sum | vars | zip
23652368
)\b
23662369
</string>
2370+
</dict>
2371+
<dict>
2372+
<key>name</key>
2373+
<string>variable.legacy.builtin.python</string>
2374+
<key>match</key>
2375+
<string>(?x)
2376+
(?&lt;!\.)\b(
2377+
file | reduce | intern | raw_input | unicode | cmp | basestring
2378+
| execfile | long | xrange
2379+
)\b
2380+
</string>
2381+
</dict>
2382+
</array>
23672383
</dict>
23682384
<key>builtin-types</key>
23692385
<dict>

misc/scopes

+1
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ support.type.python
142142
support.variable.magic.python
143143
variable.language.special.cls.python
144144
variable.language.special.self.python
145+
variable.legacy.builtin.python
145146
variable.parameter.function-call.python
146147
variable.parameter.function.language.python
147148
variable.parameter.function.language.special.cls.python

test/builtins/builtins2.py

+20-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,25 @@
11
Error
2-
file reduce intern raw_input unicode cmp basestring
2+
file reduce intern raw_input unicode cmp basestring execfile long xrange
33

44

55

66
Error : source.python
7-
file reduce intern raw_input unicode cmp basestring : source.python
7+
file : source.python, variable.legacy.builtin.python
8+
: source.python
9+
reduce : source.python, variable.legacy.builtin.python
10+
: source.python
11+
intern : source.python, variable.legacy.builtin.python
12+
: source.python
13+
raw_input : source.python, variable.legacy.builtin.python
14+
: source.python
15+
unicode : source.python, variable.legacy.builtin.python
16+
: source.python
17+
cmp : source.python, variable.legacy.builtin.python
18+
: source.python
19+
basestring : source.python, variable.legacy.builtin.python
20+
: source.python
21+
execfile : source.python, variable.legacy.builtin.python
22+
: source.python
23+
long : source.python, variable.legacy.builtin.python
24+
: source.python
25+
xrange : source.python, variable.legacy.builtin.python

test/builtins/builtins4.py

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
some.int
2+
some.sum
3+
some.super
4+
some.unicode
5+
some.foo
6+
some.Exception
7+
8+
9+
10+
some : source.python
11+
. : source.python
12+
int : source.python
13+
: source.python
14+
some : source.python
15+
. : source.python
16+
sum : source.python
17+
: source.python
18+
some : source.python
19+
. : source.python
20+
super : source.python
21+
: source.python
22+
some : source.python
23+
. : source.python
24+
unicode : source.python
25+
: source.python
26+
some : source.python
27+
. : source.python
28+
foo : source.python
29+
: source.python
30+
some : source.python
31+
. : source.python
32+
Exception : source.python
33+
: source.python

0 commit comments

Comments
 (0)