|
|
@@ -126,6 +126,8 @@ func (self tokenizeResultCode) String() string {
|
|
126
|
126
|
return "tokenizeResultCodeOk"
|
|
127
|
127
|
case tokenizeResultCodeMissingEndSingleQuote:
|
|
128
|
128
|
return "tokenizeResultCodeMissingEndSingleQuote"
|
|
|
129
|
+ case tokenizeResultCodeMissingEndDoubleQuote:
|
|
|
130
|
+ return "tokenizeResultCodeMissingEndDoubleQuote"
|
|
129
|
131
|
default:
|
|
130
|
132
|
return fmt.Sprintf("unknown!tokenizeResultCode(%d)", self)
|
|
131
|
133
|
}
|
|
|
@@ -134,6 +136,7 @@ func (self tokenizeResultCode) String() string {
|
|
134
|
136
|
const (
|
|
135
|
137
|
tokenizeResultCodeOk tokenizeResultCode = iota
|
|
136
|
138
|
tokenizeResultCodeMissingEndSingleQuote
|
|
|
139
|
+ tokenizeResultCodeMissingEndDoubleQuote
|
|
137
|
140
|
)
|
|
138
|
141
|
|
|
139
|
142
|
func tokenize(str string) tokenizeResult {
|
|
|
@@ -162,6 +165,14 @@ func tokenize(str string) tokenizeResult {
|
|
162
|
165
|
}
|
|
163
|
166
|
b.bufAppend(new_chars)
|
|
164
|
167
|
rdr.tossChar() // the second `'`
|
|
|
168
|
+ case '"':
|
|
|
169
|
+ rdr.tossChar() // first `"`
|
|
|
170
|
+ new_chars, found := rdr.takeUntil("\"")
|
|
|
171
|
+ if !found {
|
|
|
172
|
+ return tokenizeResult{code: tokenizeResultCodeMissingEndDoubleQuote, err_loc: rdr.pos - 1}
|
|
|
173
|
+ }
|
|
|
174
|
+ b.bufAppend(new_chars)
|
|
|
175
|
+ rdr.tossChar() // the second `"`
|
|
165
|
176
|
default:
|
|
166
|
177
|
b.bufAppendChar(this_byte)
|
|
167
|
178
|
rdr.tossChar()
|
|
|
@@ -178,6 +189,8 @@ func Tokenize(str string) ([]string, error) {
|
|
178
|
189
|
return res.tokens, nil
|
|
179
|
190
|
case tokenizeResultCodeMissingEndSingleQuote:
|
|
180
|
191
|
return nil, TokenizeError{code: TokenizeErrorCodeMissingEndSingleQuote, loc: res.err_loc}
|
|
|
192
|
+ case tokenizeResultCodeMissingEndDoubleQuote:
|
|
|
193
|
+ return nil, TokenizeError{code: TokenizeErrorCodeMissingEndDoubleQuote, loc: res.err_loc}
|
|
181
|
194
|
default:
|
|
182
|
195
|
return nil, TokenizeError{code: TokenizeErrorCodeGeneral, loc: res.err_loc}
|
|
183
|
196
|
}
|
|
|
@@ -192,12 +205,15 @@ type TokenizeErrorCode uint8
|
|
192
|
205
|
const (
|
|
193
|
206
|
TokenizeErrorCodeGeneral TokenizeErrorCode = iota
|
|
194
|
207
|
TokenizeErrorCodeMissingEndSingleQuote
|
|
|
208
|
+ TokenizeErrorCodeMissingEndDoubleQuote
|
|
195
|
209
|
)
|
|
196
|
210
|
|
|
197
|
211
|
func (e TokenizeError) Error() string {
|
|
198
|
212
|
switch e.code {
|
|
199
|
213
|
case TokenizeErrorCodeMissingEndSingleQuote:
|
|
200
|
214
|
return fmt.Sprintf("unterminated single-quote: at %d", e.loc)
|
|
|
215
|
+ case TokenizeErrorCodeMissingEndDoubleQuote:
|
|
|
216
|
+ return fmt.Sprintf("unterminated double-quote: at %d", e.loc)
|
|
201
|
217
|
default:
|
|
202
|
218
|
return fmt.Sprintf("unknown TokenizeError code: .code=%d .loc=%d", e.code, e.loc)
|
|
203
|
219
|
}
|