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

openscad quasiquote #480

Open
aavogt opened this issue Jan 20, 2024 · 2 comments
Open

openscad quasiquote #480

aavogt opened this issue Jan 20, 2024 · 2 comments

Comments

@aavogt
Copy link

aavogt commented Jan 20, 2024

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?
@ovitus
Copy link

ovitus commented Aug 25, 2024

Second this. How can this be done via Haskell?

@aavogt
Copy link
Author

aavogt commented Aug 25, 2024

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants