cuelang / cue

CUE has moved to https://github.com/cue-lang/cue
https://cuelang.org
Apache License 2.0
3.09k stars 171 forks source link

cmd/cue: import/export (go|rust|...) #1036

Closed myitcv closed 3 years ago

myitcv commented 3 years ago

In #646 we discuss renaming cue get go to be cue import go. In the future we also intend to more clearly support exporting from CUE to some other language representation (this is currently made possible via the cuelang.org/go/encoding/gocode package) from the command line.

Which begs the question: what about languages other than Go?

For example, @nyarly has previous enquired about Rust being added to that list.

This is a general placeholder for import/export support for "insert your language here".

Building on the motivation in #646, this would purely be the support for importing/exporting from/to "a another language", e.g. Rust. The method for resolving packages (or the equivalent in any given language) would be delegated to language specific tooling/loader/something. e.g. for Go, package resolution is handled by go/packages, which requires that (as of Go 1.16) a go.mod is present through which a package can be resolved.

verdverm commented 3 years ago

I wonder if there is a way to use tree-sitter , given all the language grammars that have accumulated there.

There looks to be an unofficial Go binding here: https://github.com/smacker/go-tree-sitter


I'm going to guess that "tree-standing" (for export) won't work out well after exploring some of the grammars. We'd probably need to define a language format (in CUE of course :) for generation. Maybe that format maps onto the tree-sitter grammar, but it looks to be quite complicated due to the widely varied syntax across languages.

myitcv commented 3 years ago

For import (currently cue get go) we need type information for Go, and suspect we would for every other language: syntax by itself would not be enough (unless I misunderstood what you were suggesting, or am missing a piece in the puzzle here with respect to tree sitter?). For export I'm not sure of the need for a common format - we simply need to take convert from CUE API values (already well defined) to a target language (could be as simple as fmt.Printf calls, could use text/template, could use an AST for the language...)

cueckoo commented 3 years ago

This issue has been migrated to https://github.com/cue-lang/cue/issues/1036.

For more details about CUE's migration to a new home, please see https://github.com/cue-lang/cue/issues/1078.