Skip to content

Commit 9d7d629

Browse files
authored
Merge pull request #4384 from harupy/parse-formatted-value
Fix the location of `FormattedValue`
2 parents 16173bf + 439298e commit 9d7d629

22 files changed

Lines changed: 2195 additions & 355 deletions

‎parser/python.lalrpop‎

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1353,18 +1353,11 @@ OneOrMore<T>: Vec<T> = {
13531353
};
13541354

13551355
Constant: ast::Constant = {
1356-
<b:bytes+> => ast::Constant::Bytes(b.into_iter().flatten().collect()),
13571356
<value:int> => ast::Constant::Int(value),
13581357
<value:float> => ast::Constant::Float(value),
13591358
<s:complex> => ast::Constant::Complex { real: s.0, imag: s.1 },
13601359
};
13611360

1362-
Bytes: Vec<u8> = {
1363-
<s:bytes+> => {
1364-
s.into_iter().flatten().collect::<Vec<u8>>()
1365-
},
1366-
};
1367-
13681361
Identifier: String = <s:name> => s;
13691362

13701363
// Hook external lexer:
@@ -1462,8 +1455,11 @@ extern {
14621455
int => lexer::Tok::Int { value: <BigInt> },
14631456
float => lexer::Tok::Float { value: <f64> },
14641457
complex => lexer::Tok::Complex { real: <f64>, imag: <f64> },
1465-
string => lexer::Tok::String { value: <String>, kind: <StringKind> },
1466-
bytes => lexer::Tok::Bytes { value: <Vec<u8>> },
1458+
string => lexer::Tok::String {
1459+
value: <String>,
1460+
kind: <StringKind>,
1461+
triple_quoted: <bool>
1462+
},
14671463
name => lexer::Tok::Name { name: <String> },
14681464
"\n" => lexer::Tok::Newline,
14691465
";" => lexer::Tok::Semi,

‎parser/src/error.rs‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,15 @@ pub enum FStringErrorType {
101101
UnterminatedString,
102102
}
103103

104+
impl FStringErrorType {
105+
pub fn to_lexical_error(self, location: Location) -> LexicalError {
106+
LexicalError {
107+
error: LexicalErrorType::FStringError(self),
108+
location,
109+
}
110+
}
111+
}
112+
104113
impl fmt::Display for FStringErrorType {
105114
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
106115
match self {

‎parser/src/fstring.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// We no longer need this file
12
use self::FStringErrorType::*;
23
use crate::{
34
ast::{Constant, ConversionFlag, Expr, ExprKind, Location},

0 commit comments

Comments
 (0)