MCPcopy Create free account
hub / github.com/GongShichen/LuminaCode / Tokenize

Function Tokenize

tools/bash/tokenizer.go:52–97  ·  view source on GitHub ↗
(command string, stripQuotes bool)

Source from the content-addressed store, hash-verified

50var envNameRe = regexp.MustCompile(`^[A-Za-z_]\w*$`)
51
52func Tokenize(command string, stripQuotes bool) []string {
53 var tokens []string
54 var current []rune
55 inSingle := false
56 inDouble := false
57 i := 0
58 runes := []rune(command)
59 n := len(runes)
60
61 for i < n {
62 ch := runes[i]
63 if ch == '\\' && i+1 < n {
64 nextCh := runes[i+1]
65 if nextCh == ' ' || nextCh == '\t' || nextCh == '\\' || nextCh == '\'' || nextCh == '"' {
66 current = append(current, nextCh)
67 i += 2
68 continue
69 }
70 i += 1
71 current = append(current, ch)
72 continue
73 } else if ch == '\'' && !inDouble {
74 inSingle = !inSingle
75 if !stripQuotes {
76 current = append(current, ch)
77 }
78 } else if ch == '"' && !inSingle {
79 inDouble = !inDouble
80 if !stripQuotes {
81 current = append(current, ch)
82 }
83 } else if (ch == ' ' || ch == '\t') && !inSingle && !inDouble {
84 if current != nil && len(current) > 0 {
85 tokens = append(tokens, string(current))
86 current = []rune{}
87 }
88 } else {
89 current = append(current, ch)
90 }
91 i += 1
92 }
93 if current != nil && len(current) > 0 {
94 tokens = append(tokens, string(current))
95 }
96 return tokens
97}
98
99func SplitPipeline(command string) []string {
100 var segments []string

Callers 11

ExtractBaseCommandFunction · 0.85
classifySensitiveReadFunction · 0.85
hasOutputRedirectionFunction · 0.85
extractSedExpressionsFunction · 0.85
hasInplaceFlagFunction · 0.85
extractSedFileArgsFunction · 0.85
parseCommandStructureFunction · 0.85
GetSimpleCommandPrefixFunction · 0.85

Calls

no outgoing calls