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

580 lets add oneline option to the rewrite command #588

Merged
merged 3 commits into from
Nov 29, 2024
Merged
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
10 changes: 8 additions & 2 deletions eo-phi-normalizer/app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}.|])
Expand Down Expand Up @@ -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 ->
Expand Down
17 changes: 15 additions & 2 deletions site/docs/src/eo-phi-normalizer/rewrite.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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.
Expand Down Expand Up @@ -212,6 +215,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
Expand Down