mirror of
https://github.com/typst/typst
synced 2025-05-14 17:15:28 +08:00
Parenthesized imports (#4869)
Co-authored-by: Laurenz <laurmaedje@gmail.com>
This commit is contained in:
parent
ecad396cc8
commit
1997db00f3
@ -989,9 +989,22 @@ fn module_import(p: &mut Parser) {
|
|||||||
// imported at the same time.
|
// imported at the same time.
|
||||||
p.expect(SyntaxKind::Ident);
|
p.expect(SyntaxKind::Ident);
|
||||||
}
|
}
|
||||||
if p.eat_if(SyntaxKind::Colon) && !p.eat_if(SyntaxKind::Star) {
|
|
||||||
|
if p.eat_if(SyntaxKind::Colon) {
|
||||||
|
if p.at(SyntaxKind::LeftParen) {
|
||||||
|
let m1 = p.marker();
|
||||||
|
p.enter_newline_mode(NewlineMode::Continue);
|
||||||
|
p.assert(SyntaxKind::LeftParen);
|
||||||
|
|
||||||
|
import_items(p);
|
||||||
|
|
||||||
|
p.expect_closing_delimiter(m1, SyntaxKind::RightParen);
|
||||||
|
p.exit_newline_mode();
|
||||||
|
} else if !p.eat_if(SyntaxKind::Star) {
|
||||||
import_items(p);
|
import_items(p);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
p.wrap(m, SyntaxKind::ModuleImport);
|
p.wrap(m, SyntaxKind::ModuleImport);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1021,6 +1034,7 @@ fn import_items(p: &mut Parser) {
|
|||||||
p.expect(SyntaxKind::Comma);
|
p.expect(SyntaxKind::Comma);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
p.wrap(m, SyntaxKind::ImportItems);
|
p.wrap(m, SyntaxKind::ImportItems);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,6 +55,49 @@
|
|||||||
#test(name, "Klaus")
|
#test(name, "Klaus")
|
||||||
#test(othername, "Klaus")
|
#test(othername, "Klaus")
|
||||||
|
|
||||||
|
--- import-items-parenthesized ---
|
||||||
|
#import "module.typ": ()
|
||||||
|
#import "module.typ": (a)
|
||||||
|
#import "module.typ": (a, b)
|
||||||
|
#import "module.typ": (a, b, c, d)
|
||||||
|
|
||||||
|
#test(a, none)
|
||||||
|
#test(b, 1)
|
||||||
|
#test(c, 2)
|
||||||
|
#test(d, 3)
|
||||||
|
|
||||||
|
--- import-items-parenthesized-multiline ---
|
||||||
|
#import "module.typ": (
|
||||||
|
a
|
||||||
|
)
|
||||||
|
#import "module.typ": (
|
||||||
|
a, b as e,
|
||||||
|
c,
|
||||||
|
|
||||||
|
|
||||||
|
d,
|
||||||
|
)
|
||||||
|
|
||||||
|
#test(a, none)
|
||||||
|
#test(e, 1)
|
||||||
|
#test(c, 2)
|
||||||
|
#test(d, 3)
|
||||||
|
|
||||||
|
--- import-items-parenthesized-invalid ---
|
||||||
|
// Error: 23-24 unclosed delimiter
|
||||||
|
#import "module.typ": (a, b, c
|
||||||
|
|
||||||
|
--- import-items-parenthesized-invalid-2 ---
|
||||||
|
// Error: 23-24 unclosed delimiter
|
||||||
|
#import "module.typ": (
|
||||||
|
|
||||||
|
--- import-items-parenthesized-invalid-3 ---
|
||||||
|
// Error: 23-24 unclosed delimiter
|
||||||
|
#import "module.typ": (
|
||||||
|
a, b,
|
||||||
|
c,
|
||||||
|
|
||||||
|
|
||||||
--- import-from-function-scope ---
|
--- import-from-function-scope ---
|
||||||
// Test importing from function scopes.
|
// Test importing from function scopes.
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user