summaryrefslogtreecommitdiff
path: root/src/compiler/GF/Grammar
diff options
context:
space:
mode:
Diffstat (limited to 'src/compiler/GF/Grammar')
-rw-r--r--src/compiler/GF/Grammar/Binary.hs5
-rw-r--r--src/compiler/GF/Grammar/Grammar.hs14
-rw-r--r--src/compiler/GF/Grammar/Lexer.hs10
-rw-r--r--src/compiler/GF/Grammar/Lockfield.hs8
-rw-r--r--src/compiler/GF/Grammar/MMacros.hs11
-rw-r--r--src/compiler/GF/Grammar/Parser.y4
-rw-r--r--src/compiler/GF/Grammar/lexer/Lexer.x4
7 files changed, 27 insertions, 29 deletions
diff --git a/src/compiler/GF/Grammar/Binary.hs b/src/compiler/GF/Grammar/Binary.hs
index ae0c72809..fab63a7ba 100644
--- a/src/compiler/GF/Grammar/Binary.hs
+++ b/src/compiler/GF/Grammar/Binary.hs
@@ -34,7 +34,7 @@ instance Binary Ident where
get = do bs <- get
if bs == BS.pack "_"
then return identW
- else return (identC bs)
+ else return (identC (rawIdentC bs))
instance Binary SourceGrammar where
put = put . modules
@@ -289,6 +289,9 @@ instance Binary Label where
1 -> fmap LVar get
_ -> decodingError
+instance Binary RawIdent where
+ put = put . rawId2bs
+ get = fmap rawIdentC get
putGFOVersion = mapM_ (putWord8 . fromIntegral . ord) gfoVersion
getGFOVersion = replicateM (length gfoVersion) (fmap (chr . fromIntegral) getWord8)
diff --git a/src/compiler/GF/Grammar/Grammar.hs b/src/compiler/GF/Grammar/Grammar.hs
index c59cd809e..2efec220b 100644
--- a/src/compiler/GF/Grammar/Grammar.hs
+++ b/src/compiler/GF/Grammar/Grammar.hs
@@ -74,7 +74,6 @@ import Data.Array.Unboxed
import qualified Data.Map as Map
import qualified Data.Set as Set
import qualified Data.IntMap as IntMap
-import qualified Data.ByteString.Char8 as BS
import Text.PrettyPrint
import System.FilePath
import Control.Monad.Identity
@@ -472,7 +471,7 @@ data TInfo =
-- | record label
data Label =
- LIdent BS.ByteString
+ LIdent RawIdent
| LVar Int
deriving (Show, Eq, Ord)
@@ -497,16 +496,15 @@ varLabel :: Int -> Label
varLabel = LVar
tupleLabel, linLabel :: Int -> Label
-tupleLabel i = LIdent $! BS.pack ('p':show i)
-linLabel i = LIdent $! BS.pack ('s':show i)
+tupleLabel i = LIdent $! rawIdentS ('p':show i)
+linLabel i = LIdent $! rawIdentS ('s':show i)
theLinLabel :: Label
-theLinLabel = LIdent (BS.singleton 's')
+theLinLabel = LIdent (rawIdentS "s")
ident2label :: Ident -> Label
-ident2label c = LIdent (ident2bs c)
+ident2label c = LIdent (ident2raw c)
label2ident :: Label -> Ident
label2ident (LIdent s) = identC s
-label2ident (LVar i) = identC (BS.pack ('$':show i))
-
+label2ident (LVar i) = identS ('$':show i)
diff --git a/src/compiler/GF/Grammar/Lexer.hs b/src/compiler/GF/Grammar/Lexer.hs
index 3ab9eda61..a9fef2cc4 100644
--- a/src/compiler/GF/Grammar/Lexer.hs
+++ b/src/compiler/GF/Grammar/Lexer.hs
@@ -278,12 +278,12 @@ getPosn :: P Posn
getPosn = P $ \inp@(AI pos _ _) -> POk pos
-alex_action_3 = tok (eitherResIdent (T_Ident . identC))
+alex_action_3 = tok (eitherResIdent (T_Ident . identC . rawIdentC))
alex_action_4 = tok (eitherResIdent (T_LString . BS.unpack))
-alex_action_5 = tok (eitherResIdent (T_Ident . identC))
-alex_action_6 = tok (T_String . unescapeInitTail . BS.unpack)
-alex_action_7 = tok (T_Integer . read . BS.unpack)
-alex_action_8 = tok (T_Double . read . BS.unpack)
+alex_action_5 = tok (eitherResIdent (T_Ident . identC . rawIdentC))
+alex_action_6 = tok (T_String . unescapeInitTail . BS.unpack)
+alex_action_7 = tok (T_Integer . read . BS.unpack)
+alex_action_8 = tok (T_Double . read . BS.unpack)
{-# LINE 1 "templates/GenericTemplate.hs" #-}
{-# LINE 1 "templates/GenericTemplate.hs" #-}
{-# LINE 1 "<built-in>" #-}
diff --git a/src/compiler/GF/Grammar/Lockfield.hs b/src/compiler/GF/Grammar/Lockfield.hs
index 8b0798527..5c2f5d0f0 100644
--- a/src/compiler/GF/Grammar/Lockfield.hs
+++ b/src/compiler/GF/Grammar/Lockfield.hs
@@ -16,8 +16,6 @@
module GF.Grammar.Lockfield (lockRecType, unlockRecord, lockLabel, isLockLabel) where
-import qualified Data.ByteString.Char8 as BS
-
import GF.Infra.Ident
import GF.Grammar.Grammar
import GF.Grammar.Macros
@@ -41,12 +39,12 @@ unlockRecord c ft = do
_ -> return $ mkAbs xs (ExtR t lock)
lockLabel :: Ident -> Label
-lockLabel c = LIdent $! BS.append lockPrefix (ident2bs c)
+lockLabel c = LIdent $! prefixRawIdent lockPrefix (ident2raw c)
isLockLabel :: Label -> Bool
isLockLabel l = case l of
- LIdent c -> BS.isPrefixOf lockPrefix c
+ LIdent c -> isPrefixOf lockPrefix c
_ -> False
-lockPrefix = BS.pack "lock_"
+lockPrefix = rawIdentS "lock_"
diff --git a/src/compiler/GF/Grammar/MMacros.hs b/src/compiler/GF/Grammar/MMacros.hs
index f1d2f172a..1b9060003 100644
--- a/src/compiler/GF/Grammar/MMacros.hs
+++ b/src/compiler/GF/Grammar/MMacros.hs
@@ -26,7 +26,6 @@ import GF.Grammar.Values
import GF.Grammar.Macros
import Control.Monad
-import qualified Data.ByteString.Char8 as BS
import Text.PrettyPrint
{-
@@ -238,11 +237,11 @@ qualifTerm m = qualif [] where
Cn c -> Q (m,c)
Con c -> QC (m,c)
_ -> composSafeOp (qualif xs) t
- chV x = string2var $ ident2bs x
+ chV x = string2var $ ident2raw x
-string2var :: BS.ByteString -> Ident
-string2var s = case BS.unpack s of
- c:'_':i -> identV (BS.singleton c) (readIntArg i) ---
+string2var :: RawIdent -> Ident
+string2var s = case showRawIdent s of
+ c:'_':i -> identV (rawIdentS [c]) (readIntArg i) ---
_ -> identC s
-- | reindex variables so that they tell nesting depth level
@@ -254,7 +253,7 @@ reindexTerm = qualif (0,[]) where
Vr x -> Vr $ look x g
_ -> composSafeOp (qualif dg) t
look x = maybe x id . lookup x --- if x is not in scope it is unchanged
- ind x d = identC $ ident2bs x `BS.append` BS.singleton '_' `BS.append` BS.pack (show d)
+ ind x d = identC $ ident2raw x `prefixRawIdent` rawIdentS "_" `prefixRawIdent` rawIdentS (show d)
{-
-- this method works for context-free abstract syntax
diff --git a/src/compiler/GF/Grammar/Parser.y b/src/compiler/GF/Grammar/Parser.y
index a84db6ffd..e5a7f359c 100644
--- a/src/compiler/GF/Grammar/Parser.y
+++ b/src/compiler/GF/Grammar/Parser.y
@@ -507,11 +507,11 @@ Patt3
PattAss :: { [(Label,Patt)] }
PattAss
- : ListIdent '=' Patt { [(LIdent (ident2bs i),$3) | i <- $1] }
+ : ListIdent '=' Patt { [(LIdent (ident2raw i),$3) | i <- $1] }
Label :: { Label }
Label
- : Ident { LIdent (ident2bs $1) }
+ : Ident { LIdent (ident2raw $1) }
| '$' Integer { LVar (fromIntegral $2) }
Sort :: { Ident }
diff --git a/src/compiler/GF/Grammar/lexer/Lexer.x b/src/compiler/GF/Grammar/lexer/Lexer.x
index ca796808b..4050f4854 100644
--- a/src/compiler/GF/Grammar/lexer/Lexer.x
+++ b/src/compiler/GF/Grammar/lexer/Lexer.x
@@ -30,9 +30,9 @@ $u = [\0-\255] -- universal: any character
"{-" ([$u # \-] | \- [$u # \}])* ("-")+ "}" ;
$white+ ;
-@rsyms { tok (eitherResIdent (T_Ident . identC)) }
+@rsyms { tok (eitherResIdent (T_Ident . identC . rawIdentC)) }
\' ($u # \')* \' { tok (eitherResIdent (T_LString . BS.unpack)) }
-(\_ | $l)($l | $d | \_ | \')* { tok (eitherResIdent (T_Ident . identC)) }
+(\_ | $l)($l | $d | \_ | \')* { tok (eitherResIdent (T_Ident . identC . rawIdentC)) }
\" ([$u # [\" \\ \n]] | (\\ (\" | \\ | \' | n | t)))* \" { tok (T_String . unescapeInitTail . BS.unpack) }