From d8a0058e209ca8bb5175c0160b88f20f07daf58c Mon Sep 17 00:00:00 2001 From: Danila Danko Date: Fri, 29 Nov 2024 17:13:33 +0300 Subject: [PATCH 1/3] feat(eo-phi-normalizer): add `rewrite` flag to output an expression on a single line --- eo-phi-normalizer/app/Main.hs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/eo-phi-normalizer/app/Main.hs b/eo-phi-normalizer/app/Main.hs index 4f15d663..cd883fde 100644 --- a/eo-phi-normalizer/app/Main.hs +++ b/eo-phi-normalizer/app/Main.hs @@ -98,6 +98,7 @@ data CLI'RewritePhi = CLI'RewritePhi , rulesPath :: Maybe String , outputFile :: Maybe String , single :: Bool + , singleLine :: Bool , json :: Bool , latex :: Bool , inputFile :: Maybe FilePath @@ -292,7 +293,10 @@ commandParser = json <- jsonSwitch latex <- latexSwitch outputFile <- outputFileOption - single <- switch (long "single" <> short 's' <> help "Output a single expression.") + let singleFlag :: String + singleFlag = "single" + single <- switch (long singleFlag <> short 's' <> help "Output a single expression.") + singleLine <- switch (long "single-line" <> short 'l' <> help [fmt|Output a single expression on a single line. Has effect only if the --{singleFlag} is enabled.|]) maxDepth <- let maxValue = 10 in option auto (long "max-depth" <> metavar.int <> value maxValue <> help [fmt|Maximum depth of rules application. Defaults to {maxValue}.|]) @@ -614,8 +618,10 @@ main = withUtf8 do . encodeToJSONString . printAsProgramOrAsObject $ logEntryLog (head (head uniqueResults)) - | single -> + | single -> do + let removeExtraSpaces = unwords . words logStrLn + . (if singleLine then removeExtraSpaces else id) . printAsProgramOrAsObject $ logEntryLog (head (head uniqueResults)) | json -> From b12970e3a63a54d94fe1e82ae9f2f638465568ea Mon Sep 17 00:00:00 2001 From: Danila Danko Date: Fri, 29 Nov 2024 17:19:22 +0300 Subject: [PATCH 2/3] feat(site): document the option combination `--single --single-line` --- site/docs/src/eo-phi-normalizer/rewrite.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/site/docs/src/eo-phi-normalizer/rewrite.md b/site/docs/src/eo-phi-normalizer/rewrite.md index 921416b9..2db01e77 100644 --- a/site/docs/src/eo-phi-normalizer/rewrite.md +++ b/site/docs/src/eo-phi-normalizer/rewrite.md @@ -212,6 +212,16 @@ eo-phi-normalizer rewrite --single --rules ./eo-phi-normalizer/test/eo/phi/rules } ``` +### `--single --single-line` + +```$ as console +eo-phi-normalizer rewrite --single --single-line --rules ./eo-phi-normalizer/test/eo/phi/rules/yegor.yaml celsius.phi +``` + +```console +{ ⟦ c ↦ Φ.org.eolang.float ( as-bytes ↦ Φ.org.eolang.bytes ( Δ ⤍ 40-39-00-00-00-00-00-00 ) ), result ↦ ξ.c.times ( x ↦ ⟦ Δ ⤍ 3F-FC-CC-CC-CC-CC-CC-CD ⟧ ) .plus ( x ↦ ⟦ Δ ⤍ 40-40-00-00-00-00-00-00 ⟧ ), λ ⤍ Package ⟧ } +``` + ### `--single` `--json` ```$ as console From 10c1adbabc818d6e5c994fe238057ce6f37bf46e Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Fri, 29 Nov 2024 14:27:10 +0000 Subject: [PATCH 3/3] Update Markdown files --- site/docs/src/eo-phi-normalizer/rewrite.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/site/docs/src/eo-phi-normalizer/rewrite.md b/site/docs/src/eo-phi-normalizer/rewrite.md index 2db01e77..6825a1ce 100644 --- a/site/docs/src/eo-phi-normalizer/rewrite.md +++ b/site/docs/src/eo-phi-normalizer/rewrite.md @@ -23,8 +23,9 @@ eo-phi-normalizer rewrite --help ```console Usage: eo-phi-normalizer rewrite [-r|--rules FILE] [-c|--chain] [-j|--json] [--tex] [-o|--output-file FILE] [-s|--single] - [--max-depth INT] [--max-growth-factor INT] - [FILE] [-d|--dependency-file FILE] + [-l|--single-line] [--max-depth INT] + [--max-growth-factor INT] [FILE] + [-d|--dependency-file FILE] Rewrite a PHI program. @@ -37,6 +38,8 @@ Available options: -o,--output-file FILE Output to FILE. When this option is not specified, output to stdout. -s,--single Output a single expression. + -l,--single-line Output a single expression on a single line. Has + effect only if the --single is enabled. --max-depth INT Maximum depth of rules application. Defaults to 10. --max-growth-factor INT The factor by which to allow the input term to grow before stopping. Defaults to 10.