1
0
forked from GitHub/gf-core

add commands to add/remove concrete syntaxes

This commit is contained in:
krangelov
2021-12-24 13:56:27 +01:00
parent 67a7e928f6
commit cb10e2fe32
4 changed files with 21 additions and 6 deletions

View File

@@ -16,10 +16,12 @@ data Command
data TransactionCommand data TransactionCommand
= CreateFun [Option] Fun Type = CreateFun [Option] Fun Type
| CreateCat [Option] Cat [Hypo] | CreateCat [Option] Cat [Hypo]
| CreateConcrete [Option] ConcName
| CreateLin [Option] Fun Term | CreateLin [Option] Fun Term
| CreateLincat [Option] Cat Term | CreateLincat [Option] Cat Term
| DropFun [Option] Fun | DropFun [Option] Fun
| DropCat [Option] Cat | DropCat [Option] Cat
| DropConcrete [Option] ConcName
| DropLin [Option] Fun | DropLin [Option] Fun
| DropLincat [Option] Cat | DropLincat [Option] Cat
deriving Show deriving Show

View File

@@ -684,10 +684,10 @@ pgfCommands = Map.fromList [
}), }),
("c", emptyCommandInfo { ("c", emptyCommandInfo {
longname = "create", longname = "create",
syntax = "create fun f = ..; create cat c = ..; create lin c = ..; or create lincat c = ..", syntax = "create fun f = ..; create cat c = ..; create concrete l; create lin c = ..; or create lincat c = ..",
synopsis = "Dynamically adds new functions and categories to the current grammar.", synopsis = "Dynamically adds new functions, categories and languages to the current grammar.",
explanation = unlines [ explanation = unlines [
"After the command you can write fun, data, cat, lin or a lincat definition.", "After the command you can write fun, data, cat, concrete, lin or a lincat definition.",
"The syntax is the same as if the definition was in a module. If you want to use", "The syntax is the same as if the definition was in a module. If you want to use",
"any operations inside lin and lincat, you should import them", "any operations inside lin and lincat, you should import them",
"by using the command `i -resource <file path>`." "by using the command `i -resource <file path>`."
@@ -700,11 +700,11 @@ pgfCommands = Map.fromList [
}), }),
("d", emptyCommandInfo { ("d", emptyCommandInfo {
longname = "drop", longname = "drop",
syntax = "drop fun f; drop cat c; drop lin c; or drop lincat c", syntax = "drop fun f; drop cat c; drop concrete l; drop lin c; or drop lincat c",
synopsis = "Dynamically removes functions and categories from the current grammar.", synopsis = "Dynamically removes functions, categories and languages from the current grammar.",
explanation = unlines [ explanation = unlines [
"After the command you must specify whether you want to remove", "After the command you must specify whether you want to remove",
"fun, data, cat, lin or a lincat definition.", "fun, data, cat, concrete, lin or a lincat definition.",
"Note that if you are removing an abstract function or category,", "Note that if you are removing an abstract function or category,",
"then all corresponding linearizations will be dropped as well." "then all corresponding linearizations will be dropped as well."
], ],

View File

@@ -75,6 +75,13 @@ pTransactionCommand = do
| take 1 cmd == "d" -> do | take 1 cmd == "d" -> do
c <- pIdent c <- pIdent
return (DropCat opts c) return (DropCat opts c)
"concrete"
| take 1 cmd == "c" -> do
name <- pIdent
return (CreateConcrete opts name)
| take 1 cmd == "d" -> do
name <- pIdent
return (DropConcrete opts name)
"lin" | take 1 cmd == "c" -> do "lin" | take 1 cmd == "c" -> do
f <- pIdent f <- pIdent
skipSpaces skipSpaces

View File

@@ -242,6 +242,9 @@ transactionCommand (CreateCat opts c ctxt) pgf = do
Left msg -> putStrLnE msg Left msg -> putStrLnE msg
Right ty -> do lift $ modifyPGF pgf (createCategory c ctxt prob) Right ty -> do lift $ modifyPGF pgf (createCategory c ctxt prob)
return () return ()
transactionCommand (CreateConcrete opts name) pgf = do
lift $ modifyPGF pgf (createConcrete name (return ()))
return ()
transactionCommand (CreateLin opts f t) pgf = do transactionCommand (CreateLin opts f t) pgf = do
lang <- optLang pgf opts lang <- optLang pgf opts
lift $ modifyPGF pgf (alterConcrete lang (createLin f [])) lift $ modifyPGF pgf (alterConcrete lang (createLin f []))
@@ -256,6 +259,9 @@ transactionCommand (DropFun opts f) pgf = do
transactionCommand (DropCat opts c) pgf = do transactionCommand (DropCat opts c) pgf = do
lift $ modifyPGF pgf (dropCategory c) lift $ modifyPGF pgf (dropCategory c)
return () return ()
transactionCommand (DropConcrete opts name) pgf = do
lift $ modifyPGF pgf (dropConcrete name)
return ()
transactionCommand (DropLin opts f) pgf = do transactionCommand (DropLin opts f) pgf = do
lang <- optLang pgf opts lang <- optLang pgf opts
lift $ modifyPGF pgf (alterConcrete lang (dropLin f)) lift $ modifyPGF pgf (alterConcrete lang (dropLin f))