(delimiter, tokenOuter)
| 181 | } |
| 182 | |
| 183 | function formatStringFactory(delimiter, tokenOuter) { |
| 184 | while ("rubf".indexOf(delimiter.charAt(0).toLowerCase()) >= 0) |
| 185 | delimiter = delimiter.substr(1); |
| 186 | |
| 187 | var singleline = delimiter.length == 1; |
| 188 | var OUTCLASS = "string"; |
| 189 | |
| 190 | function tokenNestedExpr(depth) { |
| 191 | return function(stream, state) { |
| 192 | var inner = tokenBaseInner(stream, state, true) |
| 193 | if (inner == "punctuation") { |
| 194 | if (stream.current() == "{") { |
| 195 | state.tokenize = tokenNestedExpr(depth + 1) |
| 196 | } else if (stream.current() == "}") { |
| 197 | if (depth > 1) state.tokenize = tokenNestedExpr(depth - 1) |
| 198 | else state.tokenize = tokenString |
| 199 | } |
| 200 | } |
| 201 | return inner |
| 202 | } |
| 203 | } |
| 204 | |
| 205 | function tokenString(stream, state) { |
| 206 | while (!stream.eol()) { |
| 207 | stream.eatWhile(/[^'"\{\}\\]/); |
| 208 | if (stream.eat("\\")) { |
| 209 | stream.next(); |
| 210 | if (singleline && stream.eol()) |
| 211 | return OUTCLASS; |
| 212 | } else if (stream.match(delimiter)) { |
| 213 | state.tokenize = tokenOuter; |
| 214 | return OUTCLASS; |
| 215 | } else if (stream.match('{{')) { |
| 216 | // ignore {{ in f-str |
| 217 | return OUTCLASS; |
| 218 | } else if (stream.match('{', false)) { |
| 219 | // switch to nested mode |
| 220 | state.tokenize = tokenNestedExpr(0) |
| 221 | if (stream.current()) return OUTCLASS; |
| 222 | else return state.tokenize(stream, state) |
| 223 | } else if (stream.match('}}')) { |
| 224 | return OUTCLASS; |
| 225 | } else if (stream.match('}')) { |
| 226 | // single } in f-string is an error |
| 227 | return ERRORCLASS; |
| 228 | } else { |
| 229 | stream.eat(/['"]/); |
| 230 | } |
| 231 | } |
| 232 | if (singleline) { |
| 233 | if (parserConf.singleLineStringErrors) |
| 234 | return ERRORCLASS; |
| 235 | else |
| 236 | state.tokenize = tokenOuter; |
| 237 | } |
| 238 | return OUTCLASS; |
| 239 | } |
| 240 | tokenString.isString = true; |
no test coverage detected