So, I've been thinking about a new syntax for import statements for a while, and I think I found something that most people will like. I'm opening this issue so that people can discuss about this syntax in a peaceful way, in order to make the perfect syntax (well, maybe not everybody will like it, but I hope that most people will).
Keep in mind that this syntax is still a WIP and I think has a lot of room for improvements.
The syntax was inspired by these languages:
Python,
CoffeeScript/Livescript
It's also really flexible so it fits multiple cases & personal preferences.
Alright, so the syntax would follow these simple rules:
from package import module: for importing only one module,
from package import [module1, module2]: for multiple modules (you can have as many modules you want),
import package: for importing all modules in a package
The same applies to subpackages:
from package.subpackage import module, etc.
Example
from luxe import [
Input, Scene, Sprite
Visual, Color, AppConfig
Particles, Entity, Text
] #CoffeeScript arrays are used for list of modules
from luxe.structural import [Pool, Bag]
from luxe.options import GeometryOptions
from mint import Control
from mint.types import Types
from mint.render.luxe import [LuxeMintRender, Convert]
from mint.layout.margins import Margins
import states
As you can see, the example code is quite redundant (lots of from & import), so it could also support an optional syntax for less redundancy in the code:
import! #the exclamation mark tells the compiler that this is an import block
luxe:
<<: [
Input, Scene, Sprite
Visual, Color, AppConfig
Particles, Entity, Text
] #the << child is used for modules that are part of the parent package (here luxe)
structural: [Pool, Bag] #child packages are nested objects
options: GeometryOptions
mint:
<<: Control
types: Types
render.luxe: [LuxeMintRender, Convert]
layout.margins: Margins #when there is no need to nest a child, use the . shorthand
states: *
This code would be compiled in the same way as the previous example. It would work the exact same way as CoffeeScript object notation, except for the first item in the list (as you can see in the example above)
Conditional compilation
TODO
So, what do you think about the syntax?
Please share your opinions below as it is the only way we can progress :smile:
So, I've been thinking about a new syntax for
import
statements for a while, and I think I found something that most people will like. I'm opening this issue so that people can discuss about this syntax in a peaceful way, in order to make the perfect syntax (well, maybe not everybody will like it, but I hope that most people will).Keep in mind that this syntax is still a WIP and I think has a lot of room for improvements.
The syntax was inspired by these languages:
It's also really flexible so it fits multiple cases & personal preferences.
Alright, so the syntax would follow these simple rules:
from package import module
: for importing only one module,from package import [module1, module2]
: for multiple modules (you can have as many modules you want),import package
: for importing all modules in a packageThe same applies to subpackages:
from package.subpackage import module
, etc.Example
output:
Import blocks
As you can see, the example code is quite redundant (lots of
from
&import
), so it could also support an optional syntax for less redundancy in the code:This code would be compiled in the same way as the previous example. It would work the exact same way as CoffeeScript object notation, except for the first item in the list (as you can see in the example above)
Conditional compilation
So, what do you think about the syntax? Please share your opinions below as it is the only way we can progress :smile:
Take a look at the gist
P.S. Sorry for long issue, here's some potatoes![potatoes](http://pngimg.com/upload/potato_PNG7082.png)