From 34b647fb7c911c86f41bae8c34f1e338d6e3b0e8 Mon Sep 17 00:00:00 2001 From: pete-ts Date: Fri, 17 Apr 2020 22:19:38 +0100 Subject: [PATCH] Text literals can display non-ascii chars --- parser-typechecker/src/Unison/TermPrinter.hs | 3 +- .../unison-parser-typechecker.cabal | 3 +- unison-src/transcripts/escape-sequences.md | 5 ++++ .../transcripts/escape-sequences.output.md | 28 +++++++++++++++++++ 4 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 unison-src/transcripts/escape-sequences.md create mode 100644 unison-src/transcripts/escape-sequences.output.md diff --git a/parser-typechecker/src/Unison/TermPrinter.hs b/parser-typechecker/src/Unison/TermPrinter.hs index 94995ca59..64fe86329 100644 --- a/parser-typechecker/src/Unison/TermPrinter.hs +++ b/parser-typechecker/src/Unison/TermPrinter.hs @@ -14,6 +14,7 @@ import qualified Data.Map as Map import qualified Data.Set as Set import Data.Text ( splitOn, unpack ) import qualified Data.Text as Text +import qualified Text.Show.Unicode as U import Data.Vector ( ) import Unison.ABT ( pattern AbsN', reannotateUp, annotation ) import qualified Unison.ABT as ABT @@ -187,7 +188,7 @@ pretty0 -- metaprograms), then it needs to be able to print them (and then the -- parser ought to be able to parse them, to maintain symmetry.) Boolean' b -> fmt S.BooleanLiteral $ if b then l "true" else l "false" - Text' s -> fmt S.TextLiteral $ l $ show s + Text' s -> fmt S.TextLiteral $ l $ U.ushow s Char' c -> fmt S.CharLiteral $ l $ case showEscapeChar c of Just c -> "?\\" ++ [c] Nothing -> '?': [c] diff --git a/parser-typechecker/unison-parser-typechecker.cabal b/parser-typechecker/unison-parser-typechecker.cabal index d9719341b..a25707243 100644 --- a/parser-typechecker/unison-parser-typechecker.cabal +++ b/parser-typechecker/unison-parser-typechecker.cabal @@ -201,7 +201,8 @@ library unison-core, unliftio, util, - vector + vector, + unicode-show ghc-options: -Wall -O0 -fno-warn-name-shadowing -fno-warn-missing-pattern-synonym-signatures default-extensions: diff --git a/unison-src/transcripts/escape-sequences.md b/unison-src/transcripts/escape-sequences.md new file mode 100644 index 000000000..fc7955ff3 --- /dev/null +++ b/unison-src/transcripts/escape-sequences.md @@ -0,0 +1,5 @@ +```unison +> "Rúnar" +> "῎Ανδρα μοι ἔννεπε, Μοῦσα, πολύτροπον" +> "古池や蛙飛びこむ水の音" +``` diff --git a/unison-src/transcripts/escape-sequences.output.md b/unison-src/transcripts/escape-sequences.output.md new file mode 100644 index 000000000..f0f0947cf --- /dev/null +++ b/unison-src/transcripts/escape-sequences.output.md @@ -0,0 +1,28 @@ +```unison +> "Rúnar" +> "῎Ανδρα μοι ἔννεπε, Μοῦσα, πολύτροπον" +> "古池や蛙飛びこむ水の音" +``` + +```ucm + + ✅ + + scratch.u changed. + + Now evaluating any watch expressions (lines starting with + `>`)... Ctrl+C cancels. + + 1 | > "Rúnar" + ⧩ + "Rúnar" + + 2 | > "῎Ανδρα μοι ἔννεπε, Μοῦσα, πολύτροπον" + ⧩ + "῎Ανδρα μοι ἔννεπε, Μοῦσα, πολύτροπον" + + 3 | > "古池や蛙飛びこむ水の音" + ⧩ + "古池や蛙飛びこむ水の音" + +```