MCPcopy Create free account
hub / github.com/dim-an/cod / tokenize

Method tokenize

shells/tokenize.go:125–199  ·  view source on GitHub ↗

http://man7.org/linux/man-pages/man1/bash.1.html#QUOTING

()

Source from the content-addressed store, hash-verified

123
124// http://man7.org/linux/man-pages/man1/bash.1.html#QUOTING
125func (t *tokenizer) tokenize() error {
126 for {
127 c, err := t.reader.ReadByte()
128 if err == io.EOF {
129 break
130 } else if err != nil {
131 // If we are working with strings we don't expect any exceptions here and can panic if the error occurred.
132 // But in the future we might want to use other ByteReaders so we handle error in ordinary way.
133 return err
134 }
135 switch c {
136 case '\\':
137 c, err = t.reader.ReadByte()
138 if err == io.EOF {
139 t.broken = true
140 t.emitWord()
141 return nil
142 } else if err != nil {
143 return err
144 }
145 if c == '\n' {
146 // ignore it
147 } else {
148 t.builder.WriteByte(c)
149 }
150 case '\n':
151 t.emitWord()
152 t.builder.WriteByte(c)
153 t.emitWord()
154 case '\'':
155 err = t.parseSingleQuote()
156 if err == io.EOF {
157 return nil
158 } else if err != nil {
159 return err
160 }
161 case '"':
162 err = t.parseDoubleQuote()
163 if err == io.EOF {
164 return nil
165 } else if err != nil {
166 return err
167 }
168 case ' ', '\t':
169 t.emitWord()
170 case '$':
171 c, err = t.reader.ReadByte()
172 switch {
173 case err == io.EOF:
174 t.builder.WriteByte('$')
175 case err != nil:
176 return err
177 case c == '\'' || c == '"':
178 err = t.parseAsciiString(c)
179 if err != nil {
180 return err
181 }
182 default:

Callers 1

TokenizeFunction · 0.95

Calls 7

emitWordMethod · 0.95
parseSingleQuoteMethod · 0.95
parseDoubleQuoteMethod · 0.95
parseAsciiStringMethod · 0.95
VerifyPanicFunction · 0.92
ReadByteMethod · 0.80
UnreadByteMethod · 0.80

Tested by

no test coverage detected