Skip to content

Commit 90eeddd

Browse files
author
MattDMo
committed
Lots o' changes
1 parent 446429a commit 90eeddd

File tree

1 file changed

+167
-78
lines changed

1 file changed

+167
-78
lines changed

PythonImproved-Unicode.YAML-tmLanguage

Lines changed: 167 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ comment: To make PythonImproved your default Python syntax, open a .py file and
44
name: PythonImproved-Unicode
55
scopeName: source.python
66
fileTypes: [py, py3, rpy, pyw, cpy, SConstruct, Sconstruct, sconstruct, SConscript]
7-
uuid: 74FE3C79-C1DD-41A7-99C9-41CE48307997
7+
uuid: 11B0273F-0284-4483-B17B-4B8D0A9294CC
8+
# uuid: A4AB2A88-CBF6-4515-84B7-396046E21286
89

910
patterns:
1011
- name: support.ipython.in.python
@@ -17,16 +18,7 @@ patterns:
1718
captures:
1819
'2': {name: support.ipython.cell-number.python}
1920

20-
- name: comment.line.note.python
21-
match: (#+)\s*(BUG|FIXME|TODO|XXX).*$\n?
22-
captures:
23-
'1': {name: punctuation.definition.comment.python}
24-
'2': {name: comment.line.note.notation.python}
25-
26-
- name: comment.line.number-sign.python
27-
match: (#+).*$\n?
28-
captures:
29-
'1': {name: punctuation.definition.comment.python}
21+
- include: '#comments'
3022

3123
- comment: Match identifiers in ALL_CAPS as constants, except when followed by . or
3224
(.
@@ -228,8 +220,8 @@ patterns:
228220
name: keyword.control.flow.python
229221
match: |
230222
(?x) \b(
231-
async | await | break | continue | elif | else | except | finally | for |
232-
if | pass | raise | return | try | while | with |
223+
async | await | break | continue | elif | else | except | finally |
224+
for | if | pass | raise | return | try | while | with |
233225
(yield(?:\s+from)?)
234226
)\b
235227
@@ -302,7 +294,9 @@ patterns:
302294
- include: '#keyword_arguments'
303295
- include: $self
304296

305-
- include: '#builtin_functions'
297+
- include: '#builtin_functions_name'
298+
299+
- include: '#builtin_functions_call'
306300

307301
- include: '#builtin_types'
308302

@@ -348,7 +342,7 @@ patterns:
348342

349343
- comment: Py2 print statement that should only be matched after function calls
350344
name: keyword.other.print.python
351-
match: \b(print)(?=\s)(?!\s*([.,]|$))
345+
match: (?<!\.)\b(print)(?=\s|$)
352346

353347
- name: meta.item-access.python
354348
begin: (?=[\p{Alpha}_][\p{Alnum}_]*(?:\s*\.\s*[\p{Alpha}_][\p{Alnum}_]*)*\s*\[)
@@ -503,23 +497,24 @@ repository:
503497
'1': {name: punctuation.separator.parameters.python}
504498
- include: '#comments'
505499

506-
builtin_functions:
500+
builtin_functions_call:
507501
patterns:
508502
- name: meta.function-call.python
509503
begin: |
510504
(?x)
511-
(?<!\.)(
512-
__import__ | abs | all | any | ascii | basestring | bin | bool | bytearray |
513-
bytes | callable | chr | classmethod | cmp | compile | complex | delattr |
514-
dict | dir | divmod | enumerate | eval | exec | execfile | file | filter |
515-
float | format | frozenset | getattr | globals | hasattr | hash | help |
516-
hex | id | input | int | isinstance | issubclass | iter | len | list |
517-
locals | long | map | max | memoryview | min | next | object | oct | open |
518-
ord | pow | print | property | range | raw_input | reduce | reload | repr |
519-
reversed | round | set | setattr | slice | sorted | staticmethod | str |
520-
sum | super | tuple | type | unichr | unicode | vars | xrange | zip)
521-
\s*
522-
(?=(\())
505+
(?<!\.)\b(
506+
__import__ | abs | all | any | ascii | basestring | bin | bool |
507+
bytearray | bytes | callable | chr | classmethod | cmp | compile |
508+
complex | delattr | dict | dir | divmod | enumerate | eval | exec |
509+
execfile | file | filter | float | format | frozenset | getattr |
510+
globals | hasattr | hash | help | hex | id | input | int |
511+
isinstance | issubclass | iter | len | list | locals | long | map |
512+
max | memoryview | min | next | object | oct | open | ord | pow |
513+
print | property | range | raw_input | reduce | reload | repr |
514+
reversed | round | set | setattr | slice | sorted | staticmethod |
515+
str | sum | super | tuple | type | unichr | unicode | vars |
516+
xrange | zip)
517+
\b\s*(?=\()
523518
beginCaptures:
524519
'1': {name: support.function.builtin.python}
525520
'2': {name: punctuation.definition.arguments.begin.python}
@@ -540,16 +535,36 @@ repository:
540535
- include: '#keyword_arguments'
541536
- include: $self
542537

538+
builtin_functions_name:
539+
- name: support.function.builtin.python
540+
match: |
541+
(?x)
542+
(?<!\.)
543+
\b(
544+
__import__ | abs | all | any | ascii | basestring | bin | bool |
545+
bytearray | bytes | callable | chr | classmethod | cmp | compile |
546+
complex | delattr | dict | dir | divmod | enumerate | eval | exec |
547+
execfile | file | filter | float | format | frozenset | getattr |
548+
globals | hasattr | hash | help | hex | id | input | int |
549+
isinstance | issubclass | iter | len | list | locals | long | map |
550+
max | memoryview | min | next | object | oct | open | ord | pow |
551+
print | property | range | raw_input | reduce | reload | repr |
552+
reversed | round | set | setattr | slice | sorted | staticmethod |
553+
str | sum | super | tuple | type | unichr | unicode | vars |
554+
xrange | zip)
555+
\b
556+
543557
builtin_types:
544558
name: support.type.python
559+
comment: These are from https://docs.python.org/X/library/functions.html
560+
where X is 2.7 or 3.5 and the item is a class. Also stdtypes.html
545561
match: |
546562
(?x)
547563
(?<!\.)
548564
\b(
549-
ascii | basestring | bin | bool | buffer | bytearray | bytes | classmethod |
550-
complex | dict | file | float | frozenset | hex | int | list | long |
551-
object | oct | property | reversed | set | slice | staticmethod | str |
552-
super | tuple | type | unicode | xrange)
565+
\.{3} | bool | buffer | bytearray | bytes | complex | dict | float |
566+
frozenset | int | list | long | memoryview | object | property |
567+
range | set | slice | str | tuple | type | unicode | xrange)
553568
\b
554569
555570
character-class:
@@ -625,7 +640,8 @@ repository:
625640
- begin: (?<!\.)(?=[\p{Alpha}_][\p{Alnum}_]*)
626641
end: (?![\p{Alnum}_])
627642
patterns:
628-
- include: '#builtin_functions'
643+
- include: '#builtin_functions_name'
644+
- include: '#builtin_functions_call'
629645
- include: '#builtin_types'
630646
- include: '#errors_warnings_exceptions'
631647
- include: '#magic_function_names'
@@ -641,6 +657,7 @@ repository:
641657

642658
entity_name_function:
643659
patterns:
660+
- include: '#builtin_functions_name'
644661
- include: '#magic_function_names'
645662
- include: '#generic_names'
646663
- include: '#illegal_names'
@@ -651,27 +668,46 @@ repository:
651668
(?x)
652669
\b(
653670
(
654-
Arithmetic | Assertion | Attribute | Buffer | BlockingIO | BrokenPipe |
655-
ChildProcess |
656-
(Connection(Aborted | Refused | Reset)?) |
657-
EOF | Environment | FileExists | FileNotFound | FloatingPoint | IO |
658-
Import | Indentation | Index | Interrupted | IsADirectory | NotADirectory |
659-
Permission | ProcessLookup | Timeout | Key | Lookup | Memory | Name |
660-
NotImplemented | OS | Overflow | Reference | Runtime | Recursion | Standard |
661-
Syntax | System | Tab | Type | UnboundLocal |
662-
Unicode(Encode | Decode | Translate)? | Value | VMS | Windows | ZeroDivision |
663-
([\.\p{Alpha}_][\p{Alnum}_]*))
664-
? Error
665-
| (
666-
(Pending)?Deprecation | Bytes | Future | Import | Resource | Runtime |
667-
Syntax | Unicode | User)
668-
?Warning
669-
|
670-
SystemExit | Stop(Async)?Iteration | NotImplemented | KeyboardInterrupt |
671-
GeneratorExit | ([\.\p{Alpha}_][\p{Alnum}_]*)?Exception)
671+
Arithmetic | Assertion | Attribute | Buffer | BlockingIO |
672+
BrokenPipe | ChildProcess | (Connection(Aborted | Refused | Reset)?) |
673+
EOF | Environment | FileExists | FileNotFound | FloatingPoint | IO |
674+
Import | Indentation | Index | Interrupted | IsADirectory |
675+
NotADirectory | Permission | ProcessLookup | Timeout | Key | Lookup |
676+
Memory | Name | NotImplemented | OS | Overflow | Reference | Runtime |
677+
Recursion | Standard | Syntax | System | Tab | Type | UnboundLocal |
678+
Unicode(Encode | Decode | Translate)? | Value | VMS | Windows |
679+
ZeroDivision | ([\p{Alpha}_][\p{Alnum}_]*))
680+
?Error
681+
|
682+
(
683+
(Pending)?Deprecation | Bytes | Future | Import | Resource |
684+
Runtime | Syntax | Unicode | User | [\p{Alpha}_][\p{Alnum}_]*)
685+
?Warning
686+
|
687+
SystemExit | Stop(Async)?Iteration | NotImplemented |
688+
KeyboardInterrupt | GeneratorExit
689+
|
690+
([\p{Alpha}_][\p{Alnum}_]*)
691+
?Exception
692+
)
672693
\b
694+
673695
escaped_char:
674-
match: (\\x[\h]{2})|(\\[0-7]{3})|(\\\n)|(\\\\)|(\\\")|(\\')|(\\a)|(\\b)|(\\f)|(\\n)|(\\r)|(\\t)|(\\v)
696+
match: |
697+
(?x)
698+
(\\x[\h]{2}) |
699+
(\\[0-7]{3}) |
700+
(\\\n) |
701+
(\\\\) |
702+
(\\\") |
703+
(\\') |
704+
(\\a) |
705+
(\\b) |
706+
(\\f) |
707+
(\\n) |
708+
(\\r) |
709+
(\\t) |
710+
(\\v)
675711
captures:
676712
'1': {name: constant.character.escape.hex.python}
677713
'2': {name: constant.character.escape.octal.python}
@@ -694,15 +730,6 @@ repository:
694730
'2': {name: constant.character.escape.unicode.32-bit-hex.python}
695731
'3': {name: constant.character.escape.unicode.name.python}
696732

697-
function_name:
698-
patterns:
699-
- include: '#magic_function_names'
700-
- include: '#magic_variable_names'
701-
- include: '#errors_warnings_exceptions'
702-
- include: '#builtin_functions'
703-
- include: '#builtin_types'
704-
- include: '#generic_names'
705-
706733
generic_names:
707734
name: meta.identifier.python
708735
match: '[\p{Alpha}_][\p{Alnum}_]*'
@@ -728,6 +755,7 @@ repository:
728755
beginCaptures:
729756
'1': {name: variable.parameter.function.keyword.python}
730757
'2': {name: keyword.operator.assignment.python}
758+
# Change #2 to something else?
731759
end: \s*(?:(,)|(?=$\n?|[\)\:]))
732760
endCaptures:
733761
'1': {name: punctuation.separator.parameters.python}
@@ -744,32 +772,91 @@ repository:
744772
'1': {name: punctuation.separator.continuation.line.python}
745773

746774
magic_function_names:
747-
comment: these methods have magic interpretation by python and are generally called
748-
indirectly through syntactic constructs
775+
comment: these methods have magic interpretation by python and are generally
776+
called indirectly through syntactic constructs. Names are from
777+
https://docs.python.org/X/reference/datamodel.html where X is 2.7 and 3.5
778+
See also http://www.rafekettler.com/magicmethods.html
749779
match: |
750780
(?x)
751781
(\.)?
752782
\b (
753-
__(?:abs | add | and | bool | call | ceil | cmp | complex | contains | copy |
754-
deepcopy | del | delattr | delete | delitem | delslice | dir | div | divmod |
755-
enter | eq | exit | float | floor | floordiv | format | ge | get | getattr |
756-
getattribute | getinitargs | getitem | getnewargs | getslice | getstate |
757-
gt | hash | hex | iadd | iand | idiv | ifloordiv | ilshift | imod | imul |
758-
index | init | instancecheck | int | invert | ior | ipow | irshift | isub |
759-
iter | itruediv | ixor | le | len | long | lshift | lt | missing | mod |
760-
mul | ne | neg | new | nonzero | oct | or | pos | pow | radd | rand | rdiv |
761-
rdivmod | reduce | reduce_ex | repr | reversed | rfloordiv | rlshift | rmod |
762-
rmul | ror | round | rpow | rrshift | rshift | rsub | rtruediv | rxor | set |
763-
setattr | setitem | setslice | setstate | sizeof | str | sub | subclasscheck |
764-
truediv | trunc | unicode | xor)
783+
__(?:
784+
abs | add | aenter | aexit | aiter | and | anext | await | bool |
785+
bytes | call | ceil | cmp | coerce | complex | contains | copy |
786+
deepcopy | del | delattr | delete | delitem | delslice | dir | div |
787+
divmod | enter | eq | exit | float | floor | floordiv | format | ge |
788+
get | getattr | getattribute | getinitargs | getitem | getnewargs |
789+
getnewargs_ex | getslice | getstate | gt | hash | hex | iadd | iand |
790+
idiv | idivmod | ifloordiv | ilshift | imatmul | imod | imul | index |
791+
init | instancecheck | int | invert | iop | ior | ipow | irshift |
792+
isub | iter | itruediv | ixor | le | len | length_hint | long |
793+
lshift | lt | matmul | missing | mod | mul | ne | neg | new | next |
794+
nonzero | oct | op | or | pos | pow | prepare | radd | rand | rcmp |
795+
rdiv | rdivmod | reduce | reduce_ex | repr | reversed | rfloordiv |
796+
rlshift | rmatmul | rmod | rmul | rop | ror | round | rpow | rrshift |
797+
rshift | rsub | rtruediv | rxor | set | setattr | setitem | setslice |
798+
setstate | sizeof | str | sub | subclasscheck | truediv | trunc |
799+
unicode | xor)
765800
__)
766801
\b
767802
captures:
768803
'2': {name: support.function.magic.python}
804+
patterns:
805+
- name: meta.function-call.python
806+
begin: |
807+
(?x)
808+
(?<!\.)\b(
809+
__(?:
810+
abs | add | aenter | aexit | aiter | and | anext | await | bool |
811+
bytes | call | ceil | cmp | coerce | complex | contains | copy |
812+
deepcopy | del | delattr | delete | delitem | delslice | dir | div |
813+
divmod | enter | eq | exit | float | floor | floordiv | format | ge |
814+
get | getattr | getattribute | getinitargs | getitem | getnewargs |
815+
getnewargs_ex | getslice | getstate | gt | hash | hex | iadd | iand |
816+
idiv | idivmod | ifloordiv | ilshift | imatmul | imod | imul | index |
817+
init | instancecheck | int | invert | iop | ior | ipow | irshift |
818+
isub | iter | itruediv | ixor | le | len | length_hint | long |
819+
lshift | lt | matmul | missing | mod | mul | ne | neg | new | next |
820+
nonzero | oct | op | or | pos | pow | prepare | radd | rand | rcmp |
821+
rdiv | rdivmod | reduce | reduce_ex | repr | reversed | rfloordiv |
822+
rlshift | rmatmul | rmod | rmul | rop | ror | round | rpow | rrshift |
823+
rshift | rsub | rtruediv | rxor | set | setattr | setitem | setslice |
824+
setstate | sizeof | str | sub | subclasscheck | truediv | trunc |
825+
unicode | xor)
826+
__)
827+
\s*(?=\()
828+
beginCaptures:
829+
'1': {name: support.function.magic.python}
830+
'2': {name: punctuation.definition.arguments.begin.python}
831+
end: (\))
832+
endCaptures:
833+
'1': {name: punctuation.definition.arguments.end.python}
834+
patterns:
835+
- begin: (?=[\p{Alpha}_][\p{Alnum}_]*(?:\s*\.\s*[\p{Alpha}_][\p{Alnum}_]*)*\s*\()
836+
end: (?=\s*\()
837+
patterns:
838+
- include: '#dotted_name'
839+
- begin: (\()
840+
beginCaptures:
841+
'1': {name: punctuation.definition.arguments.begin.python}
842+
contentName: meta.function-call.arguments.python
843+
end: (?=\))
844+
patterns:
845+
- include: '#keyword_arguments'
846+
- include: $self
769847

770848
magic_variable_names:
771-
comment: magic variables which a class/module may have.
772-
match: (\.)?\b(__(?:all|bases|class|debug|dict|doc|file|members|metaclass|methods|module|mro|name|slots|subclasses|version|weakref)__)\b
849+
comment: magic attributes which a class/module may have.
850+
match: |
851+
(?x)
852+
(\.)?
853+
\b(
854+
__(?:
855+
all | annotations | bases | class | closure | code | debug |
856+
defaults | dict | doc | file | func | globals | kwdefaults |
857+
members | metaclass | methods | module | mro | name | qualname |
858+
self | slots | subclasses | version | weakref)
859+
__) \b
773860
captures:
774861
'2': {name: support.variable.magic.python}
775862

@@ -1142,8 +1229,10 @@ repository:
11421229
patterns:
11431230
- include: '#string_quoted_double'
11441231
- include: '#string_quoted_single'
1232+
11451233
author: Matt Morrison @MattDMo [email protected]
1146-
bundleUUID: 0F24FCF1-6543-4CC6-8B33-2EAED401FE3A
1234+
# bundleUUID: 0F24FCF1-6543-4CC6-8B33-2EAED401FE3A
1235+
bundleUUID: EB590797-FBEE-4BEA-A140-8339AFD2CE1B
11471236
firstLineMatch: ^#!/.*\bpython[0-9.-]*\b
11481237
foldingStartMarker: ^\s*(((?:async\s+)?def)|class)\s+([.\p{Alnum}_ <]+)\s*(\((.*)\))?\s*:|\{\s*$|\(\s*$|\[\s*$|^\s*"""(?=.)(?!.*""")
11491238
foldingStopMarker: ^\s*$|^\s*\}|^\s*\]|^\s*\)|^\s*"""\s*$

0 commit comments

Comments
 (0)