From 6feded5562edce95c9976ab22780694d4b8d6ef9 Mon Sep 17 00:00:00 2001 From: Ruslan Khafizov Date: Mon, 5 Dec 2022 14:01:28 +0800 Subject: [PATCH 1/3] Remove GF dependency --- Setup.hs | 89 +------ {src => attic}/ToGF/Disambiguate.hs | 0 {src => attic}/ToGF/FromL4/ToAnswers.hs | 0 {src => attic}/ToGF/FromL4/ToProp.hs | 0 {src => attic}/ToGF/FromL4/ToQuestions.hs | 0 {src => attic}/ToGF/FromL4/TransProp.hs | 0 {src => attic}/ToGF/FromSCasp/SCasp.hs | 0 {src => attic}/ToGF/FromSCasp/ToAnswer.hs | 0 {src => attic}/ToGF/GenerateLexicon.hs | 0 {src => attic}/ToGF/ParsePred.hs | 0 {src => attic}/ToGF/TreeTransform.hs | 0 {src => attic}/ToSCASP.hs | 0 baby-l4.cabal | 279 ---------------------- exe/Main.hs | 32 +-- hie.yaml | 46 ---- package.yaml | 69 ------ src/{ToGF => }/NormalizeSyntax.hs | 2 +- 17 files changed, 6 insertions(+), 511 deletions(-) rename {src => attic}/ToGF/Disambiguate.hs (100%) rename {src => attic}/ToGF/FromL4/ToAnswers.hs (100%) rename {src => attic}/ToGF/FromL4/ToProp.hs (100%) rename {src => attic}/ToGF/FromL4/ToQuestions.hs (100%) rename {src => attic}/ToGF/FromL4/TransProp.hs (100%) rename {src => attic}/ToGF/FromSCasp/SCasp.hs (100%) rename {src => attic}/ToGF/FromSCasp/ToAnswer.hs (100%) rename {src => attic}/ToGF/GenerateLexicon.hs (100%) rename {src => attic}/ToGF/ParsePred.hs (100%) rename {src => attic}/ToGF/TreeTransform.hs (100%) rename {src => attic}/ToSCASP.hs (100%) delete mode 100644 baby-l4.cabal delete mode 100644 hie.yaml rename src/{ToGF => }/NormalizeSyntax.hs (99%) diff --git a/Setup.hs b/Setup.hs index 5838245a..9a994af6 100644 --- a/Setup.hs +++ b/Setup.hs @@ -1,89 +1,2 @@ import Distribution.Simple -import Distribution.Simple.PreProcess -import Distribution.PackageDescription -import Distribution.Simple.LocalBuildInfo -import Distribution.Simple.Program -import System.FilePath (()) -import Distribution.Simple.Utils (createDirectoryIfMissingVerbose, installOrdinaryFile) -import Distribution.Simple.Setup (installDest, InstallFlags (installVerbosity), CopyFlags (copyDest, copyVerbosity)) -import Distribution.Simple.Flag -import Distribution.Verbosity -import System.Environment (lookupEnv) - --- Custom preprocessor for GF files - --- Currently has problems with stack due to: --- https://github.com/commercialhaskell/stack/issues/3491 - --- TODO: Fix the above issue - -main :: IO () -main = defaultMainWithHooks userHooks - -userHooks :: UserHooks -userHooks = simpleUserHooks { - hookedPreProcessors = gfPPSuffix : knownSuffixHandlers - , postCopy = \args insF pDesc lbi -> do - -- print $ buildDir lbi - let cdest = fromFlag $ copyDest insF - let dDir = datadir $ absoluteComponentInstallDirs pDesc lbi (localUnitId lbi) cdest - let verbosity = fromFlag $ copyVerbosity insF - let src = buildDir lbi "l4-generated" "ParsePredicates.pgf" - let dst = dDir "grammars" "ParsePredicates.pgf" - -- print dDir - createDirectoryIfMissingVerbose verbosity True (dDir "grammars") - installOrdinaryFile verbosity src dst - return () -} - -gfPPSuffix :: PPSuffixHandler -gfPPSuffix = ("gf" , gfPP) - -gfPP :: BuildInfo -> LocalBuildInfo -> ComponentLocalBuildInfo -> PreProcessor -gfPP bi lbi clbi = PreProcessor { - platformIndependent = True, - runPreProcessor = \(inDir,inFile) (outDir,outFile) verbosity -> do - -- putStrLn $ "hello world! " ++ show ((inDir,inFile), (outDir,outFile), verbosity) - gfLibPath <- lookupEnv "GF_LIB_PATH" - putStrLn $ "GF_LIB_PATH=" ++ show gfLibPath - let lexical = getLexCategories inFile - concrete = case inFile of - "ParsePredicates.gf" -> [inDir "ParsePredicatesEng.gf"] - _ -> [] - let args = - [ "-make" - , "-v=0" - , "-f", "haskell" - , "--haskell=gadt" ] - ++ lexical - ++ ["--output-dir=" ++ outDir - , "--gfo-dir=" ++ outDir - , inDir inFile - ] ++ concrete - - print args - (gfProg, _) <- requireProgram verbosity gfProgram (withPrograms lbi) - -- runDbProgram verbosity gfProgram (withPrograms lbi) args - runProgram verbosity gfProg args - putStrLn "Done running" -} - -gfProgram :: Program -gfProgram = simpleProgram "gf" - -getLexCategories fname = case fname of - "Atoms.gf" - -> lexPrefix "Atom" - "Prop.gf" - -> getLexCategories "Atoms.gf" - "Answer.gf" - -> getLexCategories "Atoms.gf" - "Questions.gf" - -> getLexCategories "Atoms.gf" - "Predicates.gf" - -> lexPrefix "N,V,A,N2,N3,V2,A2,VA,V2V,VV,V3,VS,V2A,V2S,V2Q,Adv,AdV,AdA,AdN,ACard,CAdv,Conj,Interj,PN,Prep,Pron,Quant,Det,Card,Text,Predet,Subj" - "ParsePredicates.gf" - -> getLexCategories "Predicates.gf" - _ -> [] - where - lexPrefix x = ["--haskell=lexical", "--lexical="++x] +main = defaultMain diff --git a/src/ToGF/Disambiguate.hs b/attic/ToGF/Disambiguate.hs similarity index 100% rename from src/ToGF/Disambiguate.hs rename to attic/ToGF/Disambiguate.hs diff --git a/src/ToGF/FromL4/ToAnswers.hs b/attic/ToGF/FromL4/ToAnswers.hs similarity index 100% rename from src/ToGF/FromL4/ToAnswers.hs rename to attic/ToGF/FromL4/ToAnswers.hs diff --git a/src/ToGF/FromL4/ToProp.hs b/attic/ToGF/FromL4/ToProp.hs similarity index 100% rename from src/ToGF/FromL4/ToProp.hs rename to attic/ToGF/FromL4/ToProp.hs diff --git a/src/ToGF/FromL4/ToQuestions.hs b/attic/ToGF/FromL4/ToQuestions.hs similarity index 100% rename from src/ToGF/FromL4/ToQuestions.hs rename to attic/ToGF/FromL4/ToQuestions.hs diff --git a/src/ToGF/FromL4/TransProp.hs b/attic/ToGF/FromL4/TransProp.hs similarity index 100% rename from src/ToGF/FromL4/TransProp.hs rename to attic/ToGF/FromL4/TransProp.hs diff --git a/src/ToGF/FromSCasp/SCasp.hs b/attic/ToGF/FromSCasp/SCasp.hs similarity index 100% rename from src/ToGF/FromSCasp/SCasp.hs rename to attic/ToGF/FromSCasp/SCasp.hs diff --git a/src/ToGF/FromSCasp/ToAnswer.hs b/attic/ToGF/FromSCasp/ToAnswer.hs similarity index 100% rename from src/ToGF/FromSCasp/ToAnswer.hs rename to attic/ToGF/FromSCasp/ToAnswer.hs diff --git a/src/ToGF/GenerateLexicon.hs b/attic/ToGF/GenerateLexicon.hs similarity index 100% rename from src/ToGF/GenerateLexicon.hs rename to attic/ToGF/GenerateLexicon.hs diff --git a/src/ToGF/ParsePred.hs b/attic/ToGF/ParsePred.hs similarity index 100% rename from src/ToGF/ParsePred.hs rename to attic/ToGF/ParsePred.hs diff --git a/src/ToGF/TreeTransform.hs b/attic/ToGF/TreeTransform.hs similarity index 100% rename from src/ToGF/TreeTransform.hs rename to attic/ToGF/TreeTransform.hs diff --git a/src/ToSCASP.hs b/attic/ToSCASP.hs similarity index 100% rename from src/ToSCASP.hs rename to attic/ToSCASP.hs diff --git a/baby-l4.cabal b/baby-l4.cabal deleted file mode 100644 index 0029c5cf..00000000 --- a/baby-l4.cabal +++ /dev/null @@ -1,279 +0,0 @@ -cabal-version: 2.0 - --- This file has been generated from package.yaml by hpack version 0.35.0. --- --- see: https://github.com/sol/hpack - -name: baby-l4 -version: 0.1.2.1 -description: baby-l4 provides the core language to which natural4 compiles. -homepage: https://github.com/smucclaw/baby-l4#readme -bug-reports: https://github.com/smucclaw/baby-l4/issues -author: Wong Meng Weng -maintainer: mwwong@smu.edu.sg -copyright: 2022 -license: BSD3 -license-file: LICENSE -build-type: Custom -extra-source-files: - README.org - grammars/Prop.gf - grammars/Answer.gf - grammars/Questions.gf - grammars/Predicates.gf - grammars/ParsePredicates.gf -data-files: - l4/Prelude.l4 - grammars/Prop.gf - grammars/PropI.gf - grammars/PropEng.gf - grammars/Atoms.gf - grammars/AtomsEng.gf - grammars/Answer.gf - grammars/AnswerEng.gf - grammars/Questions.gf - grammars/QuestionsEng.gf - grammars/Predicates.gf - grammars/PredicatesEng.gf - grammars/ReducedWordNet.gf - grammars/ReducedWordNetEng.gf - grammars/ParsePredicates.labels - grammars/ParsePredicatesEng.labels - -source-repository head - type: git - location: https://github.com/smucclaw/baby-l4 - -custom-setup - setup-depends: - Cabal ==3.6.3.0 - , base >=4.7 && <5 - , filepath - -library - exposed-modules: - Exec - InterfaceNunchaku - JustificationVis - L4.Annotation - L4.Error - L4.KeyValueMap - L4.Lexer - L4.Parser - L4.PrintProg - L4.Syntax - L4.SyntaxManipulation - L4.TypeInference - L4.Typing - MainHelpers - Model - Proof - RuleTransfo - SimpleRules - Smt - TimedMC - ToASP - ToDA2 - ToDMN.FromL4 - ToDMN.FromSimpleToReg - ToDMN.Picklers - ToDMN.Types - ToEpilog - ToGF.Disambiguate - ToGF.FromL4.ToAnswers - ToGF.FromL4.ToProp - ToGF.FromL4.ToQuestions - ToGF.FromL4.TransProp - ToGF.FromSCasp.SCasp - ToGF.FromSCasp.ToAnswer - ToGF.GenerateLexicon - ToGF.NormalizeSyntax - ToGF.ParsePred - ToGF.TreeTransform - ToRules.FromL4 - ToRules.ToDecls - ToRules.ToRules - ToRules.Types - ToSCASP - other-modules: - Paths_baby_l4 - autogen-modules: - Paths_baby_l4 - hs-source-dirs: - src - ghc-options: -Wall -Wno-missed-extra-shared-lib - build-depends: - MissingH - , array - , base >=4.7 && <5 - , containers - , either - , extra - , fgl - , gf - , gf-ud - , ghc - , graphviz - , haskeline - , hslogger - , hxt - , l4-generated - , lens - , lsp - , lsp-types - , megaparsec - , mmorph - , mtl - , optparse-applicative - , pretty-simple - , prettyprinter >=1.7.0 - , sbv - , simple-smt - , sorted-list - , split - , tasty - , tasty-hunit - , text - , transformers - default-language: Haskell2010 - -library l4-generated - exposed-modules: - Prop - Answer - Questions - ParsePredicates - Predicates - other-modules: - Paths_baby_l4 - autogen-modules: - Paths_baby_l4 - hs-source-dirs: - grammars - ghc-options: -Wall -Wno-missed-extra-shared-lib - build-tool-depends: - gf:gf - build-depends: - MissingH - , array - , base >=4.7 && <5 - , containers - , either - , extra - , fgl - , gf - , gf-ud - , ghc - , graphviz - , haskeline - , hslogger - , hxt - , lens - , lsp - , lsp-types - , megaparsec - , mmorph - , mtl - , optparse-applicative - , pretty-simple - , prettyprinter >=1.7.0 - , sbv - , simple-smt - , sorted-list - , split - , tasty - , tasty-hunit - , text - , transformers - default-language: Haskell2010 - -executable hxtread - main-is: Main.hs - other-modules: - DecTables - Paths_baby_l4 - autogen-modules: - Paths_baby_l4 - hs-source-dirs: - hxtread - ghc-options: -Wall -Wno-missed-extra-shared-lib - build-depends: - MissingH - , array - , baby-l4 - , base >=4.7 && <5 - , containers - , either - , extra - , fgl - , gf - , gf-ud - , ghc - , graphviz - , haskeline - , hslogger - , hxt - , hxt-css - , lens - , lsp - , lsp-types - , megaparsec - , mmorph - , mtl - , optparse-applicative - , pretty-simple - , prettyprinter >=1.7.0 - , sbv - , simple-smt - , sorted-list - , split - , tasty - , tasty-hunit - , text - , transformers - default-language: Haskell2010 - -executable l4 - main-is: Main.hs - other-modules: - Paths_baby_l4 - autogen-modules: - Paths_baby_l4 - hs-source-dirs: - exe - ghc-options: -Wall -Wno-missed-extra-shared-lib -threaded -rtsopts "-with-rtsopts=-N -H500M -qg" - build-depends: - MissingH - , array - , baby-l4 - , base >=4.7 && <5 - , containers - , either - , extra - , fgl - , gf - , gf-ud - , ghc - , graphviz - , haskeline - , hslogger - , hxt - , l4-generated - , lens - , lsp - , lsp-types - , megaparsec - , mmorph - , mtl - , optparse-applicative - , pretty-simple - , prettyprinter >=1.7.0 - , sbv - , simple-smt - , sorted-list - , split - , tasty - , tasty-hunit - , text - , transformers - default-language: Haskell2010 diff --git a/exe/Main.hs b/exe/Main.hs index a2dd4628..33325e30 100644 --- a/exe/Main.hs +++ b/exe/Main.hs @@ -11,22 +11,16 @@ import L4.Typing ( checkError ) import Proof (proveProgram) import System.Environment ( getEnv ) import Options.Applicative -import qualified ToGF.FromL4.ToProp as GF import System.IO ( stderr, hPutStr, hPutStrLn, hPrint ) import System.IO.Error (catchIOError) import Control.Exception (catch, SomeException (SomeException)) import Control.Monad ( when, unless ) -import ToSCASP (createSCasp) -import ToGF.FromSCasp.SCasp ( parseModel ) -import ToGF.FromSCasp.ToAnswer ( nlgModels ) -import ToGF.FromL4.ToQuestions ( createQuestions ) -import ToGF.FromL4.ToAnswers ( createPGFforAnswers ) -import ToGF.NormalizeSyntax import L4.Annotation ( SRng, LocTypeAnnot (typeAnnot) ) import Paths_baby_l4 (getDataFileName) import Text.Pretty.Simple ( pPrint, pPrintString, pPrint ) import L4.Error (printError) import Data.Either (rights) +import NormalizeSyntax import MainHelpers (readPrelude, getTpAst, HelperErr(..) ) import Control.Monad.Except (runExceptT) @@ -59,21 +53,16 @@ process args input = do (Fexpsys Graph) -> expSys tpAstNoSrc -- (Fexpsys Rules) -> astToRules tpAstNoSrc (Fexpsys Rules) -> genREP tpAstNoSrc - (Fgf GFOpts { gflang = gfl, showast = True } ) -> GF.nlgAST gfl fpath normalAst - (Fgf GFOpts { gflang = gfl, showast = False} ) -> GF.nlg gfl fpath normalAst Fdmn -> genDMN tpAstNoSrc - Fepilog -> astToEpilog tpAstNoSrc - Fscasp -> createSCasp normalAst + Fepilog -> astToEpilog tpAstNoSrc Fsmt -> proveProgram tpAstNoSrc Fyaml -> do createDSyaml tpAstNoSrc putStrLn "---------------" putStrLn "WIP: create the questions with GF. Below is the current progress. They are not used yet in the yaml." - createQuestions fpath normalAst putStrLn "---------------" - createPGFforAnswers fpath normalAst -data Format = Fasp | Fast | Fdmn | Fepilog | Fexpsys ESOpts | Fgf GFOpts | Fscasp | Fsmt | Fyaml +data Format = Fasp | Fast | Fdmn | Fepilog | Fexpsys ESOpts | Fscasp | Fsmt | Fyaml deriving Show -- l4 gf en output english only @@ -89,18 +78,13 @@ data InputOpts = InputOpts , filepath :: FilePath } deriving Show -data GFOpts = GFOpts - { gflang :: GF.GFlang -- perhaps this should be a list of strings - , showast :: Bool } - deriving Show data ESOpts = Graph | Rules deriving Show optsParse :: Parser InputOpts optsParse = InputOpts <$> subparser - ( command "gf" (info gfSubparser gfHelper) - <> command "epilog" (info (pure Fepilog) (progDesc "output to Epilog")) + ( command "epilog" (info (pure Fepilog) (progDesc "output to Epilog")) <> command "asp" (info (pure Fasp) (progDesc "output to ASP / Clingo")) <> command "ast" (info (pure Fast) (progDesc "Show the AST in Haskell")) <> command "scasp" (info (pure Fscasp) (progDesc "output to sCASP for DocAssemble purposes")) @@ -113,14 +97,6 @@ optsParse = InputOpts <$> <*> argument str (metavar "Filename") <**> helper where - gfSubparser = fmap Fgf $ GFOpts <$> - subparser - ( command "all" (info (pure GF.GFall) (progDesc "tell GF to output all languages")) - <> command "en" (info (pure GF.GFeng) (progDesc "tell GF to output english")) - <> command "swe" (info (pure GF.GFswe) (progDesc "tell GF to output swedish")) - ) - <*> switch (long "ast" <> help "Print GF AST to STDERR") - <**> helper gfHelper = fullDesc <> header "l4 gf - specialized for natLang output" <> progDesc "Prints natLang format (subcommands: en, my)" diff --git a/hie.yaml b/hie.yaml deleted file mode 100644 index 73a168dd..00000000 --- a/hie.yaml +++ /dev/null @@ -1,46 +0,0 @@ -cradle: - multi: - - path: ./Setup.hs - config: - cradle: - none: {} - # direct: - # arguments: - # - "-package Cabal" - # - "-package base" - - path: "./grammars" - config: - cradle: - none: - # direct: - # arguments: - # - "-package Cabal" - # - "-package base" - - path: "*.x" - config: - cradle: - none: - - path: "*.y" - config: - cradle: - none: - - - path: "./" - config: - cradle: - stack: - - path: "./src" - component: "baby-l4:lib" - - - path: "./exe/Main.hs" - component: "baby-l4:exe:l4" - - - path: "./lsp/Main.hs" - component: "baby-l4:exe:lsp-server-bl4" - - - path: "./tests/" - component: "baby-l4:test:unit-tests" - - - path: "./lsp-tests/Test.hs" - component: "baby-l4:test:lsp-server-tests" - diff --git a/package.yaml b/package.yaml index 300a21d6..62f4dbc9 100644 --- a/package.yaml +++ b/package.yaml @@ -8,29 +8,9 @@ copyright: "2022" extra-source-files: - README.org -- grammars/Prop.gf -- grammars/Answer.gf -- grammars/Questions.gf -- grammars/Predicates.gf -- grammars/ParsePredicates.gf data-files: - l4/Prelude.l4 -- grammars/Prop.gf -- grammars/PropI.gf -- grammars/PropEng.gf -- grammars/Atoms.gf -- grammars/AtomsEng.gf -- grammars/Answer.gf -- grammars/AnswerEng.gf -- grammars/Questions.gf -- grammars/QuestionsEng.gf -- grammars/Predicates.gf -- grammars/PredicatesEng.gf -- grammars/ReducedWordNet.gf -- grammars/ReducedWordNetEng.gf -- grammars/ParsePredicates.labels -- grammars/ParsePredicatesEng.labels # To avoid duplicated efforts in documentation and dealing with the # complications of embedding Haddock markup inside cabal files, it is @@ -85,8 +65,6 @@ ghc-options: -Wall -Wno-missed-extra-shared-lib library: source-dirs: src - dependencies: - - l4-generated custom-setup: dependencies: @@ -94,23 +72,6 @@ custom-setup: - base >= 4.7 && < 5 - Cabal == 3.6.3.0 -internal-libraries: - l4-generated: - exposed-modules: - # generated from GF grammars - - Prop - - Answer - - Questions - - ParsePredicates - - Predicates - - dependencies: - - gf - build-tools: gf:gf - ghc-options: [] - source-dirs: - - grammars - language: Haskell2010 executables: l4: @@ -122,7 +83,6 @@ executables: - '"-with-rtsopts=-N -H500M -qg"' dependencies: - baby-l4 - - l4-generated hxtread: source-dirs: hxtread @@ -130,32 +90,3 @@ executables: dependencies: - hxt-css - baby-l4 - -# lsp-server-bl4: -# main: Main.hs -# source-dirs: lsp -# ghc-options: -# - -threaded -# - -rtsopts -# - '"-with-rtsopts=-N -H500M -qg"' -# dependencies: -# - baby-l4 -# - l4-generated - - -#tests: - # lsp-server-tests: - # main: Spec.hs - # source-dirs: lsp-tests - # ghc-options: - # - Wall - # dependencies: - # - tasty - # - tasty-hunit - # - tasty-expected-failure - # - baby-l4 - # - l4-generated - # - lsp-test - # - lsp-types - # - text - diff --git a/src/ToGF/NormalizeSyntax.hs b/src/NormalizeSyntax.hs similarity index 99% rename from src/ToGF/NormalizeSyntax.hs rename to src/NormalizeSyntax.hs index 8b23877c..ce8c5905 100644 --- a/src/ToGF/NormalizeSyntax.hs +++ b/src/NormalizeSyntax.hs @@ -1,6 +1,6 @@ {-# LANGUAGE TypeApplications #-} {-# LANGUAGE PatternSynonyms #-} -module ToGF.NormalizeSyntax where +module NormalizeSyntax where import L4.Annotation (HasDefault (defaultVal)) import Data.Char (toLower) From aa79c280ac6249edff3af2dea4ca05edf409496c Mon Sep 17 00:00:00 2001 From: Ruslan Khafizov Date: Mon, 5 Dec 2022 14:19:29 +0800 Subject: [PATCH 2/3] Upgrade ghc in flake --- flake.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index 71b52b40..5e080854 100644 --- a/flake.nix +++ b/flake.nix @@ -18,7 +18,7 @@ pkgs.mkShell { nativeBuildInputs = [ gf-pkgs.gf-with-rgl - pkgs.haskell.compiler.ghc884 + pkgs.haskell.compiler.ghc925 nixpkgs-newer.legacyPackages.${arch}.stack # pkgs.graphviz # pkgs.emacs From d6810f7fa5261368661a866bb08c02760a921096 Mon Sep 17 00:00:00 2001 From: Ruslan Khafizov Date: Mon, 5 Dec 2022 14:27:45 +0800 Subject: [PATCH 3/3] 9.2.5 seems to be missing --- flake.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index 5e080854..ed42e15d 100644 --- a/flake.nix +++ b/flake.nix @@ -18,7 +18,7 @@ pkgs.mkShell { nativeBuildInputs = [ gf-pkgs.gf-with-rgl - pkgs.haskell.compiler.ghc925 + pkgs.haskell.compiler.ghc924 nixpkgs-newer.legacyPackages.${arch}.stack # pkgs.graphviz # pkgs.emacs