-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Expand file tree
/
Copy pathstrings.py
More file actions
112 lines (80 loc) · 1.51 KB
/
strings.py
File metadata and controls
112 lines (80 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#Raw
r'012345678'
r'(\033|~{)'
r'\A[+-]?\d+'
r'(?P<name>[\w]+)|'
r'\|\[\][123]|\{\}'
r'^.$'
r'[^A-Z]'
# With escapes
'\n'
"\'"
'\''
"\""
"\t\l\b"
#F-strings
f''
rf'hello'
fr'hello'
f'a{1+1}b'
f'{x}{y}a{z}'
#This is not legal in CPython, but we tokenize it anyway.
f'a{'x'+"y"}b'
#Multiline f-string
f'''
In f-string expressions act as if parenthesised
{
x +
y &
z
}
end
'''
#Multi-line
r""" Single quotation character with multi-line
"a", 'b', "", ''
....
"""
r''' Single quotation character with multi-line
"a", 'b', "", ''
....
'''
#f-string conversions
!a
!s
!r
f"{k}={v!r}"
#Implicit concatenation
(f'{expr} text '
'continuation'
f'and{v}'
)
#prefixes
u'{}\r{}{:<{width}}'
u'{}\r{}{:<{}}'
#f-strings with format specifier
f'result: {value:0.2f}'
f'result: {value:{width}.{precision}}'
f"Too {'many' if alen > elen else 'few'} parameters for {cls};"
# f-strings have special escaping rules for curly-brackets
f'This should work \{foo}'
rf'This should work \{foo}'
f'\}' # syntax error (we currently don't report this)
f'\}}' # ok
# f-strings with unicode literals of the form `\N{...}`
f'{degrees:0.0f}\N{DEGREE SIGN}'
f"{degrees:0.0f}\N{DEGREE SIGN}"
f'''{degrees:0.0f}\N{DEGREE SIGN}'''
f"""{degrees:0.0f}\N{DEGREE SIGN}"""
# double curlies in f-strings with various kinds of quoting
f'{{ {foo} }}'
f"{{ {foo} }}"
f'''{{ {foo} }}'''
f"""{{ {foo} }}"""
# Empty f-strings
f''
f""
f''''''
f""""""
r'\NUL' # _Not_ a named unicode escape (`\N{...}`)
f'res: {val:{width:0}.{prec:1}}'