You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Allow importing with array syntax (like in Python) #3065
feature requestNew feature or requestgood contributionSuitable for contribution, but unlike "good first issue", it may need prior experiencesyntaxAbout syntax, parsing, etc.
I get that for = long heading it isn't great to be able to place heading's content on multiple lines (becomes less readable, but would be nice for very long heading), but for import statement it has become obvious that sometimes import lines are simply too long. Look even at Rust's imports (use) — maybe something like that also would work (but it's less understandable, than a simple array-syntax imports).
Use Case
Remove clutter on import lines and make huge imports more readable and maintainable.
Reacted by Andrew Voynov, PgBiel, max397574, Eric Biedert, Daniel Bershatsky, abel1502 and Chaoses-Ib
Also using python as a reference, there are times when a large amount of imports mean you should be doing #import utils.typ and calling utils.thing1, utils.thing2, etc. instead.
Similar to import numpy as np -- you don't use from numpy import ones, zeros, sum, ..., but instead import the module as a shorthand and access things from there.
Not saying array import is bad, just that sometimes so many imports are a sign you should just be importing the whole module instead
@ntjess, I understand and agree. The main point is to provide an ability/choice to import things differently, in a more convenient and readable way. Sometime things that I import should just be global, because their names aren't shadowing anything else and because its reference will be shorter (i.e., ones instead of np.ones) — shorter is mainly better (fewer chars, less code, more readable, more compact, less file size).
This is just a simple argument, but I hope I got my point across.
Surprisingly, you are right, but only 99%. The trailing comma makes an error "unexpected closing paren" (why "paren" though?), so unfortunately you have to sacrifice it in this situation. I thought that parentheses will also create a scope like [] or {}, but today I learned that they do not create any scope (wow!). But that's a great finding/workaround anyway.
feature requestNew feature or requestgood contributionSuitable for contribution, but unlike "good first issue", it may need prior experiencesyntaxAbout syntax, parsing, etc.
Activity
emilyyyylime commentedon Dec 25, 2023
I expected either
\as a continuation character or just a terminating comma to work as line continuations, but it seems both don't work. +1ntjess commentedon Jan 5, 2024
It's not ideal, but this does work in the meantime (tested on v0.10):
Also using python as a reference, there are times when a large amount of imports mean you should be doing
#import utils.typand callingutils.thing1,utils.thing2, etc. instead.Similar to
import numpy as np-- you don't usefrom numpy import ones, zeros, sum, ..., but instead import the module as a shorthand and access things from there.Not saying array import is bad, just that sometimes so many imports are a sign you should just be importing the whole module instead
Andrew15-5 commentedon Jan 5, 2024
@ntjess, I understand and agree. The main point is to provide an ability/choice to import things differently, in a more convenient and readable way. Sometime things that I import should just be global, because their names aren't shadowing anything else and because its reference will be shorter (i.e.,
onesinstead ofnp.ones) — shorter is mainly better (fewer chars, less code, more readable, more compact, less file size).This is just a simple argument, but I hope I got my point across.
Andrew15-5 commentedon Jan 5, 2024
Surprisingly, you are right, but only 99%. The trailing comma makes an error "unexpected closing paren" (why "paren" though?), so unfortunately you have to sacrifice it in this situation. I thought that parentheses will also create a scope like
[]or{}, but today I learned that they do not create any scope (wow!). But that's a great finding/workaround anyway.Very simple (working) tablex example
ntjess commentedon Jan 5, 2024
You're correct; thanks for checking. I edited my answer to remove the trailing comma.
ntjess commentedon Mar 12, 2024
@laurmaedje This syntax causes an error in the 0.11 rc -- is this intentional?
Compiles in 0.10, panics in 0.11 with
unclosed delimiter+unexpected closing parenlaurmaedje commentedon Mar 12, 2024
No, that's a regression. I'll look into it.
laurmaedje commentedon Mar 12, 2024
@ntjess I fixed the regression with #3633
Adham-A commentedon Aug 21, 2024
Hello I would like to work on this issue if this is still availaible as my first contribution to Typst,
Just a few questions :
I've looked into the code to understand how it works and as far as my quick search goes :
I found this :
https://github.com/typst/typst/blob/main/crates/typst-syntax/src/parser.rs#L789
So the goal here is to modify a part of the Parser/Lexer or is it something way simpler ?
laurmaedje commentedon Aug 21, 2024
@Adham-A yep, this would need to be added in the parser, syntax tree, and code evaluation.
Adham-A commentedon Aug 21, 2024
Thank you I will look into this then, is there some documentation availaible on the inner workings of this to help ?
laurmaedje commentedon Aug 21, 2024
There is a bit of documentation in an unmerged PR. But beyond that, sadly not much. :/