@@ -292,29 +292,48 @@ function readKeyword(stream: StringStream): Presentation<Keyword> {
292292defineReadItem ( "-" , readKeywordOrNegativeInteger ) ;
293293defineReadItem ( ":" , readKeywordOrNegativeInteger ) ;
294294
295- function maybeReadQuotedString ( stream : StringStream ) : string | undefined {
295+ function maybeReadQuotedString (
296+ stream : StringStream
297+ ) : Presentation < string > | undefined {
296298 if ( stream . peekChar ( ) !== '"' ) {
297299 return undefined ;
298300 }
299301 stream . readChar ( ) ;
300302 const word : string [ ] = [ ] ;
301- readUntil ( / " / , stream , word ) ;
302- if ( stream . peekChar ( ) === '"' ) {
303- stream . readChar ( ) ;
304- return word . join ( "" ) ;
305- } else {
306- return undefined ;
307- }
303+ do {
304+ readUntil ( / " / , stream , word ) ;
305+ if ( stream . peekChar ( ) === '"' && word . at ( - 1 ) === "\\" ) {
306+ word . pop ( ) ;
307+ word . push ( '"' ) ;
308+ stream . readChar ( ) ;
309+ if ( stream . peekChar ( ) === undefined ) {
310+ return StringPresentationType . wrap ( word . join ( "" ) ) ;
311+ } else {
312+ continue ;
313+ }
314+ } else if ( stream . peekChar ( ) === '"' ) {
315+ stream . readChar ( ) ;
316+ // wrap to stop post processing of the string
317+ // which is the reason they are quoting in the first place.
318+ return StringPresentationType . wrap ( word . join ( "" ) ) ;
319+ } else if ( stream . peekChar ( ) === undefined ) {
320+ // the only reason we don't error here is because we don't have the infrastructure
321+ // for how reader errors will work and not look confusing as shit.
322+ return undefined ;
323+ }
324+ // eslint-disable-next-line no-constant-condition
325+ } while ( true ) ;
308326}
309327
310- function readString ( stream : StringStream ) : string {
328+ function readString ( stream : StringStream ) : string | Presentation < string > {
311329 const quotedString = stream . savingPositionIf ( {
312330 predicate : ( t ) => t === undefined ,
313331 body : ( stream ) => maybeReadQuotedString ( stream as StringStream ) ,
314332 } ) ;
315333 if ( quotedString !== undefined ) {
316- return quotedString as string ;
334+ return quotedString as Presentation < string > ;
317335 } else {
336+ // we want these to be transformable read items.
318337 return readWord ( stream ) ;
319338 }
320339}
0 commit comments