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

Method TranspileLine

shell/transpile.go:18–38  ·  view source on GitHub ↗

TranspileLine is the main function for parsing a single line of shell input, returning a new transpiled line of code that converts Exec code into corresponding Go function calls.

(ln string)

Source from the content-addressed store, hash-verified

16// returning a new transpiled line of code that converts Exec code into corresponding
17// Go function calls.
18func (sh *Shell) TranspileLine(ln string) string {
19 if len(ln) == 0 {
20 return ln
21 }
22 if strings.HasPrefix(ln, "#!") {
23 return ""
24 }
25 toks := sh.TranspileLineTokens(ln)
26 paren, brace, brack := toks.BracketDepths()
27 sh.ParenDepth += paren
28 sh.BraceDepth += brace
29 sh.BrackDepth += brack
30 if sh.TypeDepth > 0 && sh.BraceDepth == 0 {
31 sh.TypeDepth = 0
32 }
33 if sh.DeclDepth > 0 && sh.ParenDepth == 0 {
34 sh.DeclDepth = 0
35 }
36 // logx.PrintlnDebug("depths: ", sh.ParenDepth, sh.BraceDepth, sh.BrackDepth)
37 return toks.Code()
38}
39
40// TranspileLineTokens returns the tokens for the full line
41func (sh *Shell) TranspileLineTokens(ln string) Tokens {

Callers 2

TranspileCodeMethod · 0.95
TestTranspileFunction · 0.95

Calls 3

TranspileLineTokensMethod · 0.95
BracketDepthsMethod · 0.80
CodeMethod · 0.45

Tested by 1

TestTranspileFunction · 0.76