Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

170 CLI command to generate PHI term #511

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions eo-phi-normalizer/app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ import PyF (fmt, fmtTrim)
import System.Directory (createDirectoryIfMissing, doesFileExist)
import System.FilePath (takeDirectory)
import System.IO (IOMode (WriteMode), getContents', hFlush, hPutStr, hPutStrLn, openFile, stdout)
import Language.EO.Phi.Generate

data CLI'TransformPhi = CLI'TransformPhi
{ chain :: Bool
Expand Down Expand Up @@ -133,12 +134,20 @@ data CLI'Pipeline
| CLI'Pipeline'PrintDataizeConfigs' CLI'Pipeline'PrintDataizeConfigs
deriving stock (Show)

data CLI'Generate = CLI'Generate
{ minTermSize :: Int
, maxTermSize :: Int
, quantity :: Int
}
deriving stock (Show)

data CLI
= CLI'TransformPhi' CLI'TransformPhi
| CLI'DataizePhi' CLI'DataizePhi
| CLI'MetricsPhi' CLI'MetricsPhi
| CLI'PrintRules' CLI'PrintRules
| CLI'Pipeline' CLI'Pipeline
| CLI'Generate' CLI'Generate
deriving stock (Show)

data MetavarName = MetavarName
Expand Down Expand Up @@ -238,6 +247,7 @@ data CommandParser = CommandParser
, pipeline :: Parser CLI'Pipeline
, pipeline' :: CommandParser'Pipeline
, printRules :: Parser CLI'PrintRules
, generate :: Parser CLI'Generate
}

commandParser :: CommandParser
Expand Down Expand Up @@ -304,6 +314,13 @@ commandParser =
<> command commandNames.pipeline'.prepareTests commandParserInfo.pipeline'.prepareTests
<> command commandNames.pipeline'.printDataizeConfigs commandParserInfo.pipeline'.printDataizeConfigs
)
generate = do
minTermSize <- option auto (long "min-size" <> value 30)
maxTermSize <- option auto (long "max-size" <> value 30)
-- minDepth <- option auto (long "min-depth" <> value 30)
-- maxDepth <- option auto (long "max-depth" <> value 30)
quantity <- argument auto (value 1)
pure CLI'Generate{..}

data CommandParserInfo'Pipeline = CommandParserInfo'Pipeline
{ report :: ParserInfo CLI'Pipeline
Expand All @@ -318,6 +335,7 @@ data CommandParserInfo = CommandParserInfo
, printRules :: ParserInfo CLI
, pipeline :: ParserInfo CLI
, pipeline' :: CommandParserInfo'Pipeline
, generate :: ParserInfo CLI
}

commandParserInfo :: CommandParserInfo
Expand All @@ -334,6 +352,7 @@ commandParserInfo =
, prepareTests = info (CLI'Pipeline'PrepareTests' <$> commandParser.pipeline'.prepareTests) (progDesc "Prepare EO test files for the pipeline.")
, printDataizeConfigs = info (CLI'Pipeline'PrintDataizeConfigs' <$> commandParser.pipeline'.printDataizeConfigs) (progDesc [fmt|Print configs for the `normalizer {commandNames.dataize}` command.|])
}
, generate = info (CLI'Generate' <$> commandParser.generate) (progDesc "Generate random PHI term.")
}

data CommandNames'Pipeline = CommandNames'Pipeline
Expand All @@ -349,6 +368,7 @@ data CommandNames = CommandNames
, printRules :: String
, pipeline :: String
, pipeline' :: CommandNames'Pipeline
, generate :: String
}

commandNames :: CommandNames
Expand All @@ -365,6 +385,7 @@ commandNames =
, prepareTests = "prepare-tests"
, printDataizeConfigs = "print-dataize-configs"
}
, generate = "generate"
}

cli :: Parser CLI
Expand All @@ -375,6 +396,7 @@ cli =
<> command commandNames.dataize commandParserInfo.dataize
<> command commandNames.pipeline commandParserInfo.pipeline
<> command commandNames.printRules commandParserInfo.printRules
<> command commandNames.generate commandParserInfo.generate
)

cliOpts :: String -> ParserInfo CLI
Expand Down Expand Up @@ -695,3 +717,9 @@ main = withUtf8 do
CLI'Pipeline' (CLI'Pipeline'PrintDataizeConfigs' CLI'Pipeline'PrintDataizeConfigs{..}) -> do
config <- decodeFileThrow @_ @PipelineConfig configFile
PrintConfigs.printDataizeConfigs config phiPrefixesToStrip singleLine
CLI'Generate' (CLI'Generate{..}) -> do
objs <- generateObjectsWith (GenerateOpts{ minSize = minTermSize, maxSize = maxTermSize, .. })
forM_ (zip [1..] objs) $ \(ind, obj) -> do
putStrLn $ "Term " ++ show ind ++ ":"
putStrLn $ printTree obj
putStrLn ""
7 changes: 6 additions & 1 deletion eo-phi-normalizer/eo-phi-normalizer.cabal
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cabal-version: 1.24

-- This file has been generated from package.yaml by hpack version 0.36.0.
-- This file has been generated from package.yaml by hpack version 0.37.0.
--
-- see: https://github.com/sol/hpack

Expand Down Expand Up @@ -146,6 +146,7 @@ library
Language.EO.Phi.Dataize.Atoms
Language.EO.Phi.Dataize.Context
Language.EO.Phi.Dependencies
Language.EO.Phi.Generate
Language.EO.Phi.Metrics.Collect
Language.EO.Phi.Metrics.Data
Language.EO.Phi.Normalize
Expand Down Expand Up @@ -181,6 +182,7 @@ library
BNFC:bnfc >=2.9.4.1
build-depends:
PyF
, QuickCheck
, aeson
, array >=0.5.5.0
, base >=4.7 && <5
Expand Down Expand Up @@ -220,6 +222,7 @@ executable normalizer
BNFC:bnfc >=2.9.4.1
build-depends:
PyF
, QuickCheck
, aeson
, aeson-pretty
, array >=0.5.5.0
Expand Down Expand Up @@ -256,6 +259,7 @@ test-suite doctests
Language.EO.Phi.Dataize.Atoms
Language.EO.Phi.Dataize.Context
Language.EO.Phi.Dependencies
Language.EO.Phi.Generate
Language.EO.Phi.Metrics.Collect
Language.EO.Phi.Metrics.Data
Language.EO.Phi.Normalize
Expand Down Expand Up @@ -292,6 +296,7 @@ test-suite doctests
BNFC:bnfc >=2.9.4.1
build-depends:
PyF
, QuickCheck
, aeson
, array >=0.5.5.0
, base >=4.7 && <5
Expand Down
1 change: 1 addition & 0 deletions eo-phi-normalizer/package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ dependencies:
- hashable
- unordered-containers
- containers
- QuickCheck

default-extensions:
- ImportQualifiedPost
Expand Down
Loading