mirror of
https://github.com/anoma/juvix.git
synced 2025-01-07 16:22:14 +03:00
2d36a65324
# Changes The main goal of this pr is to remove the `--target` flag for `juvix compile` and use subcommands instead. The targets that are relevant to normal users are found in `juvix compile --help`. Targets that are relevant only to developers are found in `juvix dev compile --help`. Below I list some of the changes in more detail. ## Compile targets for user-facing languages - `juvix compile native` - `juvix compile wasi`. I wasn't sure how to call this: `wasm`, `wasm32-wasi`, etc. In the end I thought `wasi` was short and accurate, but we can change it. - `juvix compile vampir` - `juvix compile anoma` - `juvix compile cairo` ## *New* compile targets for internal languages See `juvix dev compile --help`. 1. `dev compile core` has the same behaviour as `dev core from-concrete`. The `dev core from-concrete` is redundant at the moment. 2. `dev compile tree` compiles to Tree and prints the InfoTable to the output file wihout any additional checks. 3. `dev compile reg` compiles to Reg and prints the InfoTable to the output file wihout any additional checks. 4. `dev compile asm` compiles to Asm and prints the InfoTable to the output file wihout any additional checks. 5. 4. `dev compile casm` compiles to Asm and prints the Result to the output file wihout any additional checks. TODO: should the Result be printed or something else? At the moment the Result lacks a pretty instance. 6. ## Optional input file 1. The input file for commands that expect a .juvix file as input is now optional. If the argument is ommited, he main file given in the package.yaml will be used. This applies to the following commands: 1. `juvix compile [native|wasi|geb|vampir|anoma|cairo]` 8. `juvix dev compile [core|reg|tree|casm|asm]` 1. `juvix html` 3. `juvix markdown`. 4. `juvix dev internal [typecheck|pretty]`. 5. `juvix dev [parse|scope]` 7. `juvix compile [native|wasi|geb|vampir|anoma|cairo]` 9. note that `juvix format` has not changed its behaviour. ## Refactor some C-like compiler flags Both `juvix compile native` and `juvix compile wasi` support `--only-c` (`-C`), `--only-preprocess` (`-E`), `--only-assemble` (`-S`). I propose to deviate from the `gcc` style and instead use a flag with a single argument: - `--cstage [source|preprocess|assembly|exec(default)]`. I'm open to suggestions. For now, I've kept the legacy flags but marked them as deprecated in the help message. ## Remove code duplication I've tried to reduce code duplication. This is sometimes in tension with code readability so I've tried to find a good balance. I've tried to make it so we don't have to jump to many different files to understand what a single command is doing. I'm sure there is still room for improvement. ## Other refactors I've implemented other small refactors that I considered improved the quality of the code. ## TODO/Future work We should refactor commands (under `compile dev`) which still use `module Commands.Extra.Compile` and remove it.
142 lines
3.9 KiB
Haskell
142 lines
3.9 KiB
Haskell
module Commands.Html.Options where
|
|
|
|
import CommonOptions
|
|
import Data.List.NonEmpty qualified as NonEmpty
|
|
import Juvix.Compiler.Backend.Html.Data.Options hiding (HtmlOptions)
|
|
|
|
data HtmlOptions = HtmlOptions
|
|
{ _htmlNonRecursive :: Bool,
|
|
_htmlOnlySource :: Bool,
|
|
_htmlOnlyCode :: Bool,
|
|
_htmlTheme :: Theme,
|
|
_htmlOutputDir :: AppPath Dir,
|
|
_htmlInputFile :: Maybe (AppPath File),
|
|
_htmlNoFooter :: Bool,
|
|
_htmlFolderStructure :: Bool,
|
|
_htmlNoPath :: Bool,
|
|
_htmlExt :: Text,
|
|
_htmlStripPrefix :: Text,
|
|
_htmlAssetsPrefix :: Text,
|
|
_htmlUrlPrefix :: Text,
|
|
_htmlIdPrefix :: Text,
|
|
_htmlOpen :: Bool
|
|
}
|
|
deriving stock (Data)
|
|
|
|
makeLenses ''HtmlOptions
|
|
|
|
parseHtml :: Parser HtmlOptions
|
|
parseHtml = do
|
|
_htmlNonRecursive <-
|
|
switch
|
|
( long "non-recursive"
|
|
<> help "Do not process imported modules recursively"
|
|
)
|
|
_htmlOnlySource <-
|
|
switch
|
|
( long "only-source"
|
|
<> help "Generate only Html for the source code with syntax highlighting"
|
|
)
|
|
_htmlOnlyCode <-
|
|
switch
|
|
( long "only-code"
|
|
<> help "If --only-source is enabled, only generate the code without the header and footer"
|
|
)
|
|
_htmlTheme <-
|
|
option
|
|
(eitherReader parseTheme)
|
|
( long "theme"
|
|
<> metavar "THEME"
|
|
<> value Ayu
|
|
<> showDefault
|
|
<> help ("Theme for syntax highlighting. " <> availableStr)
|
|
<> completeWith (map show allThemes)
|
|
)
|
|
_htmlOutputDir <-
|
|
parseGenericOutputDir
|
|
( value "html"
|
|
<> showDefault
|
|
<> help "Html output directory"
|
|
<> action "directory"
|
|
)
|
|
_htmlNoFooter <-
|
|
switch
|
|
( long "no-footer"
|
|
<> help "Remove HTML Juvix footer"
|
|
)
|
|
_htmlNoPath <-
|
|
switch
|
|
( long "no-path"
|
|
<> help "Remove the path from all hyperlinks"
|
|
)
|
|
_htmlExt <-
|
|
strOption
|
|
( value ".html"
|
|
<> long "ext"
|
|
<> showDefault
|
|
<> help "File extension for the generated HTML files"
|
|
)
|
|
_htmlStripPrefix <-
|
|
strOption
|
|
( value ""
|
|
<> long "strip-prefix"
|
|
<> showDefault
|
|
<> help "Strip the given prefix from the hyperlinks. This has no effect if --no-path is enabled. It has precedence over --prefix-url"
|
|
)
|
|
_htmlFolderStructure <-
|
|
switch
|
|
( long "folder-structure"
|
|
<> help "Generate HTML following the module's folder structure"
|
|
)
|
|
_htmlAssetsPrefix <-
|
|
strOption
|
|
( value ""
|
|
<> long "prefix-assets"
|
|
<> showDefault
|
|
<> help "Prefix used for assets's source path"
|
|
)
|
|
_htmlUrlPrefix <-
|
|
strOption
|
|
( value ""
|
|
<> long "prefix-url"
|
|
<> showDefault
|
|
<> help "Prefix used for inner Juvix hyperlinks"
|
|
)
|
|
_htmlIdPrefix <-
|
|
strOption
|
|
( value ""
|
|
<> long "prefix-id"
|
|
<> showDefault
|
|
<> help "Prefix used for HTML element IDs"
|
|
)
|
|
_htmlOpen <-
|
|
switch
|
|
( long "open"
|
|
<> help "Open the documentation after generating it"
|
|
)
|
|
_htmlInputFile <- optional (parseInputFiles (NonEmpty.fromList [FileExtJuvix, FileExtJuvixMarkdown]))
|
|
pure HtmlOptions {..}
|
|
where
|
|
allThemes :: [Theme]
|
|
allThemes = allElements
|
|
|
|
availableStr :: String
|
|
availableStr =
|
|
dotSep
|
|
[ showCategory (light, filter ((== light) . themeLight) allThemes)
|
|
| light <- allElements
|
|
]
|
|
where
|
|
showCategory :: (ThemeLight, [Theme]) -> String
|
|
showCategory (light, ts) = show light <> " themes: " <> commaSep (map show ts)
|
|
commaSep = intercalate ", "
|
|
dotSep = intercalate ". "
|
|
|
|
parseTheme :: String -> Either String Theme
|
|
parseTheme s = case lookup (map toLower s) themes of
|
|
Just t -> return t
|
|
Nothing -> Left $ "unrecognised theme: " <> s
|
|
where
|
|
themes :: [(String, Theme)]
|
|
themes = [(show theme, theme) | theme <- allThemes]
|