|
126 | 126 | % strings and transpose begin with `'`. The `.'` operator has |
127 | 127 | % already been handled above: |
128 | 128 | elseif letter == '''' |
129 | | - is_first_symbol = false; |
130 | | - previous = tokenlist(end); |
131 | | - % transpose operator: |
132 | | - % To differentiate the start of a string from the transpose |
133 | | - % operator, we need to check whether the previous token was a |
134 | | - % value or an operator. If a value, `'` means transpose. If an |
135 | | - % operator, `'` marks the start of a string. |
136 | | - if previous.isEqual('pair', {'}' ']' ')'}) || ... |
137 | | - previous.hasType({'identifier' 'number' 'property'}) |
138 | | - pos = pos + 1; |
139 | | - add_token('punctuation', letter); |
140 | | - % strings: |
141 | | - else |
142 | | - string = skip_string(); |
| 129 | + % the first symbol cannot be transpose, so must be string |
| 130 | + if is_first_symbol |
| 131 | + string = skip_string(''''); |
143 | 132 | add_token('string', string); |
| 133 | + else |
| 134 | + previous = tokenlist(end); |
| 135 | + |
| 136 | + % transpose operator: |
| 137 | + % To differentiate the start of a string from the |
| 138 | + % transpose operator, we need to check whether the |
| 139 | + % previous token was a value or an operator. If a value, |
| 140 | + % `'` means transpose. If an operator, `'` marks the start |
| 141 | + % of a string. |
| 142 | + if previous.isEqual('pair', {'}' ']' ')'}) || ... |
| 143 | + previous.hasType({'identifier' 'number' 'property'}) |
| 144 | + pos = pos + 1; |
| 145 | + add_token('punctuation', letter); |
| 146 | + % strings: |
| 147 | + else |
| 148 | + string = skip_string(''''); |
| 149 | + add_token('string', string); |
| 150 | + end |
144 | 151 | end |
| 152 | + is_first_symbol = false; |
| 153 | + % string that starts with double quotes (") |
| 154 | + elseif letter == '"' |
| 155 | + is_first_symbol = false; |
| 156 | + string = skip_string('"'); |
| 157 | + add_token('string', string); |
145 | 158 | % we don't make any distinction between different kinds of parens: |
146 | 159 | elseif any(letter == open_pairs) |
147 | 160 | is_first_symbol = false; |
@@ -246,18 +259,20 @@ function add_token(token_type, token_text) |
246 | 259 | string = source_code(string_start:pos-1); |
247 | 260 | end |
248 | 261 |
|
249 | | - function string = skip_string() |
| 262 | + function string = skip_string(quote_type) |
250 | 263 | %SKIP_STRING skips to the end of the string and returns the STRING |
251 | | - % the STRING includes both quotation marks. |
| 264 | + % the STRING includes both quotation marks. QUOTE_TYPE is the |
| 265 | + % type of quote character to look for (' or "). |
252 | 266 | % this modifies POS! |
253 | 267 |
|
254 | 268 | string_start = pos; |
255 | 269 | while true |
256 | | - if source_code(pos) ~= '''' || pos == string_start |
| 270 | + if source_code(pos) ~= quote_type || pos == string_start |
257 | 271 | pos = pos + 1; |
258 | | - elseif length(source_code) > pos && source_code(pos+1) == '''' |
| 272 | + elseif length(source_code) > pos ... |
| 273 | + && source_code(pos+1) == quote_type |
259 | 274 | pos = pos + 2; |
260 | | - else % source_code(pos) == '''' |
| 275 | + else % source_code(pos) == quote_type |
261 | 276 | pos = pos + 1; |
262 | 277 | break; |
263 | 278 | end |
@@ -302,7 +317,10 @@ function parse_command() |
302 | 317 | letter = source_code(pos); |
303 | 318 | % commands can contain literal strings: |
304 | 319 | if letter == '''' |
305 | | - string_literal = skip_string(); |
| 320 | + string_literal = skip_string(''''); |
| 321 | + add_token('string', string_literal); |
| 322 | + elseif letter == '"' |
| 323 | + string_literal = skip_string('"'); |
306 | 324 | add_token('string', string_literal); |
307 | 325 | % commands can contain spaces: |
308 | 326 | elseif any(letter == spaces) |
|
0 commit comments