Skip to content

Commit 12ff50d

Browse files
Removed unnecessary regular expressions
1 parent 5299f2b commit 12ff50d

File tree

1 file changed

+6
-33
lines changed

1 file changed

+6
-33
lines changed

bpython/line.py

Lines changed: 6 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -65,41 +65,14 @@ def current_word(cursor_offset: int, line: str) -> Optional[LinePart]:
6565
# end matching at closing double-quote if one is present
6666
"?"""
6767

68-
_match_int_and_float = \
69-
r"""\-? # match a negative sign if present
70-
\d+ # match any number of digits
71-
(?:\.\d*)? # if there is a decimal point, match it and subsequent digits
72-
|\- # if only a negative sign has been entered, match it
73-
"""
74-
75-
# used to match possible elements in a tuple
76-
_match_tuple_element = (
77-
f'(?:{_match_single_quote_str_bytes}|' # match single quote str/bytes repr
78-
f'{_match_double_quote_str_bytes}|' # or double quote str/bytes repr
79-
f'{_match_int_and_float})' # or int or float repr
80-
)
81-
82-
_match_tuple = \
83-
rf""" # match open parenthesis
84-
\(
85-
# matches any number of tuple elements followed by `,` then ` `
86-
(?:{_match_tuple_element},[ ])*
87-
# followed by another element being typed or one element tuple i.e. `(1,)`
88-
(?:{_match_tuple_element},?)?
89-
# match close parentesis if present
90-
\)?
91-
"""
92-
9368
# match valid identifier name followed by `[` character
9469
_match_dict_before_key = r"""[\w_][\w0-9._]*\["""
9570

9671
_current_dict_key_re = LazyReCompile(
97-
f'{_match_dict_before_key}('
72+
f'{_match_dict_before_key}((?:'
9873
f'{_match_single_quote_str_bytes}|'
9974
f'{_match_double_quote_str_bytes}|'
100-
f'{_match_int_and_float}|'
101-
f'{_match_tuple}|'
102-
f'{_match_all_dict_keys}|)',
75+
f'{_match_all_dict_keys}|)*)',
10376
re.VERBOSE
10477
)
10578

@@ -116,12 +89,12 @@ def current_dict_key(cursor_offset: int, line: str) -> Optional[LinePart]:
11689
_capture_dict_name = r"""([\w_][\w0-9._]*)\["""
11790

11891
_current_dict_re = LazyReCompile(
119-
f'{_capture_dict_name}('
92+
f'{_capture_dict_name}((?:'
12093
f'{_match_single_quote_str_bytes}|'
12194
f'{_match_double_quote_str_bytes}|'
122-
f'{_match_int_and_float}|'
123-
f'{_match_tuple}|'
124-
f'{_match_all_dict_keys}|)',
95+
# f'{_match_int_and_float}|'
96+
# f'{_match_tuple}|'
97+
f'{_match_all_dict_keys}|)*)',
12598
re.VERBOSE
12699
)
127100

0 commit comments

Comments
 (0)