Skip to content

Commit 6528115

Browse files
committed
Fix odd highlighting of strings and comments after '.'.
1 parent 6bf31f7 commit 6528115

File tree

4 files changed

+73
-3
lines changed

4 files changed

+73
-3
lines changed

grammars/MagicPython.cson

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,17 @@ repository:
366366
]
367367
"member-access":
368368
begin: "\\.\\s*(?!\\.)"
369-
end: "(?<=\\S)(?=\\W)|$"
369+
end: '''
370+
(?x)
371+
# stop when you've just read non-whitespace followed by non-word
372+
# i.e. when finished reading an identifier or function call
373+
(?<=\\S)(?=\\W) |
374+
# stop when seeing the start of something that's not a word,
375+
# i.e. when seeing a non-identifier
376+
(^|(?<=\\s))(?=[^\\\\\\w\\s]) |
377+
$
378+
379+
'''
370380
patterns: [
371381
{
372382
include: "#function-call"

grammars/MagicPython.tmLanguage

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,15 @@
563563
<key>begin</key>
564564
<string>\.\s*(?!\.)</string>
565565
<key>end</key>
566-
<string>(?&lt;=\S)(?=\W)|$</string>
566+
<string>(?x)
567+
# stop when you've just read non-whitespace followed by non-word
568+
# i.e. when finished reading an identifier or function call
569+
(?&lt;=\S)(?=\W) |
570+
# stop when seeing the start of something that's not a word,
571+
# i.e. when seeing a non-identifier
572+
(^|(?&lt;=\s))(?=[^\\\w\s]) |
573+
$
574+
</string>
567575
<key>patterns</key>
568576
<array>
569577
<dict>

grammars/src/MagicPython.syntax.yaml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,15 @@ repository:
267267

268268
member-access:
269269
begin: \.\s*(?!\.)
270-
end: (?<=\S)(?=\W)|$
270+
end: |
271+
(?x)
272+
# stop when you've just read non-whitespace followed by non-word
273+
# i.e. when finished reading an identifier or function call
274+
(?<=\S)(?=\W) |
275+
# stop when seeing the start of something that's not a word,
276+
# i.e. when seeing a non-identifier
277+
(^|(?<=\s))(?=[^\\\w\s]) |
278+
$
271279
patterns:
272280
- include: '#function-call'
273281
- include: '#member-access-base'

test/expressions/expr19.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
a. #foo
2+
a.
3+
#foo
4+
a. \
5+
#foo
6+
a. 'bar'
7+
a.
8+
'bar'
9+
a. \
10+
'bar'
11+
12+
13+
14+
a : source.python
15+
. : source.python
16+
# : comment.line.number-sign.python, punctuation.definition.comment.python, source.python
17+
foo : comment.line.number-sign.python, source.python
18+
a : source.python
19+
. : source.python
20+
# : comment.line.number-sign.python, punctuation.definition.comment.python, source.python
21+
foo : comment.line.number-sign.python, source.python
22+
a : source.python
23+
. : source.python
24+
\ : separator.continuation.line.python, source.python
25+
: source.python
26+
# : comment.line.number-sign.python, punctuation.definition.comment.python, source.python
27+
foo : comment.line.number-sign.python, source.python
28+
a : source.python
29+
. : source.python
30+
' : punctuation.definition.string.begin.python, source.python, string.quoted.single.python
31+
bar : source.python, string.quoted.single.python
32+
' : punctuation.definition.string.end.python, source.python, string.quoted.single.python
33+
a : source.python
34+
. : source.python
35+
' : punctuation.definition.string.begin.python, source.python, string.quoted.docstring.single.python
36+
bar : source.python, string.quoted.docstring.single.python
37+
' : punctuation.definition.string.end.python, source.python, string.quoted.docstring.single.python
38+
a : source.python
39+
. : source.python
40+
\ : separator.continuation.line.python, source.python
41+
: source.python
42+
' : punctuation.definition.string.begin.python, source.python, string.quoted.single.python
43+
bar : source.python, string.quoted.single.python
44+
' : punctuation.definition.string.end.python, source.python, string.quoted.single.python

0 commit comments

Comments
 (0)