the-sett / elm-syntax-dsl

A DSL for creating Elm syntax trees and pretty printing Elm source code.
BSD 3-Clause "New" or "Revised" License
20 stars 4 forks source link

Escape backslash, tab and newline in char literals #29

Closed sylbru closed 3 years ago

sylbru commented 3 years ago

This fixes a bug in escapeChar with char literal \ (backslash). It currently generates '\' which makes the whole file syntactically wrong because the ending quote is escaped. This generates '\\' instead.

I also added \t and \n to keep escapeChar consistent with escape.

Another possibility: add the single quote ' to the characters escaped in escape, and make escapeChar simply call escape after transforming the Char to a String:

escapeChar : Char -> String
escapeChar =
    String.fromChar >> escape

See also https://github.com/stil4m/elm-syntax/pull/125/files and https://github.com/stil4m/elm-syntax/issues/124

rupertlssmith commented 3 years ago

Thanks - this will be published as version 5.2.1