Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
cython
Commits
9020149c
Commit
9020149c
authored
Mar 23, 2016
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
simplify some error handling code in f-string parser
parent
29c1030e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
4 additions
and
11 deletions
+4
-11
Cython/Compiler/Parsing.py
Cython/Compiler/Parsing.py
+4
-11
No files found.
Cython/Compiler/Parsing.py
View file @
9020149c
...
@@ -1030,7 +1030,7 @@ def p_f_string_expr(s, unicode_value, pos, starting_index):
...
@@ -1030,7 +1030,7 @@ def p_f_string_expr(s, unicode_value, pos, starting_index):
# and the index in the string that follows the expression.
# and the index in the string that follows the expression.
i
=
starting_index
i
=
starting_index
size
=
len
(
unicode_value
)
size
=
len
(
unicode_value
)
conversion_char
=
None
conversion_char
=
terminal_char
=
format_spec
=
None
format_spec_str
=
u''
format_spec_str
=
u''
nested_depth
=
0
nested_depth
=
0
...
@@ -1083,14 +1083,10 @@ def p_f_string_expr(s, unicode_value, pos, starting_index):
...
@@ -1083,14 +1083,10 @@ def p_f_string_expr(s, unicode_value, pos, starting_index):
if
terminal_char
==
'!'
:
if
terminal_char
==
'!'
:
i
+=
1
i
+=
1
if
i
>=
size
:
if
i
+
2
>
size
:
s
.
error
(
"invalid conversion char at end of string"
)
s
.
error
(
"invalid conversion char at end of string"
)
conversion_char
=
unicode_value
[
i
]
conversion_char
=
unicode_value
[
i
]
i
+=
1
i
+=
1
if
i
>=
size
:
s
.
error
(
"invalid conversion char at end of string"
)
terminal_char
=
unicode_value
[
i
]
terminal_char
=
unicode_value
[
i
]
if
terminal_char
==
':'
:
if
terminal_char
==
':'
:
...
@@ -1123,7 +1119,7 @@ def p_f_string_expr(s, unicode_value, pos, starting_index):
...
@@ -1123,7 +1119,7 @@ def p_f_string_expr(s, unicode_value, pos, starting_index):
format_spec_str
=
unicode_value
[
start_format_spec
:
i
]
format_spec_str
=
unicode_value
[
start_format_spec
:
i
]
if
terminal_char
!=
'}'
:
if
terminal_char
!=
'}'
:
s
.
error
(
"missing '}' in format string expression'
"
)
s
.
error
(
"missing '}' in format string expression'
, found '%s'"
%
terminal_char
)
# parse the expression as if it was surrounded by parentheses
# parse the expression as if it was surrounded by parentheses
buf
=
StringIO
(
'(%s)'
%
expr_str
)
buf
=
StringIO
(
'(%s)'
%
expr_str
)
...
@@ -1137,12 +1133,9 @@ def p_f_string_expr(s, unicode_value, pos, starting_index):
...
@@ -1137,12 +1133,9 @@ def p_f_string_expr(s, unicode_value, pos, starting_index):
# the format spec is itself treated like an f-string
# the format spec is itself treated like an f-string
if
format_spec_str
is
not
None
:
if
format_spec_str
is
not
None
:
format_spec
=
ExprNodes
.
JoinedStrNode
(
pos
,
values
=
p_f_string
(
s
,
format_spec_str
,
pos
))
format_spec
=
ExprNodes
.
JoinedStrNode
(
pos
,
values
=
p_f_string
(
s
,
format_spec_str
,
pos
))
else
:
format_spec
=
None
return
i
+
1
,
ExprNodes
.
FormattedValueNode
(
return
i
+
1
,
ExprNodes
.
FormattedValueNode
(
s
.
position
(),
value
=
expr
,
conversion_char
=
conversion_char
,
s
.
position
(),
value
=
expr
,
conversion_char
=
conversion_char
,
format_spec
=
format_spec
)
format_spec
=
format_spec
)
# since PEP 448:
# since PEP 448:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment