MCPcopy Create free account
hub / github.com/cogentcore/core / TranspileCode

Method TranspileCode

shell/shell.go:286–306  ·  view source on GitHub ↗

TranspileCode processes each line of given code, adding the results to the LineStack

(code string)

Source from the content-addressed store, hash-verified

284// TranspileCode processes each line of given code,
285// adding the results to the LineStack
286func (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
309func (sh *Shell) TranspileCodeFromFile(file string) error {

Callers 4

TranspileCodeFromFileMethod · 0.95
TranspileConfigMethod · 0.95
TestCommandFunction · 0.95
EvalMethod · 0.80

Calls 4

TranspileLineMethod · 0.95
AddLineMethod · 0.95
AddChunkMethod · 0.95
SplitMethod · 0.80

Tested by 1

TestCommandFunction · 0.76