Skip to content

Commit c5910bc

Browse files
committed
Make some parse errors nicer for string literals
- Avoid reporting "expected '\'" - Report the closing " as "end of string literal"
1 parent 2853f24 commit c5910bc

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/main/scala/scalaparsers/ParsingUtil.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ trait Parsing[S] {
285285
private def charLetter = satisfy(c => (c != '\'') && (c != '\\') && (c > '\u0016'))
286286
private def charChar = (charLetter | charEscape) scope "character literal character"
287287
private def stringLetter = satisfy(c => (c != '"') && (c != '\\') && (c > '\u0016'))
288-
private def stringEscape = ch('\\') >> (
288+
private def stringEscape = satisfy(_ == '\\') >> (
289289
(simpleSpace.skipSome >> (ch('\\') scope "end of string gap")).as(None) | // escape gap
290290
ch('&').as(None) | // empty escape
291291
escapeCode.map(Some(_))
@@ -302,7 +302,7 @@ trait Parsing[S] {
302302
.slice
303303
.interspersedWith(stringEscape.map(_.fold("")(_ toString)))
304304
.map(_ mkString)
305-
.between('"','"')
305+
.between('"','"' scope "end of string literal")
306306
.scope("string literal"))
307307

308308
/** Format a string back to its equivalent literal form. */

0 commit comments

Comments
 (0)