mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-23 19:42:50 -06:00
added linearize -all
This commit is contained in:
@@ -103,7 +103,7 @@ allCommands mgr = Map.fromAscList [
|
|||||||
}),
|
}),
|
||||||
("l", emptyCommandInfo {
|
("l", emptyCommandInfo {
|
||||||
exec = \opts -> return . fromStrings . map (optLin opts),
|
exec = \opts -> return . fromStrings . map (optLin opts),
|
||||||
options = ["record","table","term"],
|
options = ["all","record","table","term"],
|
||||||
flags = ["lang"]
|
flags = ["lang"]
|
||||||
}),
|
}),
|
||||||
("p", emptyCommandInfo {
|
("p", emptyCommandInfo {
|
||||||
@@ -117,6 +117,7 @@ allCommands mgr = Map.fromAscList [
|
|||||||
|
|
||||||
optLin opts t = unlines [linea lang t | lang <- optLangs opts] where
|
optLin opts t = unlines [linea lang t | lang <- optLangs opts] where
|
||||||
linea lang = case opts of
|
linea lang = case opts of
|
||||||
|
_ | isOpt "all" opts -> allLinearize gr (cid lang)
|
||||||
_ | isOpt "table" opts -> tableLinearize gr (cid lang)
|
_ | isOpt "table" opts -> tableLinearize gr (cid lang)
|
||||||
_ | isOpt "term" opts -> termLinearize gr (cid lang)
|
_ | isOpt "term" opts -> termLinearize gr (cid lang)
|
||||||
_ | isOpt "record" opts -> recordLinearize gr (cid lang)
|
_ | isOpt "record" opts -> recordLinearize gr (cid lang)
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
module GF.GFCC.ShowLinearize (
|
module GF.GFCC.ShowLinearize (
|
||||||
tableLinearize,
|
tableLinearize,
|
||||||
recordLinearize,
|
recordLinearize,
|
||||||
termLinearize
|
termLinearize,
|
||||||
|
allLinearize
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import GF.GFCC.Linearize
|
import GF.GFCC.Linearize
|
||||||
@@ -13,8 +14,9 @@ import GF.GFCC.PrintGFCC ----
|
|||||||
import GF.Data.Operations
|
import GF.Data.Operations
|
||||||
import Data.List
|
import Data.List
|
||||||
|
|
||||||
-- printing linearizations with parameters
|
-- printing linearizations in different ways with source parameters
|
||||||
|
|
||||||
|
-- internal representation, only used internally in this module
|
||||||
data Record =
|
data Record =
|
||||||
RR [(String,Record)]
|
RR [(String,Record)]
|
||||||
| RT [(String,Record)]
|
| RT [(String,Record)]
|
||||||
@@ -36,6 +38,7 @@ prRecord = prr where
|
|||||||
RS s -> prQuotedString s
|
RS s -> prQuotedString s
|
||||||
RCon s -> s
|
RCon s -> s
|
||||||
|
|
||||||
|
-- uses the encoding of record types in GFCC.paramlincat
|
||||||
mkRecord :: Term -> Term -> Record
|
mkRecord :: Term -> Term -> Record
|
||||||
mkRecord typ trm = case (typ,trm) of
|
mkRecord typ trm = case (typ,trm) of
|
||||||
(R rs, R ts) -> RR [(str lab, mkRecord ty t) | (P lab ty, t) <- zip rs ts]
|
(R rs, R ts) -> RR [(str lab, mkRecord ty t) | (P lab ty, t) <- zip rs ts]
|
||||||
@@ -47,23 +50,38 @@ mkRecord typ trm = case (typ,trm) of
|
|||||||
where
|
where
|
||||||
str = realize
|
str = realize
|
||||||
|
|
||||||
|
-- show all branches, without labels and params
|
||||||
|
allLinearize :: GFCC -> CId -> Exp -> String
|
||||||
|
allLinearize gfcc lang = concat . map pr . tabularLinearize gfcc lang where
|
||||||
|
pr (p,vs) = unlines vs
|
||||||
|
|
||||||
|
-- show all branches, with labels and params
|
||||||
tableLinearize :: GFCC -> CId -> Exp -> String
|
tableLinearize :: GFCC -> CId -> Exp -> String
|
||||||
tableLinearize gfcc lang = unlines . branches . recLinearize gfcc lang where
|
tableLinearize gfcc lang = unlines . map pr . tabularLinearize gfcc lang where
|
||||||
|
pr (p,vs) = p +++ ":" +++ unwords (intersperse "|" vs)
|
||||||
|
|
||||||
|
-- create a table from labels+params to variants
|
||||||
|
tabularLinearize :: GFCC -> CId -> Exp -> [(String,[String])]
|
||||||
|
tabularLinearize gfcc lang = branches . recLinearize gfcc lang where
|
||||||
branches r = case r of
|
branches r = case r of
|
||||||
RR fs -> [lab +++ b | (lab,t) <- fs, b <- branches t]
|
RR fs -> [(lab +++ b,s) | (lab,t) <- fs, (b,s) <- branches t]
|
||||||
RT fs -> [lab +++ b | (lab,t) <- fs, b <- branches t]
|
RT fs -> [(lab +++ b,s) | (lab,t) <- fs, (b,s) <- branches t]
|
||||||
RFV rs -> intersperse "|" (concatMap branches rs)
|
RFV rs -> [([], ss) | (_,ss) <- concatMap branches rs]
|
||||||
RS s -> [" : " ++ s]
|
RS s -> [([], [s])]
|
||||||
RCon _ -> []
|
RCon _ -> []
|
||||||
|
|
||||||
|
-- show record in GF-source-like syntax
|
||||||
recordLinearize :: GFCC -> CId -> Exp -> String
|
recordLinearize :: GFCC -> CId -> Exp -> String
|
||||||
recordLinearize gfcc lang = prRecord . recLinearize gfcc lang
|
recordLinearize gfcc lang = prRecord . recLinearize gfcc lang
|
||||||
|
|
||||||
termLinearize :: GFCC -> CId -> Exp -> String
|
-- create a GF-like record, forming the basis of all functions above
|
||||||
termLinearize gfcc lang = printTree . linExp gfcc lang
|
|
||||||
|
|
||||||
recLinearize :: GFCC -> CId -> Exp -> Record
|
recLinearize :: GFCC -> CId -> Exp -> Record
|
||||||
recLinearize gfcc lang exp = mkRecord typ $ linExp gfcc lang exp where
|
recLinearize gfcc lang exp = mkRecord typ $ linExp gfcc lang exp where
|
||||||
typ = case exp of
|
typ = case exp of
|
||||||
DTr _ (AC f) _ -> lookParamLincat gfcc lang $ valCat $ lookType gfcc f
|
DTr _ (AC f) _ -> lookParamLincat gfcc lang $ valCat $ lookType gfcc f
|
||||||
|
|
||||||
|
-- show GFCC term
|
||||||
|
termLinearize :: GFCC -> CId -> Exp -> String
|
||||||
|
termLinearize gfcc lang = printTree . linExp gfcc lang
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user