This commit is contained in:
aarne
2004-09-23 14:41:42 +00:00
parent d5b4230d6d
commit 2c60a2d82a
31 changed files with 434 additions and 211 deletions

View File

@@ -104,6 +104,7 @@ data CType =
| Table CType CType
| Cn CIdent
| TStr
| TInts Integer
deriving (Eq,Ord,Show)
data Labelling =
@@ -121,6 +122,7 @@ data Term =
| S Term Term
| C Term Term
| FV [Term]
| EInt Integer
| K Tokn
| E
deriving (Eq,Ord,Show)
@@ -157,6 +159,7 @@ data Patt =
| PV Ident
| PW
| PR [PattAssign]
| PI Integer
deriving (Eq,Ord,Show)
data PattAssign =

View File

@@ -77,6 +77,7 @@ term2patt trm = case trm of
aa' <- mapM term2patt aa
return (PR (map (uncurry PAss) (zip ll aa')))
LI x -> return $ PV x
EInt i -> return $ PI i
_ -> prtBad "no pattern corresponds to term" trm
patt2term :: Patt -> Term
@@ -85,6 +86,7 @@ patt2term p = case p of
PV x -> LI x
PW -> anyTerm ----
PR pas -> R [ Ass lbl (patt2term q) | PAss lbl q <- pas ]
PI i -> EInt i
anyTerm :: Term
anyTerm = LI (A.identC "_") --- should not happen

View File

@@ -111,6 +111,7 @@ redCType t = case t of
Table p v -> liftM2 G.Table (redCType p) (redCType v)
Cn mc -> liftM (uncurry G.QC) $ redQIdent mc
TStr -> return $ F.typeStr
TInts i -> return $ F.typeInts (fromInteger i)
redCTerm :: Term -> Err G.Term
redCTerm x = case x of
@@ -139,6 +140,7 @@ redCTerm x = case x of
C term0 term -> liftM2 G.C (redCTerm term0) (redCTerm term)
FV terms -> liftM G.FV $ mapM redCTerm terms
K (KS str) -> return $ G.K str
EInt i -> return $ G.EInt $ fromInteger i
E -> return $ G.Empty
K (KP d vs) -> return $
G.Alts (tList d,[(tList s, G.Strs $ map G.K v) | Var s v <- vs])
@@ -169,5 +171,6 @@ redPatt p = case p of
ls' = map redLabel ls
ts <- mapM redPatt ts
return $ G.PR $ zip ls' ts
PI i -> return $ G.PInt (fromInteger i)
_ -> Bad $ "cannot recompile pattern" +++ show p

View File

@@ -93,6 +93,7 @@ RecType. CType ::= "{" [Labelling] "}" ;
Table. CType ::= "(" CType "=>" CType ")" ;
Cn. CType ::= CIdent ;
TStr. CType ::= "Str" ;
TInts. CType ::= "Ints" Integer ;
Lbg. Labelling ::= Label ":" CType ;
@@ -108,6 +109,7 @@ S. Term1 ::= Term1 "!" Term2 ;
C. Term ::= Term "++" Term1 ;
FV. Term1 ::= "variants" "{" [Term2] "}" ; --- no separator!
EInt. Term2 ::= Integer ;
K. Term2 ::= Tokn ;
E. Term2 ::= "[" "]" ;
@@ -129,6 +131,7 @@ PC. Patt ::= "(" CIdent [Patt] ")" ;
PV. Patt ::= Ident ;
PW. Patt ::= "_" ;
PR. Patt ::= "{" [PattAssign] "}" ;
PI. Patt ::= Integer ;
PAss. PattAssign ::= Label "=" Patt ;

View File

@@ -37,12 +37,12 @@ data Tok =
| TD String -- double precision float literals
| TC String -- character literals
deriving (Eq,Show)
deriving (Eq,Show,Ord)
data Token =
PT Posn Tok
| Err Posn
deriving Show
deriving (Eq,Show,Ord)
tokenPos (PT (Pn _ l _) _ :_) = "line " ++ show l
tokenPos (Err (Pn _ l _) :_) = "line " ++ show l
@@ -57,12 +57,13 @@ prToken t = case t of
PT _ (TV s) -> s
PT _ (TD s) -> s
PT _ (TC s) -> s
_ -> show t
eitherResIdent :: (String -> Tok) -> String -> Tok
eitherResIdent tv s = if isResWord s then (TS s) else (tv s) where
isResWord s = isInTree s $
B "lin" (B "data" (B "abstract" (B "Type" (B "Str" N N) N) (B "concrete" (B "cat" N N) N)) (B "grammar" (B "fun" (B "flags" N N) N) (B "in" N N))) (B "pre" (B "open" (B "of" (B "lincat" N N) N) (B "param" (B "oper" N N) N)) (B "transfer" (B "table" (B "resource" N N) N) (B "variants" N N)))
B "lin" (B "concrete" (B "Type" (B "Str" (B "Ints" N N) N) (B "cat" (B "abstract" N N) N)) (B "fun" (B "flags" (B "data" N N) N) (B "in" (B "grammar" N N) N))) (B "pre" (B "open" (B "of" (B "lincat" N N) N) (B "param" (B "oper" N N) N)) (B "transfer" (B "table" (B "resource" N N) N) (B "variants" N N)))
data BTree = N | B String BTree BTree deriving (Show)
@@ -90,7 +91,7 @@ unescapeInitTail = unesc . tail where
-------------------------------------------------------------------
data Posn = Pn !Int !Int !Int
deriving (Eq, Show)
deriving (Eq, Show,Ord)
alexStartPos :: Posn
alexStartPos = Pn 0 1 1

File diff suppressed because one or more lines are too long

View File

@@ -234,6 +234,7 @@ instance Print CType where
Table ctype0 ctype -> prPrec i 0 (concatD [doc (showString "(") , prt 0 ctype0 , doc (showString "=>") , prt 0 ctype , doc (showString ")")])
Cn cident -> prPrec i 0 (concatD [prt 0 cident])
TStr -> prPrec i 0 (concatD [doc (showString "Str")])
TInts n -> prPrec i 0 (concatD [doc (showString "Ints") , prt 0 n])
prtList es = case es of
[] -> (concatD [])
@@ -260,6 +261,7 @@ instance Print Term where
S term0 term -> prPrec i 1 (concatD [prt 1 term0 , doc (showString "!") , prt 2 term])
C term0 term -> prPrec i 0 (concatD [prt 0 term0 , doc (showString "++") , prt 1 term])
FV terms -> prPrec i 1 (concatD [doc (showString "variants") , doc (showString "{") , prt 2 terms , doc (showString "}")])
EInt n -> prPrec i 2 (concatD [prt 0 n])
K tokn -> prPrec i 2 (concatD [prt 0 tokn])
E -> prPrec i 2 (concatD [doc (showString "[") , doc (showString "]")])
@@ -322,6 +324,7 @@ instance Print Patt where
PV id -> prPrec i 0 (concatD [prt 0 id])
PW -> prPrec i 0 (concatD [doc (showString "_")])
PR pattassigns -> prPrec i 0 (concatD [doc (showString "{") , prt 0 pattassigns , doc (showString "}")])
PI n -> prPrec i 0 (concatD [prt 0 n])
prtList es = case es of
[] -> (concatD [])

View File

@@ -35,7 +35,7 @@ transModType x = case x of
transExtend :: Extend -> Result
transExtend x = case x of
Ext id -> failure x
Ext ids -> failure x
NoExt -> failure x
@@ -129,6 +129,7 @@ transCType x = case x of
Table ctype0 ctype -> failure x
Cn cident -> failure x
TStr -> failure x
TInts n -> failure x
transLabelling :: Labelling -> Result
@@ -148,6 +149,7 @@ transTerm x = case x of
S term0 term -> failure x
C term0 term -> failure x
FV terms -> failure x
EInt n -> failure x
K tokn -> failure x
E -> failure x
@@ -191,6 +193,7 @@ transPatt x = case x of
PV id -> failure x
PW -> failure x
PR pattassigns -> failure x
PI n -> failure x
transPattAssign :: PattAssign -> Result