TranspileGo returns transpiled tokens assuming Go code. Unpacks any backtick encapsulated shell commands.
(toks Tokens)
| 142 | // TranspileGo returns transpiled tokens assuming Go code. |
| 143 | // Unpacks any backtick encapsulated shell commands. |
| 144 | func (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 |
no test coverage detected