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)
| 16 | // returning a new transpiled line of code that converts Exec code into corresponding |
| 17 | // Go function calls. |
| 18 | func (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 |
| 41 | func (sh *Shell) TranspileLineTokens(ln string) Tokens { |