Skip to content

Commit

Permalink
Improved rendering of whitespace leading unexpected tokens (#109)
Browse files Browse the repository at this point in the history
  • Loading branch information
j-mie6 authored Feb 10, 2022
1 parent 7bd71fb commit 13f2d25
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/main/scala/parsley/errors/helpers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@ import scala.util.matching.Regex
// $COVERAGE-OFF$
private [parsley] object helpers {
def renderRawString(s: String): String = s match {
case "\n" => "newline"
case "\t" => "tab"
case " " => "space"
case cs if cs.head.isWhitespace => cs.head match {
case c if c.isSpaceChar => "space"
case '\n' => "newline"
case '\t' => "tab"
case _ => "whitespace character"
}
case Unprintable(up) => f"unprintable character (\\u${up.head.toInt}%04X)"
// Do we want this only in unexpecteds?
case cs => "\"" + cs.takeWhile(c => c != '\n' && c != ' ') + "\""
case cs => "\"" + cs.takeWhile(!_.isWhitespace) + "\""
}

def combineAsList(elems: List[String]): Option[String] = elems.sorted.reverse match {
Expand Down

0 comments on commit 13f2d25

Please sign in to comment.