Skip to content

Commit b9aa8b0

Browse files
committed
Fix higlighting for format strings.
1 parent 90e8586 commit b9aa8b0

File tree

14 files changed

+434
-130
lines changed

14 files changed

+434
-130
lines changed

grammars/MagicPython.cson

Lines changed: 111 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,7 @@ repository:
748748
}
749749
]
750750
"string-consume-escape":
751-
match: "\\\\."
751+
match: "\\\\['\"\\n\\\\]"
752752
"string-raw-guts":
753753
patterns: [
754754
{
@@ -832,7 +832,7 @@ repository:
832832
{{ | }}
833833
| (?:
834834
{
835-
[^!:\\.\\[\\]'"]*? (\\.[[:alpha:]_]\\w*? | \\[[^\\]'"]+\\])*?
835+
\\w*? (\\.[[:alpha:]_]\\w*? | \\[[^\\]'"]+\\])*?
836836
(![rsa])?
837837
( : \\w? [<>=^]? [-+ ]? \\#?
838838
\\d* ,? (\\.\\d+)? [bcdeEfFgGnosxX%]? )?
@@ -851,7 +851,7 @@ repository:
851851
begin: '''
852852
(?x)
853853
\\{
854-
[^!:\\.\\[\\]'"]*? (\\.[[:alpha:]_]\\w*? | \\[[^\\]'"]+\\])*?
854+
\\w*? (\\.[[:alpha:]_]\\w*? | \\[[^\\]'"]+\\])*?
855855
(![rsa])?
856856
(:)
857857
(?=[^'"}\\n]*\\})
@@ -2863,7 +2863,7 @@ repository:
28632863
]
28642864
"string-raw-quoted-single-line":
28652865
name: "string.quoted.raw.single.python"
2866-
begin: "\\b(([uU]R)|(R))(\\'|\")"
2866+
begin: "\\b(([uU]R)|(R))((['\"]))"
28672867
end: "(\\4)|((?<!\\\\)\\n)"
28682868
beginCaptures:
28692869
"2":
@@ -2878,13 +2878,16 @@ repository:
28782878
"2":
28792879
name: "invalid.illegal.newline.python"
28802880
patterns: [
2881+
{
2882+
include: "#string-single-bad-brace-formatting-raw"
2883+
}
28812884
{
28822885
include: "#string-raw-guts"
28832886
}
28842887
]
28852888
"string-bin-quoted-single-line":
28862889
name: "string.quoted.binary.single.python"
2887-
begin: "(\\b[bB])(\\'|\")"
2890+
begin: "(\\b[bB])((['\"]))"
28882891
end: "(\\2)|((?<!\\\\)\\n)"
28892892
beginCaptures:
28902893
"1":
@@ -2903,7 +2906,7 @@ repository:
29032906
]
29042907
"string-raw-bin-quoted-single-line":
29052908
name: "string.quoted.raw.binary.single.python"
2906-
begin: "(\\b(?:R[bB]|[bB]R))(\\'|\")"
2909+
begin: "(\\b(?:R[bB]|[bB]R))((['\"]))"
29072910
end: "(\\2)|((?<!\\\\)\\n)"
29082911
beginCaptures:
29092912
"1":
@@ -2922,7 +2925,7 @@ repository:
29222925
]
29232926
"string-quoted-single-line":
29242927
name: "string.quoted.single.python"
2925-
begin: "(\\b[rR](?=[uU]))?([uU])?(\\'|\")"
2928+
begin: "(\\b[rR](?=[uU]))?([uU])?((['\"]))"
29262929
end: "(\\3)|((?<!\\\\)\\n)"
29272930
beginCaptures:
29282931
"1":
@@ -2937,13 +2940,60 @@ repository:
29372940
"2":
29382941
name: "invalid.illegal.newline.python"
29392942
patterns: [
2943+
{
2944+
include: "#string-single-bad-brace-formatting-unicode"
2945+
}
29402946
{
29412947
include: "#string-unicode-guts"
29422948
}
29432949
]
2950+
"string-single-bad-brace-formatting-unicode":
2951+
comment: "odd format or format-like syntax"
2952+
begin: '''
2953+
(?x)
2954+
(?!\\{\\{)
2955+
(?= \\{ (
2956+
\\w*? (?!(['"])|((?<!\\\\)\\n)) [^!:\\.\\[}\\w]
2957+
)
2958+
.*?(?!(['"])|((?<!\\\\)\\n))
2959+
\\}
2960+
)
2961+
2962+
'''
2963+
end: "(?=(['\"])|((?<!\\\\)\\n))"
2964+
patterns: [
2965+
{
2966+
include: "#escape-sequence-unicode"
2967+
}
2968+
{
2969+
include: "#string-entity"
2970+
}
2971+
]
2972+
"string-single-bad-brace-formatting-raw":
2973+
comment: "odd format or format-like syntax"
2974+
begin: '''
2975+
(?x)
2976+
(?!\\{\\{)
2977+
(?= \\{ (
2978+
\\w*? (?!(['"])|((?<!\\\\)\\n)) [^!:\\.\\[}\\w]
2979+
)
2980+
.*?(?!(['"])|((?<!\\\\)\\n))
2981+
\\}
2982+
)
2983+
2984+
'''
2985+
end: "(?=(['\"])|((?<!\\\\)\\n))"
2986+
patterns: [
2987+
{
2988+
include: "#string-consume-escape"
2989+
}
2990+
{
2991+
include: "#string-formatting"
2992+
}
2993+
]
29442994
"string-raw-quoted-multi-line":
29452995
name: "string.quoted.raw.multi.python"
2946-
begin: "\\b(([uU]R)|(R))(\\'\\'\\'|\"\"\")"
2996+
begin: "\\b(([uU]R)|(R))('''|\"\"\")"
29472997
end: "(\\4)"
29482998
beginCaptures:
29492999
"2":
@@ -2958,13 +3008,16 @@ repository:
29583008
"2":
29593009
name: "invalid.illegal.newline.python"
29603010
patterns: [
3011+
{
3012+
include: "#string-multi-bad-brace-formatting-raw"
3013+
}
29613014
{
29623015
include: "#string-raw-guts"
29633016
}
29643017
]
29653018
"string-bin-quoted-multi-line":
29663019
name: "string.quoted.binary.multi.python"
2967-
begin: "(\\b[bB])(\\'\\'\\'|\"\"\")"
3020+
begin: "(\\b[bB])('''|\"\"\")"
29683021
end: "(\\2)"
29693022
beginCaptures:
29703023
"1":
@@ -2983,7 +3036,7 @@ repository:
29833036
]
29843037
"string-raw-bin-quoted-multi-line":
29853038
name: "string.quoted.raw.binary.multi.python"
2986-
begin: "(\\b(?:R[bB]|[bB]R))(\\'\\'\\'|\"\"\")"
3039+
begin: "(\\b(?:R[bB]|[bB]R))('''|\"\"\")"
29873040
end: "(\\2)"
29883041
beginCaptures:
29893042
"1":
@@ -3002,7 +3055,7 @@ repository:
30023055
]
30033056
"string-quoted-multi-line":
30043057
name: "string.quoted.multi.python"
3005-
begin: "(\\b[rR](?=[uU]))?([uU])?(\\'\\'\\'|\"\"\")"
3058+
begin: "(\\b[rR](?=[uU]))?([uU])?('''|\"\"\")"
30063059
end: "(\\3)"
30073060
beginCaptures:
30083061
"1":
@@ -3017,7 +3070,54 @@ repository:
30173070
"2":
30183071
name: "invalid.illegal.newline.python"
30193072
patterns: [
3073+
{
3074+
include: "#string-multi-bad-brace-formatting-unicode"
3075+
}
30203076
{
30213077
include: "#string-unicode-guts"
30223078
}
3079+
]
3080+
"string-multi-bad-brace-formatting-unicode":
3081+
comment: "odd format or format-like syntax"
3082+
begin: '''
3083+
(?x)
3084+
(?!\\{\\{)
3085+
(?= \\{ (
3086+
\\w*? (?!\'''|""") [^!:\\.\\[}\\w]
3087+
)
3088+
.*?(?!\'''|""")
3089+
\\}
3090+
)
3091+
3092+
'''
3093+
end: "(?='''|\"\"\")"
3094+
patterns: [
3095+
{
3096+
include: "#escape-sequence-unicode"
3097+
}
3098+
{
3099+
include: "#string-entity"
3100+
}
3101+
]
3102+
"string-multi-bad-brace-formatting-raw":
3103+
comment: "odd format or format-like syntax"
3104+
begin: '''
3105+
(?x)
3106+
(?!\\{\\{)
3107+
(?= \\{ (
3108+
\\w*? (?!\'''|""") [^!:\\.\\[}\\w]
3109+
)
3110+
.*?(?!\'''|""")
3111+
\\}
3112+
)
3113+
3114+
'''
3115+
end: "(?='''|\"\"\")"
3116+
patterns: [
3117+
{
3118+
include: "#string-consume-escape"
3119+
}
3120+
{
3121+
include: "#string-formatting"
3122+
}
30233123
]

grammars/MagicPython.syntax.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,13 @@ repository:
5858
- file: 'pystring.inc.syntax.yaml'
5959
vars:
6060
line: single
61-
marker: "\\'|\""
61+
marker: (['"])
6262
guard: "|((?<!\\\\)\\n)"
6363

6464
- file: 'pystring.inc.syntax.yaml'
6565
vars:
6666
line: multi
67-
marker: "\\'\\'\\'|\"\"\""
67+
marker: "'''|\"\"\""
6868
guard: ""
6969

7070

@@ -529,7 +529,7 @@ repository:
529529
- include: '#string-brace-formatting'
530530

531531
string-consume-escape:
532-
match: \\.
532+
match: \\['"\n\\]
533533

534534
string-raw-guts:
535535
patterns:
@@ -593,7 +593,7 @@ repository:
593593
{{ | }}
594594
| (?:
595595
{
596-
[^!:\.\[\]'"]*? (\.[[:alpha:]_]\w*? | \[[^\]'"]+\])*?
596+
\w*? (\.[[:alpha:]_]\w*? | \[[^\]'"]+\])*?
597597
(![rsa])?
598598
( : \w? [<>=^]? [-+ ]? \#?
599599
\d* ,? (\.\d+)? [bcdeEfFgGnosxX%]? )?
@@ -606,7 +606,7 @@ repository:
606606
begin: |
607607
(?x)
608608
\{
609-
[^!:\.\[\]'"]*? (\.[[:alpha:]_]\w*? | \[[^\]'"]+\])*?
609+
\w*? (\.[[:alpha:]_]\w*? | \[[^\]'"]+\])*?
610610
(![rsa])?
611611
(:)
612612
(?=[^'"}\n]*\})

0 commit comments

Comments
 (0)