diff options
| author | simonmar <unknown> | 2006-01-06 16:30:19 +0000 |
|---|---|---|
| committer | simonmar <unknown> | 2006-01-06 16:30:19 +0000 |
| commit | 9d7da331989abcd1844e9d03b8d1e4163796fa85 (patch) | |
| tree | 8efa2e6fdcf8bfee777ae6477a686d0594c5ff76 /ghc/compiler/hsSyn/Convert.lhs | |
| parent | 2a2efb720c0fdc06fe749f96f284b00b30f8f3f7 (diff) | |
| download | haskell-9d7da331989abcd1844e9d03b8d1e4163796fa85.tar.gz | |
[project @ 2006-01-06 16:30:17 by simonmar]
Add support for UTF-8 source files
GHC finally has support for full Unicode in source files. Source
files are now assumed to be UTF-8 encoded, and the full range of
Unicode characters can be used, with classifications recognised using
the implementation from Data.Char. This incedentally means that only
the stage2 compiler will recognise Unicode in source files, because I
was too lazy to port the unicode classifier code into libcompat.
Additionally, the following synonyms for keywords are now recognised:
forall symbol (U+2200) forall
right arrow (U+2192) ->
left arrow (U+2190) <-
horizontal ellipsis (U+22EF) ..
there are probably more things we could add here.
This will break some source files if Latin-1 characters are being used.
In most cases this should result in a UTF-8 decoding error. Later on
if we want to support more encodings (perhaps with a pragma to specify
the encoding), I plan to do it by recoding into UTF-8 before parsing.
Internally, there were some pretty big changes:
- FastStrings are now stored in UTF-8
- Z-encoding has been moved right to the back end. Previously we
used to Z-encode every identifier on the way in for simplicity,
and only decode when we needed to show something to the user.
Instead, we now keep every string in its UTF-8 encoding, and
Z-encode right before printing it out. To avoid Z-encoding the
same string multiple times, the Z-encoding is cached inside the
FastString the first time it is requested.
This speeds up the compiler - I've measured some definite
improvement in parsing at least, and I expect compilations overall
to be faster too. It also cleans up a lot of cruft from the
OccName interface. Z-encoding is nicely hidden inside the
Outputable instance for Names & OccNames now.
- StringBuffers are UTF-8 too, and are now represented as
ForeignPtrs.
- I've put together some test cases, not by any means exhaustive,
but there are some interesting UTF-8 decoding error cases that
aren't obvious. Also, take a look at unicode001.hs for a demo.
Diffstat (limited to 'ghc/compiler/hsSyn/Convert.lhs')
| -rw-r--r-- | ghc/compiler/hsSyn/Convert.lhs | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/ghc/compiler/hsSyn/Convert.lhs b/ghc/compiler/hsSyn/Convert.lhs index 96623bbd5c..9dddd29c21 100644 --- a/ghc/compiler/hsSyn/Convert.lhs +++ b/ghc/compiler/hsSyn/Convert.lhs @@ -20,7 +20,8 @@ import qualified Name ( Name, mkInternalName, getName ) import Module ( Module, mkModule ) import RdrHsSyn ( mkClassDecl, mkTyData ) import qualified OccName -import OccName ( startsVarId, startsVarSym, startsConId, startsConSym ) +import OccName ( startsVarId, startsVarSym, startsConId, startsConSym, + pprNameSpace ) import SrcLoc ( Located(..), SrcSpan ) import Type ( Type ) import TysWiredIn ( unitTyCon, tupleTyCon, tupleCon, trueDataCon, nilDataCon, consDataCon ) @@ -550,7 +551,7 @@ okOcc ns str@(c:_) badOcc :: OccName.NameSpace -> String -> SDoc badOcc ctxt_ns occ - = ptext SLIT("Illegal") <+> text (OccName.nameSpaceString ctxt_ns) + = ptext SLIT("Illegal") <+> pprNameSpace ctxt_ns <+> ptext SLIT("name:") <+> quotes (text occ) thRdrName :: OccName.NameSpace -> String -> TH.NameFlavour -> RdrName @@ -605,7 +606,7 @@ mk_uniq_occ ns occ uniq -- The packing and unpacking is rather turgid :-( mk_occ :: OccName.NameSpace -> String -> OccName.OccName -mk_occ ns occ = OccName.mkOccFS ns (mkFastString occ) +mk_occ ns occ = OccName.mkOccNameFS ns (mkFastString occ) mk_ghc_ns :: TH.NameSpace -> OccName.NameSpace mk_ghc_ns TH.DataName = OccName.dataName |
