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

Method TranspileGo

shell/transpile.go:144–165  ·  view source on GitHub ↗

TranspileGo returns transpiled tokens assuming Go code. Unpacks any backtick encapsulated shell commands.

(toks Tokens)

Source from the content-addressed store, hash-verified

142// TranspileGo returns transpiled tokens assuming Go code.
143// Unpacks any backtick encapsulated shell commands.
144func (sh *Shell) TranspileGo(toks Tokens) Tokens {
145 n := len(toks)
146 if n == 0 {
147 return toks
148 }
149 if toks[0].Tok == token.FUNC { // reorder as an assignment
150 if len(toks) > 1 && toks[1].Tok == token.IDENT {
151 toks[0] = toks[1]
152 toks.Insert(1, token.DEFINE)
153 toks[2] = &Token{Tok: token.FUNC}
154 }
155 }
156 gtoks := make(Tokens, 0, len(toks)) // return tokens
157 for _, tok := range toks {
158 if sh.TypeDepth == 0 && tok.IsBacktickString() {
159 gtoks = append(gtoks, sh.TranspileExecString(tok.Str, true)...)
160 } else {
161 gtoks = append(gtoks, tok)
162 }
163 }
164 return gtoks
165}
166
167// TranspileExecString returns transpiled tokens assuming Exec code,
168// from a backtick-encoded string, with the given bool indicating

Callers 2

TranspileLineTokensMethod · 0.95
TranspileExecMethod · 0.95

Calls 3

TranspileExecStringMethod · 0.95
IsBacktickStringMethod · 0.80
InsertMethod · 0.45

Tested by

no test coverage detected