Skip to content

openscad quasiquote #480

Open
Open

Description

@aavogt

I like circle($fn=6), but I don't see it in the haskell api. While it is possible to encode such optional arguments in haskell, I think a quasiquoter would be better.

hex1 d = [scad| circle(d, $fn=6) |] -- too light
hex2 d = [scad2d| circle($$d, $fn=6) |] -- too heavy
hex3 d = [scad| circle($(d), $fn=6) |] -- just right?

Activity

  1. ovitus commented on Aug 25, 2024

    @ovitus

    Second this. How can this be done via Haskell?

  2. aavogt commented on Aug 25, 2024

    @aavogt
    Author

    https://github.com/Haskell-Things/ImplicitCAD/blob/master/programs/extopenscad.hs#L168 shows how it parses scad/runs scad files. SymbolicObj3 contains functions, so the QuasiQuoter probably has to run the parser at runtime because there's no Lift instance, ie. it probably will look like:

    -- | QuasiQuoter for extopenscad expressions
    -- 
    -- > hex ::  Double -> IO SymbolicObj2
    -- > hex d = [scad2d| circle($(d), $fn=6) |]
    scad2d = QuasiQuoter { quoteExp = \ str -> do
      checkSyntax str -- optional: probably calls runOpenscad
      [| (\(_,obj2s,_obj3s,_) -> obj2s) <$> runOpenscad scadOpts _ $(antiquote str) |] }
    
    -- | > antiquote "ab $(c) def" == [| "ab " ++ show c ++ " def" |]
    antiquote :: String -> ExpQ
    antiquote = _

    But maybe the result doesn't have to be in IO.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions