TranspileCode processes each line of given code, adding the results to the LineStack
(code string)
| 284 | // TranspileCode processes each line of given code, |
| 285 | // adding the results to the LineStack |
| 286 | func (sh *Shell) TranspileCode(code string) { |
| 287 | lns := strings.Split(code, "\n") |
| 288 | n := len(lns) |
| 289 | if n == 0 { |
| 290 | return |
| 291 | } |
| 292 | for _, ln := range lns { |
| 293 | hasDecl := sh.DeclDepth > 0 |
| 294 | tl := sh.TranspileLine(ln) |
| 295 | sh.AddLine(tl) |
| 296 | if sh.BraceDepth == 0 && sh.BrackDepth == 0 && sh.ParenDepth == 1 && sh.lastCommand != "" { |
| 297 | sh.lastCommand = "" |
| 298 | nl := len(sh.Lines) |
| 299 | sh.Lines[nl-1] = sh.Lines[nl-1] + ")" |
| 300 | sh.ParenDepth-- |
| 301 | } |
| 302 | if hasDecl && sh.DeclDepth == 0 { // break at decl |
| 303 | sh.AddChunk() |
| 304 | } |
| 305 | } |
| 306 | } |
| 307 | |
| 308 | // TranspileCodeFromFile transpiles the code in given file |
| 309 | func (sh *Shell) TranspileCodeFromFile(file string) error { |