-
Fluent DSL Generator
-
Supporting lauguages are:
- Haskell
- C++
- Scala
Clone this repository and type stack install.
> git clone https://github.com/csg-tokyo/typelevelLR
> cd typelevelLR
> stack install
You can also use Docker:
> git clone https://github.com/csg-tokyo/typelevelLR
> cd typelevelLR
> docker build -t csg-tokyo/typelevellr:latest .
> docker run -v $(pwd):/workdir -it csg-tokyo/typelevellr:latest
- Define your syntax
> nano hello.syntax
syntax helloDSL (Start) {
simpleHello : Start -> "hello"
helloWithName : Start -> "hello" Name
nameString : Name -> "name(String)"
}
- Generate Fluent DSL Library
> typelevelLR --haskell
- Import Fluent DSL Library
> nano MyApp.hs
import HelloDSL
main :: IO ()
main = print $ begin |> hello |> name "ymzk" |> end
> runghc MyApp.hs
HelloWithName (NameString "ymzk")
- Define semantics
> nano HelloDSLSemantics.hs
module HelloDSLSemantics where
import HelloDSL
runHelloDSL :: Start -> IO ()
runHelloDSL (SimpleHello name) = putStrLn "Hello."
runHelloDSL (HelloWithName (NameString name)) = putStrLn ("Hello, " ++ name ++ "!!")
- Run it
> nano MyApp.hs
module MyApp where
import HelloDSL
import HelloDSLSemantics
main :: IO ()
main = runHelloDSL $ begin |> hello |> name "ymzk" |> end
> runghc MyApp.hs
Hello, ymzk!!
Will be written.