diff --git a/parser/src/python.lalrpop b/parser/src/python.lalrpop index db1a33312..d51295731 100644 --- a/parser/src/python.lalrpop +++ b/parser/src/python.lalrpop @@ -202,18 +202,19 @@ RaiseStatement: ast::Statement = { }; ImportStatement: ast::Statement = { - "import" >>> => { + "import" >> => { ast::Statement { location, node: ast::StatementType::Import { names }, } }, - "from" "import" => { + "from" "import" => { + let (level, module) = source; ast::Statement { location, node: ast::StatementType::ImportFrom { - level: n.0, - module: n.1, + level, + module, names }, } @@ -235,8 +236,8 @@ ImportDots: usize = { }; ImportAsNames: Vec = { - >> => i, - "(" >> ")" => i, + >> => i, + "(" >> ")" => i, "*" => { // Star import all vec![ast::ImportSymbol { symbol: "*".to_string(), alias: None }] @@ -245,7 +246,7 @@ ImportAsNames: Vec = { #[inline] -ImportPart: ast::ImportSymbol = { +ImportAsAlias: ast::ImportSymbol = { => ast::ImportSymbol { symbol, alias: a.map(|a| a.1) }, }; @@ -608,7 +609,7 @@ Decorator: ast::Expression = { }; YieldExpr: ast::Expression = { - "yield" => ast::Expression { + "yield" => ast::Expression { location, node: ast::ExpressionType::Yield { value: value.map(Box::new) } }, diff --git a/tests/snippets/import.py b/tests/snippets/import.py index 7c730c265..2996a27cc 100644 --- a/tests/snippets/import.py +++ b/tests/snippets/import.py @@ -64,3 +64,9 @@ with OverrideImportContext(): # pass #else: # raise AssertionError('X should not be imported') + +from testutils import assertRaises + +with assertRaises(SyntaxError): + exec('import') +