Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal: preserve the original source's comments in the generated gop_autogen.go file as much as possible #1864

Open
CarlJi opened this issue Apr 21, 2024 · 0 comments
Labels

Comments

@CarlJi
Copy link
Member

CarlJi commented Apr 21, 2024

Proposal

Currently, when converting Go+ code or Go code to gop_autogen.go, we only preserve the associated documentation of the Node, but the comments are ignored.

For example:

const Pi = 3.14

var version = "1.0"

// comment one
func MulInt(a, b int) int {
	// comment two
	return a * b
}

// comment three
func MulFloat(a, b float64) float64 {
	return a * b
}

// comment four
func Add = (
	// comment five
	func(a int, b int) int {
		// comment six
		return a+b
	}
	func(a float64, b float64) float64 {
		return a+b
	}
)

func Mul = (
	// comment seven
	MulInt
	// comment eight
	MulFloat
)

type M struct {
	Info string
}

type T struct {
	X int
	Y int
}

func (t *T) Info() string {
	return sprintf("%v-%v", t.X, t.Y)
}

func onStart(fn func(int) int) {
	// comment nine
	n := fn(100)
	println n
}

println(version)

// comment ten
onStart x => x*x
onStart x => {
	// comment eleven
	return x*x
}

we got:

// Code generated by gop (Go+); DO NOT EDIT.

package main

import "fmt"

const _ = true
const Pi = 3.14
const Gopo_Mul = "MulInt,MulFloat"

type M struct {
	Info string
}
type T struct {
	X int
	Y int
}
//line examples/002/002.gop:16:1
// comment four
func Add__0(a int, b int) int {
//line examples/002/002.gop:21:1
	return a + b
}
//line examples/002/002.gop:16:1
// comment four
func Add__1(a float64, b float64) float64 {
//line examples/002/002.gop:24:1
	return a + b
}
//line examples/002/002.gop:5:1
// comment one
func MulInt(a int, b int) int {
//line examples/002/002.gop:8:1
	return a * b
}
//line examples/002/002.gop:11:1
// comment three
func MulFloat(a float64, b float64) float64 {
//line examples/002/002.gop:13:1
	return a * b
}

var version = "1.0"
//line examples/002/002.gop:44:1
func (t *T) Info() string {
//line examples/002/002.gop:45:1
	return fmt.Sprintf("%v-%v", t.X, t.Y)
}
//line examples/002/002.gop:48:1
func onStart(fn func(int) int) {
//line examples/002/002.gop:50:1
	n := fn(100)
//line examples/002/002.gop:51:1
	fmt.Println(n)
}
//line examples/002/002.gop:54
func main() {
//line examples/002/002.gop:54:1
	fmt.Println(version)
//line examples/002/002.gop:57:1
	onStart(func(x int) int {
//line examples/002/002.gop:57:1
		return x * x
	})
//line examples/002/002.gop:58:1
	onStart(func(x int) int {
//line examples/002/002.gop:60:1
		return x * x
	})
}

From a completeness perspective, I am thinking it would be better to keep all original comments as much as possible.

Background

Considering that the gop_autogen.go file is intended to be pushed into the code repository, I am currently exploring ways to ensure it adheres to the standard Go coding style.

Workarounds

node

@CarlJi CarlJi changed the title Proposal: preserve the original source's comments in the generated auto_gen.go file as much as possible Proposal: preserve the original source's comments in the generated gop_autogen.go file as much as possible Apr 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants