summaryrefslogtreecommitdiff
path: root/src/parse/parser.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2021-07-08 21:16:16 +0200
committerLaurenz <laurmaedje@gmail.com>2021-07-08 21:16:16 +0200
commit551e3af9d09a03aaa246cac46b98124bc10835ba (patch)
treeb075a93df7cb608eae9650e497fb6a1336d80212 /src/parse/parser.rs
parent5c327e249e03ac303e7fef40e2df6c6ef834db66 (diff)
Replace using with from
Diffstat (limited to 'src/parse/parser.rs')
-rw-r--r--src/parse/parser.rs10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/parse/parser.rs b/src/parse/parser.rs
index 8ea80d68..1e0f2f5d 100644
--- a/src/parse/parser.rs
+++ b/src/parse/parser.rs
@@ -51,6 +51,8 @@ pub enum Group {
Stmt,
/// A group for a single expression, ended by a line break.
Expr,
+ /// A group for import items, ended by a semicolon, line break or `from`.
+ Imports,
}
impl<'s> Parser<'s> {
@@ -128,6 +130,7 @@ impl<'s> Parser<'s> {
Group::Brace => self.assert(Token::LeftBrace),
Group::Stmt => {}
Group::Expr => {}
+ Group::Imports => {}
}
}
@@ -149,6 +152,7 @@ impl<'s> Parser<'s> {
Group::Brace => Some((Token::RightBrace, true)),
Group::Stmt => Some((Token::Semicolon, false)),
Group::Expr => None,
+ Group::Imports => None,
} {
if self.next == Some(end) {
// Bump the delimeter and return. No need to rescan in this case.
@@ -361,6 +365,7 @@ impl<'s> Parser<'s> {
Token::RightBracket => self.inside(Group::Bracket),
Token::RightBrace => self.inside(Group::Brace),
Token::Semicolon => self.inside(Group::Stmt),
+ Token::From => self.inside(Group::Imports),
Token::Space(n) => n >= 1 && self.stop_at_newline(),
_ => false,
} {
@@ -371,7 +376,10 @@ impl<'s> Parser<'s> {
/// Whether the active group ends at a newline.
fn stop_at_newline(&self) -> bool {
let active = self.groups.last().map(|group| group.kind);
- matches!(active, Some(Group::Stmt) | Some(Group::Expr))
+ matches!(
+ active,
+ Some(Group::Stmt) | Some(Group::Expr) | Some(Group::Imports)
+ )
}
/// Whether we are inside the given group.