TranspileFile transpiles the given input cosh file to the given output Go file, adding package main and func main declarations.
(in string, out string)
| 318 | // TranspileFile transpiles the given input cosh file to the given output Go file, |
| 319 | // adding package main and func main declarations. |
| 320 | func (sh *Shell) TranspileFile(in string, out string) error { |
| 321 | err := sh.TranspileCodeFromFile(in) |
| 322 | if err != nil { |
| 323 | return err |
| 324 | } |
| 325 | sh.Lines = slices.Insert(sh.Lines, 0, "package main", "", "func main() {", "shell := shell.NewShell()") |
| 326 | sh.Lines = append(sh.Lines, "}") |
| 327 | src := []byte(sh.Code()) |
| 328 | // fmt.Println(string(src)) |
| 329 | res, err := imports.Process(out, src, nil) |
| 330 | if err != nil { |
| 331 | res = src |
| 332 | slog.Error(err.Error()) |
| 333 | } else { |
| 334 | err = sh.DepthError() |
| 335 | } |
| 336 | werr := os.WriteFile(out, res, 0666) |
| 337 | return errors.Join(err, werr) |
| 338 | } |
| 339 | |
| 340 | // AddError adds the given error to the error stack if it is non-nil, |
| 341 | // and calls the Cancel function if set, to stop execution. |
no test coverage detected