summaryrefslogtreecommitdiff
path: root/src/compiler/GF/Grammar
diff options
context:
space:
mode:
authorkrasimir <krasimir@chalmers.se>2010-01-31 15:54:25 +0000
committerkrasimir <krasimir@chalmers.se>2010-01-31 15:54:25 +0000
commitbe6465a2ebb1aba43433cff29bf5bad6e2065e26 (patch)
tree8702aca1395dbf3f91379eb73378badf1742db5c /src/compiler/GF/Grammar
parentacd927f87bfcc9b1a3b9f38371239adf27a3bf6b (diff)
refactor GF.Infra.Modules for better error messages
Diffstat (limited to 'src/compiler/GF/Grammar')
-rw-r--r--src/compiler/GF/Grammar/Binary.hs10
-rw-r--r--src/compiler/GF/Grammar/Grammar.hs4
-rw-r--r--src/compiler/GF/Grammar/Lookup.hs2
-rw-r--r--src/compiler/GF/Grammar/Parser.y26
-rw-r--r--src/compiler/GF/Grammar/Printer.hs3
5 files changed, 21 insertions, 24 deletions
diff --git a/src/compiler/GF/Grammar/Binary.hs b/src/compiler/GF/Grammar/Binary.hs
index fbad5ac7e..7e56492cb 100644
--- a/src/compiler/GF/Grammar/Binary.hs
+++ b/src/compiler/GF/Grammar/Binary.hs
@@ -26,16 +26,16 @@ instance Binary Ident where
then return identW
else return (identC bs)
-instance (Ord i, Binary i, Binary a) => Binary (MGrammar i a) where
+instance Binary a => Binary (MGrammar a) where
put (MGrammar ms) = put ms
get = fmap MGrammar get
-instance (Ord i, Binary i, Binary a) => Binary (ModInfo i a) where
+instance Binary a => Binary (ModInfo a) where
put mi = do put (mtype mi,mstatus mi,flags mi,extend mi,mwith mi,opens mi,mexdeps mi,jments mi,positions mi)
get = do (mtype,mstatus,flags,extend,mwith,opens,med,jments,positions) <- get
return (ModInfo mtype mstatus flags extend mwith opens med jments positions)
-instance (Binary i) => Binary (ModuleType i) where
+instance Binary ModuleType where
put MTAbstract = putWord8 0
put MTResource = putWord8 2
put (MTConcrete i) = putWord8 3 >> put i
@@ -50,7 +50,7 @@ instance (Binary i) => Binary (ModuleType i) where
5 -> get >>= return . MTInstance
_ -> decodingError
-instance (Binary i) => Binary (MInclude i) where
+instance Binary MInclude where
put MIAll = putWord8 0
put (MIOnly xs) = putWord8 1 >> put xs
put (MIExcept xs) = putWord8 2 >> put xs
@@ -61,7 +61,7 @@ instance (Binary i) => Binary (MInclude i) where
2 -> fmap MIExcept get
_ -> decodingError
-instance Binary i => Binary (OpenSpec i) where
+instance Binary OpenSpec where
put (OSimple i) = putWord8 0 >> put i
put (OQualif i j) = putWord8 1 >> put (i,j)
get = do tag <- getWord8
diff --git a/src/compiler/GF/Grammar/Grammar.hs b/src/compiler/GF/Grammar/Grammar.hs
index 8d1468d9d..e0ca01341 100644
--- a/src/compiler/GF/Grammar/Grammar.hs
+++ b/src/compiler/GF/Grammar/Grammar.hs
@@ -53,11 +53,11 @@ import GF.Data.Operations
import qualified Data.ByteString.Char8 as BS
-- | grammar as presented to the compiler
-type SourceGrammar = MGrammar Ident Info
+type SourceGrammar = MGrammar Info
emptySourceGrammar = MGrammar []
-type SourceModInfo = ModInfo Ident Info
+type SourceModInfo = ModInfo Info
type SourceModule = (Ident, SourceModInfo)
diff --git a/src/compiler/GF/Grammar/Lookup.hs b/src/compiler/GF/Grammar/Lookup.hs
index 074f0c5ec..d56c1ee30 100644
--- a/src/compiler/GF/Grammar/Lookup.hs
+++ b/src/compiler/GF/Grammar/Lookup.hs
@@ -55,7 +55,7 @@ lookupIdent c t =
Ok v -> return v
Bad _ -> Bad ("unknown identifier" +++ showIdent c)
-lookupIdentInfo :: ModInfo Ident a -> Ident -> Err a
+lookupIdentInfo :: ModInfo a -> Ident -> Err a
lookupIdentInfo mo i = lookupIdent i (jments mo)
lookupResDef :: SourceGrammar -> Ident -> Ident -> Err Term
diff --git a/src/compiler/GF/Grammar/Parser.y b/src/compiler/GF/Grammar/Parser.y
index 320053674..ef4a5d84b 100644
--- a/src/compiler/GF/Grammar/Parser.y
+++ b/src/compiler/GF/Grammar/Parser.y
@@ -135,7 +135,7 @@ ComplMod
: {- empty -} { MSComplete }
| 'incomplete' { MSIncomplete }
-ModType :: { (ModuleType Ident,Ident) }
+ModType :: { (ModuleType,Ident) }
ModType
: 'abstract' Ident { (MTAbstract, $2) }
| 'resource' Ident { (MTResource, $2) }
@@ -143,9 +143,9 @@ ModType
| 'concrete' Ident 'of' Ident { (MTConcrete $4, $2) }
| 'instance' Ident 'of' Ident { (MTInstance $4, $2) }
-ModHeaderBody :: { ( [(Ident,MInclude Ident)]
- , Maybe (Ident,MInclude Ident,[(Ident,Ident)])
- , [OpenSpec Ident]
+ModHeaderBody :: { ( [(Ident,MInclude)]
+ , Maybe (Ident,MInclude,[(Ident,Ident)])
+ , [OpenSpec]
) }
ModHeaderBody
: ListIncluded '**' Included 'with' ListInst '**' ModOpen { ($1, Just (fst $3,snd $3,$5), $7) }
@@ -156,14 +156,14 @@ ModHeaderBody
| Included 'with' ListInst { ([], Just (fst $1,snd $1,$3), []) }
| ModOpen { ([], Nothing, $1) }
-ModOpen :: { [OpenSpec Ident] }
+ModOpen :: { [OpenSpec] }
ModOpen
: { [] }
| 'open' ListOpen { $2 }
-ModBody :: { ( [(Ident,MInclude Ident)]
- , Maybe (Ident,MInclude Ident,[(Ident,Ident)])
- , Maybe ([OpenSpec Ident],[(Ident,SrcSpan,Info)],Options)
+ModBody :: { ( [(Ident,MInclude)]
+ , Maybe (Ident,MInclude,[(Ident,Ident)])
+ , Maybe ([OpenSpec],[(Ident,SrcSpan,Info)],Options)
) }
ModBody
: ListIncluded '**' Included 'with' ListInst '**' ModContent { ($1, Just (fst $3,snd $3,$5), Just $7) }
@@ -175,7 +175,7 @@ ModBody
| ModContent { ([], Nothing, Just $1) }
| ModBody ';' { $1 }
-ModContent :: { ([OpenSpec Ident],[(Ident,SrcSpan,Info)],Options) }
+ModContent :: { ([OpenSpec],[(Ident,SrcSpan,Info)],Options) }
ModContent
: '{' ListTopDef '}' { ([],[d | Left ds <- $2, d <- ds],concatOptions [o | Right o <- $2]) }
| 'open' ListOpen 'in' '{' ListTopDef '}' { ($2,[d | Left ds <- $5, d <- ds],concatOptions [o | Right o <- $5]) }
@@ -185,12 +185,12 @@ ListTopDef
: {- empty -} { [] }
| TopDef ListTopDef { $1 : $2 }
-ListOpen :: { [OpenSpec Ident] }
+ListOpen :: { [OpenSpec] }
ListOpen
: Open { [$1] }
| Open ',' ListOpen { $1 : $3 }
-Open :: { OpenSpec Ident }
+Open :: { OpenSpec }
Open
: Ident { OSimple $1 }
| '(' Ident '=' Ident ')' { OQualif $2 $4 }
@@ -204,12 +204,12 @@ Inst :: { (Ident,Ident) }
Inst
: '(' Ident '=' Ident ')' { ($2,$4) }
-ListIncluded :: { [(Ident,MInclude Ident)] }
+ListIncluded :: { [(Ident,MInclude)] }
ListIncluded
: Included { [$1] }
| Included ',' ListIncluded { $1 : $3 }
-Included :: { (Ident,MInclude Ident) }
+Included :: { (Ident,MInclude) }
Included
: Ident { ($1,MIAll ) }
| Ident '[' ListIdent ']' { ($1,MIOnly $3) }
diff --git a/src/compiler/GF/Grammar/Printer.hs b/src/compiler/GF/Grammar/Printer.hs
index 06cac9705..996a7a807 100644
--- a/src/compiler/GF/Grammar/Printer.hs
+++ b/src/compiler/GF/Grammar/Printer.hs
@@ -9,7 +9,6 @@
module GF.Grammar.Printer
( TermPrintQual(..)
- , ppIdent
, ppLabel
, ppModule
, ppJudgement
@@ -256,8 +255,6 @@ ppDDecl q (_,id,typ)
| id == identW = ppTerm q 6 typ
| otherwise = parens (ppIdent id <+> colon <+> ppTerm q 0 typ)
-ppIdent = text . showIdent
-
ppQIdent q m id =
case q of
Qualified -> ppIdent m <> char '.' <> ppIdent id