Skip to content

Commit aa1a946

Browse files
committed
Add LexicalError
1 parent f08f6f7 commit aa1a946

3 files changed

Lines changed: 24 additions & 5 deletions

File tree

‎parser/src/error.rs‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ pub enum LexicalErrorType {
2525
TabsAfterSpaces,
2626
DefaultArgumentError,
2727
PositionalArgumentError,
28+
IterableArgumentUnpackingError,
29+
StarredExpressionError,
30+
DoubleStarredExpressionError,
31+
GeneratorExpressionError,
2832
DuplicateKeywordArgumentError,
2933
UnrecognizedToken { tok: char },
3034
FStringError(FStringErrorType),
@@ -58,6 +62,21 @@ impl fmt::Display for LexicalErrorType {
5862
LexicalErrorType::PositionalArgumentError => {
5963
write!(f, "positional argument follows keyword argument")
6064
}
65+
LexicalErrorType::IterableArgumentUnpackingError => {
66+
write!(
67+
f,
68+
"iterable argument unpacking follows keyword argument unpacking"
69+
)
70+
}
71+
LexicalErrorType::StarredExpressionError => {
72+
write!(f, "cannot use starred expression here")
73+
}
74+
LexicalErrorType::DoubleStarredExpressionError => {
75+
write!(f, "cannot use double starred expression here")
76+
}
77+
LexicalErrorType::GeneratorExpressionError => {
78+
write!(f, "Generator expression must be parenthesized")
79+
}
6180
LexicalErrorType::UnrecognizedToken { tok } => {
6281
write!(f, "Got unexpected token {}", tok)
6382
}

‎parser/src/python.lalrpop‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,7 +1005,7 @@ Atom: ast::Expr = {
10051005
match elt.node {
10061006
ast::ExprKind::Starred { .. } => {
10071007
Err(LexicalError{
1008-
error : LexicalErrorType::OtherError("cannot use starred expression here".to_string()),
1008+
error : LexicalErrorType::StarredExpressionError,
10091009
location,
10101010
}.into())
10111011
},
@@ -1033,7 +1033,7 @@ Atom: ast::Expr = {
10331033
},
10341034
"(" <location:@L> "**" <e:Expression> ")" =>? {
10351035
Err(LexicalError{
1036-
error : LexicalErrorType::OtherError("cannot use double starred expression here".to_string()),
1036+
error : LexicalErrorType::DoubleStarredExpressionError,
10371037
location,
10381038
}.into())
10391039
},

‎parser/src/python.rs‎

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)