mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-23 11:42:49 -06:00
Merge AId and App forms in GFCCRaw.
This commit is contained in:
@@ -9,7 +9,6 @@ data Grammar =
|
|||||||
|
|
||||||
data RExp =
|
data RExp =
|
||||||
App CId [RExp]
|
App CId [RExp]
|
||||||
| AId CId
|
|
||||||
| AInt Integer
|
| AInt Integer
|
||||||
| AStr String
|
| AStr String
|
||||||
| AFlt Double
|
| AFlt Double
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ import Data.Map
|
|||||||
|
|
||||||
toGFCC :: Grammar -> GFCC
|
toGFCC :: Grammar -> GFCC
|
||||||
toGFCC (Grm [
|
toGFCC (Grm [
|
||||||
App (CId "grammar") (AId a:cs),
|
App (CId "grammar") (App a []:cs),
|
||||||
App (CId "flags") gfs,
|
App (CId "flags") gfs,
|
||||||
ab@(
|
ab@(
|
||||||
App (CId "abstract") [
|
App (CId "abstract") [
|
||||||
@@ -26,7 +26,7 @@ toGFCC (Grm [
|
|||||||
App (CId "concrete") ccs
|
App (CId "concrete") ccs
|
||||||
]) = GFCC {
|
]) = GFCC {
|
||||||
absname = a,
|
absname = a,
|
||||||
cncnames = [c | AId c <- cs],
|
cncnames = [c | App c [] <- cs],
|
||||||
gflags = fromAscList [(f,v) | App f [AStr v] <- gfs],
|
gflags = fromAscList [(f,v) | App f [AStr v] <- gfs],
|
||||||
abstract =
|
abstract =
|
||||||
let
|
let
|
||||||
@@ -134,15 +134,15 @@ toHypo e = case e of
|
|||||||
|
|
||||||
toExp :: RExp -> Exp
|
toExp :: RExp -> Exp
|
||||||
toExp e = case e of
|
toExp e = case e of
|
||||||
App fun [App (CId "B") xs, App (CId "X") exps] ->
|
App (CId "App") [App fun [], App (CId "B") xs, App (CId "X") exps] ->
|
||||||
DTr [x | AId x <- xs] (AC fun) (lmap toExp exps)
|
DTr [x | App x [] <- xs] (AC fun) (lmap toExp exps)
|
||||||
App (CId "Eq") eqs ->
|
App (CId "Eq") eqs ->
|
||||||
EEq [Equ (lmap toExp ps) (toExp v) | App (CId "E") (v:ps) <- eqs]
|
EEq [Equ (lmap toExp ps) (toExp v) | App (CId "E") (v:ps) <- eqs]
|
||||||
|
App (CId "Var") [App i []] -> DTr [] (AV i) []
|
||||||
AMet -> DTr [] (AM 0) []
|
AMet -> DTr [] (AM 0) []
|
||||||
AInt i -> DTr [] (AI i) []
|
AInt i -> DTr [] (AI i) []
|
||||||
AFlt i -> DTr [] (AF i) []
|
AFlt i -> DTr [] (AF i) []
|
||||||
AStr i -> DTr [] (AS i) []
|
AStr i -> DTr [] (AS i) []
|
||||||
AId i -> DTr [] (AV i) []
|
|
||||||
_ -> error $ "exp " ++ show e
|
_ -> error $ "exp " ++ show e
|
||||||
|
|
||||||
toTerm :: RExp -> Term
|
toTerm :: RExp -> Term
|
||||||
@@ -153,10 +153,10 @@ toTerm e = case e of
|
|||||||
App (CId "P") [e,v] -> P (toTerm e) (toTerm v)
|
App (CId "P") [e,v] -> P (toTerm e) (toTerm v)
|
||||||
App (CId "RP") [e,v] -> RP (toTerm e) (toTerm v) ----
|
App (CId "RP") [e,v] -> RP (toTerm e) (toTerm v) ----
|
||||||
App (CId "W") [AStr s,v] -> W s (toTerm v)
|
App (CId "W") [AStr s,v] -> W s (toTerm v)
|
||||||
|
App (CId "A") [AInt i] -> V (fromInteger i)
|
||||||
|
App f [] -> F f
|
||||||
AInt i -> C (fromInteger i)
|
AInt i -> C (fromInteger i)
|
||||||
AMet -> TM
|
AMet -> TM
|
||||||
AId f -> F f
|
|
||||||
App (CId "A") [AInt i] -> V (fromInteger i)
|
|
||||||
AStr s -> K (KS s) ----
|
AStr s -> K (KS s) ----
|
||||||
_ -> error $ "term " ++ show e
|
_ -> error $ "term " ++ show e
|
||||||
|
|
||||||
@@ -166,7 +166,7 @@ toTerm e = case e of
|
|||||||
|
|
||||||
fromGFCC :: GFCC -> Grammar
|
fromGFCC :: GFCC -> Grammar
|
||||||
fromGFCC gfcc0 = Grm [
|
fromGFCC gfcc0 = Grm [
|
||||||
app "grammar" (AId (absname gfcc) : lmap AId (cncnames gfcc)),
|
app "grammar" (App (absname gfcc) [] : lmap (flip App []) (cncnames gfcc)),
|
||||||
app "flags" [App f [AStr v] | (f,v) <- toList (gflags gfcc `union` aflags agfcc)],
|
app "flags" [App f [AStr v] | (f,v) <- toList (gflags gfcc `union` aflags agfcc)],
|
||||||
app "abstract" [
|
app "abstract" [
|
||||||
app "fun" [App f [fromType t,fromExp d] | (f,(t,d)) <- toList (funs agfcc)],
|
app "fun" [App f [fromType t,fromExp d] | (f,(t,d)) <- toList (funs agfcc)],
|
||||||
@@ -202,10 +202,10 @@ fromHypo e = case e of
|
|||||||
fromExp :: Exp -> RExp
|
fromExp :: Exp -> RExp
|
||||||
fromExp e = case e of
|
fromExp e = case e of
|
||||||
DTr xs (AC fun) exps ->
|
DTr xs (AC fun) exps ->
|
||||||
App fun [App (CId "B") (lmap AId xs), App (CId "X") (lmap fromExp exps)]
|
App (CId "App") [App fun [], App (CId "B") (lmap (flip App []) xs), App (CId "X") (lmap fromExp exps)]
|
||||||
|
DTr [] (AV x) [] -> App (CId "Var") [App x []]
|
||||||
DTr [] (AS s) [] -> AStr s
|
DTr [] (AS s) [] -> AStr s
|
||||||
DTr [] (AF d) [] -> AFlt d
|
DTr [] (AF d) [] -> AFlt d
|
||||||
DTr [] (AV x) [] -> AId x
|
|
||||||
DTr [] (AI i) [] -> AInt (toInteger i)
|
DTr [] (AI i) [] -> AInt (toInteger i)
|
||||||
DTr [] (AM _) [] -> AMet ----
|
DTr [] (AM _) [] -> AMet ----
|
||||||
EEq eqs ->
|
EEq eqs ->
|
||||||
@@ -222,7 +222,7 @@ fromTerm e = case e of
|
|||||||
W s v -> app "W" [AStr s, fromTerm v]
|
W s v -> app "W" [AStr s, fromTerm v]
|
||||||
C i -> AInt (toInteger i)
|
C i -> AInt (toInteger i)
|
||||||
TM -> AMet
|
TM -> AMet
|
||||||
F f -> AId f
|
F f -> App f []
|
||||||
V i -> App (CId "A") [AInt (toInteger i)]
|
V i -> App (CId "A") [AInt (toInteger i)]
|
||||||
K (KS s) -> AStr s ----
|
K (KS s) -> AStr s ----
|
||||||
K (KP d vs) -> app "FV" (str d : [str v | Var v _ <- vs]) ----
|
K (KP d vs) -> app "FV" (str d : [str v | Var v _ <- vs]) ----
|
||||||
|
|||||||
@@ -14,13 +14,12 @@ pGrammar :: P Grammar
|
|||||||
pGrammar = liftM Grm pTerms
|
pGrammar = liftM Grm pTerms
|
||||||
|
|
||||||
pTerms :: P [RExp]
|
pTerms :: P [RExp]
|
||||||
pTerms = liftM2 (:) pTerm pTerms <++ (skipSpaces >> return [])
|
pTerms = liftM2 (:) (pTerm 1) pTerms <++ (skipSpaces >> return [])
|
||||||
|
|
||||||
pTerm :: P RExp
|
pTerm :: Int -> P RExp
|
||||||
pTerm = skipSpaces >> (pApp <++ pId <++ pNum <++ pStr <++ pMeta)
|
pTerm n = skipSpaces >> (pParen <++ pApp <++ pNum <++ pStr <++ pMeta)
|
||||||
where pApp = between (char '(') (char ')')
|
where pParen = between (char '(') (char ')') (pTerm 0)
|
||||||
(liftM2 App pIdent pTerms)
|
pApp = liftM2 App pIdent (if n == 0 then pTerms else return [])
|
||||||
pId = liftM AId pIdent
|
|
||||||
pStr = char '"' >> liftM AStr (manyTill (pEsc <++ get) (char '"'))
|
pStr = char '"' >> liftM AStr (manyTill (pEsc <++ get) (char '"'))
|
||||||
-- FIXME: what escapes are used?
|
-- FIXME: what escapes are used?
|
||||||
pEsc = char '\\' >> get
|
pEsc = char '\\' >> get
|
||||||
|
|||||||
@@ -10,15 +10,14 @@ printTree g = prGrammar g ""
|
|||||||
prGrammar :: Grammar -> ShowS
|
prGrammar :: Grammar -> ShowS
|
||||||
prGrammar (Grm xs) = prRExpList xs
|
prGrammar (Grm xs) = prRExpList xs
|
||||||
|
|
||||||
prRExp :: RExp -> ShowS
|
prRExp :: Int -> RExp -> ShowS
|
||||||
prRExp (App x []) = showChar '(' . prCId x . showChar ')'
|
prRExp _ (App x []) = prCId x
|
||||||
prRExp (App x xs) = showChar '(' . prCId x . showChar ' '
|
prRExp n (App x xs) = p (prCId x . showChar ' ' . prRExpList xs)
|
||||||
. prRExpList xs . showChar ')'
|
where p s = if n == 0 then s else showChar '(' . s . showChar ')'
|
||||||
prRExp (AId x) = prCId x
|
prRExp _ (AInt x) = shows x
|
||||||
prRExp (AInt x) = shows x
|
prRExp _ (AStr x) = showChar '"' . concatS (map mkEsc x) . showChar '"'
|
||||||
prRExp (AStr x) = showChar '"' . concatS (map mkEsc x) . showChar '"'
|
prRExp _ (AFlt x) = shows x -- FIXME: simpler format
|
||||||
prRExp (AFlt x) = shows x -- FIXME: simpler format
|
prRExp _ AMet = showChar '?'
|
||||||
prRExp AMet = showChar '?'
|
|
||||||
|
|
||||||
mkEsc :: Char -> ShowS
|
mkEsc :: Char -> ShowS
|
||||||
mkEsc s = case s of
|
mkEsc s = case s of
|
||||||
@@ -29,7 +28,7 @@ mkEsc s = case s of
|
|||||||
_ -> showChar s
|
_ -> showChar s
|
||||||
|
|
||||||
prRExpList :: [RExp] -> ShowS
|
prRExpList :: [RExp] -> ShowS
|
||||||
prRExpList = concatS . intersperse (showChar ' ') . map prRExp
|
prRExpList = concatS . intersperse (showChar ' ') . map (prRExp 1)
|
||||||
|
|
||||||
prCId :: CId -> ShowS
|
prCId :: CId -> ShowS
|
||||||
prCId (CId x) = showString x
|
prCId (CId x) = showString x
|
||||||
|
|||||||
Reference in New Issue
Block a user