goatlang / goat

Extended flavor of the Go programming language, aiming for increased value safety and maintainability
MIT License
63 stars 1 forks source link

Import Go files and vice versa #5

Closed marcelloh closed 1 year ago

marcelloh commented 1 year ago

"This means they can import regular Go files but also be safely imported from any other Go file." Are we talking about Go Source files?

because if the syntax is changing, how would this be possible?

avivcarmis commented 1 year ago

@marcelloh, A bit of clarifying should be added there. .go files will not be able to directly import .goat files. however, goat should be used to generate/transpile regular .go files from those .goat files. Then go sources will be able to import those. Libraries written in goat should generate go sources before shipped in order to allow go projects to safely import them.

It already works well in the TypeScript ecosystem, as .ts files can safely import any .js files but not vise versa. However, when .ts written libraries are shipped, they include files translated to .js. For example, here's the official javascript MongoDB driver written mostly in TypeScript. Many of the consumers of this lib use pure javascript to import it although it unable to import .ts files directly.

Does it seem reasonable?

marcelloh commented 1 year ago

Then I would like to see that generator/transpiler (or an explanation on specific parts) to understand how the goat-code would turn into Go-code. Now now btw :-) Follow up question : can a person influence the way that generator/transpiler works (to have an outcome that matches their programming style)?

avivpxi commented 1 year ago

That generator is something we need to implement here, once we done defining the language spec and syntactic rules. But essential, if the syntax is similar, it will probably be some kind of a fork of the go parser package to parse .goat files into an AST .

Regarding the followup: can you share an example of such an option? Any idea for improvement is highly appreciated.

marcelloh commented 1 year ago

I have no idea (yet) but I can image that a generator would perhaps use some kind of template model for certain parts. In that case one might alter the template part to generate a slightly different outcome. (I once made a generator , that used templates (which were derived from a base program; altering the base would led to new templates and so, for new generated Go software)

avivpxi commented 1 year ago

Seems reasonable that goat would have some kind of config that would allow configuring various compilation and generation settings, right? Let's leave this discussion open for when concrete ideas come up. I can ping you once we start implementing the parser/generator

marcelloh commented 1 year ago

That's ok