1
0
forked from GitHub/gf-core

added the "alter lin" command

This commit is contained in:
Krasimir Angelov
2023-03-07 15:29:58 +01:00
parent c7e988dacf
commit 9dc36a0f5f
9 changed files with 108 additions and 18 deletions

View File

@@ -17,7 +17,7 @@ data TransactionCommand
= CreateFun [Option] Fun Type
| CreateCat [Option] Cat [Hypo]
| CreateConcrete [Option] ConcName
| CreateLin [Option] Fun Term
| CreateLin [Option] Fun Term Bool
| CreateLincat [Option] Cat Term
| DropFun [Option] Fun
| DropCat [Option] Cat

View File

@@ -716,6 +716,20 @@ pgfCommands = Map.fromList [
],
needsTypeCheck = False
}),
("a", emptyCommandInfo {
longname = "alter",
syntax = "alter lin f = ..",
synopsis = "Dynamically updates the linearization of a function in the current grammar.",
explanation = unlines [
"The syntax is the same as if the definition was in a module. If you want to use",
"any operations inside the lin definition, you should import them",
"by using the command `i -resource <file path>`."
],
flags = [
("lang","the language in which to alter the lin")
],
needsTypeCheck = False
}),
("d", emptyCommandInfo {
longname = "drop",
syntax = "drop fun f; drop cat c; drop concrete l; drop lin c; or drop lincat c",

View File

@@ -82,7 +82,7 @@ pTransactionCommand = do
| take 1 cmd == "d" -> do
name <- pIdent
return (DropConcrete opts name)
"lin" | take 1 cmd == "c" -> do
"lin" | elem (take 1 cmd) ["c","a"] -> do
f <- pIdent
skipSpaces
args <- sepBy pIdent skipSpaces
@@ -92,7 +92,7 @@ pTransactionCommand = do
t <- readS_to_P (\s -> case runPartial pTerm s of
Right (s,t) -> [(t,s)]
_ -> [])
return (CreateLin opts f (foldr (Abs Explicit . identS) t args))
return (CreateLin opts f (foldr (Abs Explicit . identS) t args) (take 1 cmd == "a"))
| take 1 cmd == "d" -> do
f <- pIdent
return (DropLin opts f)

View File

@@ -138,7 +138,7 @@ execute1 readNGF s0 =
continue
_ -> do putStrLnE $ "no import in history"
continue
(w :ws) | w == "c" || w == "d" -> do
(w :ws) | elem w ["c","a","d"] -> do
case readTransactionCommand s0 of
Just cmd -> do checkout
env <- gets pgfenv
@@ -282,7 +282,7 @@ transactionCommand (CreateCat opts c ctxt) pgf mb_txnid = do
transactionCommand (CreateConcrete opts name) pgf mb_txnid = do
lift $ updatePGF pgf mb_txnid (createConcrete name (return ()))
return ()
transactionCommand (CreateLin opts f t) pgf mb_txnid = do
transactionCommand (CreateLin opts f t is_alter) pgf mb_txnid = do
sgr <- getGrammar
lang <- optLang pgf opts
mo <- maybe (fail "no source grammar in scope") return $
@@ -297,7 +297,7 @@ transactionCommand (CreateLin opts f t) pgf mb_txnid = do
Just fields -> case runCheck (compileLinTerm sgr mo t (type2term mo ty)) of
Ok ((prods,seqtbl,fields'),_)
| fields == fields' -> do
createLin f prods seqtbl
(if is_alter then alterLin else createLin) f prods seqtbl
return ()
| otherwise -> fail "The linearization categories in the resource and the compiled grammar does not match"
Bad msg -> fail msg