Skip to content

Commit 7bcf2c3

Browse files
authored
Merge pull request RustPython#3014 from leesungbin/underscore_grammar
Solve some lexical error with underscore
2 parents dd3d289 + d7e9c7d commit 7bcf2c3

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

Lib/test/test_grammar.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,6 @@ def test_float_exponent_tokenization(self):
179179
self.assertEqual(1 if 0else 0, 0)
180180
self.assertRaises(SyntaxError, eval, "0 if 1Else 0")
181181

182-
# TODO: RUSTPYTHON
183-
@unittest.expectedFailure
184182
def test_underscore_literals(self):
185183
for lit in VALID_UNDERSCORE_LITERALS:
186184
self.assertEqual(eval(lit), eval(lit.replace('_', '')))

parser/src/lexer.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,10 +316,21 @@ where
316316

317317
// 1e6 for example:
318318
if self.chr0 == Some('e') || self.chr0 == Some('E') {
319+
if self.chr1 == Some('_') {
320+
return Err(LexicalError {
321+
error: LexicalErrorType::OtherError("Invalid Syntax".to_owned()),
322+
location: self.get_pos(),
323+
});
324+
}
319325
value_text.push(self.next_char().unwrap().to_ascii_lowercase());
320-
321326
// Optional +/-
322327
if self.chr0 == Some('-') || self.chr0 == Some('+') {
328+
if self.chr1 == Some('_') {
329+
return Err(LexicalError {
330+
error: LexicalErrorType::OtherError("Invalid Syntax".to_owned()),
331+
location: self.get_pos(),
332+
});
333+
}
323334
value_text.push(self.next_char().unwrap());
324335
}
325336

0 commit comments

Comments
 (0)