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

Generalize the output customization. #15

Open
astynax opened this issue Sep 1, 2021 · 4 comments
Open

Generalize the output customization. #15

astynax opened this issue Sep 1, 2021 · 4 comments

Comments

@astynax
Copy link
Owner

astynax commented Sep 1, 2021

For now there is only a couple of preprocessors for some genenerators. But it will be nice to have a way to customize the output: pretty-printing, size of indentation. It can be a mini-language like "key=val,key=val|" that will prepend the template itself.

@uhbif19
Copy link
Contributor

uhbif19 commented Aug 15, 2022

I would do it by writing generic prefix-parsing function, like this (not sure about names now):

data FilesystemKind = Python | Haskell
class RendererKindRead FilesystemKind where
     prefix Python  = "py"
     prefix Haskell = "hs"

>>> parsePrefix @FilesystemKind "hs,indent=4,other_param=something|sometemplate"
Config {
     rendererKind = Haskell
     indent = 4
     other_param = Something
 }

@astynax
Copy link
Owner Author

astynax commented Aug 16, 2022

I don't thing that any classes are strictly necessary here. Will records of functions be just enough? I can see something like this:

type Args = [(String, String)]

data Preprocessor a where
  Preprocessor :: forall args =>
    { pParseArgs :: Args -> Maybe args
    , pGetTransformation :: args -> Transformation a
    } -> Preprocessor a
  
fooPreprocessors :: [(String, Preprocessor Foo)]
fooPreprocessors =
  [ ("hs", haskellify)
  ...]

data HaskellifyArgs = HaskellyfyArgs
  { haIndent :: Int
  , ... }

haskellify = Preprocessor {..}
  where
    pParseArgs args = do
      indent <- lookup "indent" args >>= readMaybe
      ...
    pMakeTransformation HaskellifyArgs{..} = ...

@uhbif19
Copy link
Contributor

uhbif19 commented Aug 16, 2022

@astynax Your solution presumes that each prefix/preprocessor has its own config, while mine uses the same config for every prefix. So I think it is worth to discuss which customization options you wanna see and check if they do differ for different prefixes.

Also I do not understand, why using classes are bad. My class uses just the same idea as Read.

@astynax
Copy link
Owner Author

astynax commented Aug 17, 2022

Each preprocessor should have its own config. This means that your interface-like class will grow.

Also, I have thought about the external preprocessors like pandoc filters. My variant can be easily extended with external filter support: one can just add a new value of Preprocessor type. Data kind based solution will need a special ("Other") constructor for that, and IMHO such "backdoors" don't look nice.

There is a case that can make class-bases solution viable: we may decide to link proprocessors not only to the inputs but also for the outputs. MPTC here will work as multiple dispatching:

class Preprocess (name :: KnownSymbol) tree out where
   ...
   
instance Preprocess "hs" FileTree Tree where
  ...

But even it that case it may be simpler to have just a Map of Preprocessors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants