-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from julianpeeters/dev
Setup mdoc and github actions
- Loading branch information
Showing
11 changed files
with
294 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
name: Scala CI | ||
|
||
on: | ||
push: | ||
branches: [ main ] | ||
pull_request: | ||
branches: [ main ] | ||
|
||
jobs: | ||
build: | ||
name: Build and Test | ||
strategy: | ||
matrix: | ||
os: [ubuntu-latest, macos-latest] | ||
scala: [3.3.1] | ||
java: ['11', '17'] | ||
runs-on: ${{ matrix.os }} | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Set up Java | ||
uses: actions/setup-java@v3.13.0 | ||
with: | ||
distribution: 'temurin' | ||
java-version: ${{ matrix.java }} | ||
- name: Run tests | ||
run: sbt ++${{ matrix.scala }} test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
name: Release | ||
|
||
on: | ||
push: | ||
tags: ["*"] | ||
jobs: | ||
publish: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
- uses: actions/setup-java@v3.13.0 | ||
with: | ||
distribution: temurin | ||
java-version: 8 | ||
cache: sbt | ||
- run: sbt ci-release | ||
env: | ||
PGP_PASSPHRASE: ${{ secrets.PGP_PASSPHRASE }} | ||
PGP_SECRET: ${{ secrets.PGP_SECRET }} | ||
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }} | ||
SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,106 @@ | ||
# dc10 | ||
A ***D**efinitional* ***C**ompiler* for compiling models of programs into programs. | ||
- `dc10-compile`: Evaluate metaprograms into code strings | ||
- `dc10-io`: Evaluate metaprograms into source files | ||
- `dc10-scala`: AST and dsl for constructing metaprograms | ||
A ***D**efinitional* ***C**ompiler* for generating Scala code. | ||
- [`dc10-core`](#dc10-core): Core models and abstractions for defining a language implementation | ||
- [`dc10-io`](#dc10-io): Fs2 integration for evaluating metaprograms into source files | ||
- [`dc10-scala`](#dc10-scala): AST and dsl for defining and rendering Scala programs | ||
|
||
### Installation | ||
### Getting Started | ||
- Libraries for Scala 3 (JVM only) | ||
- Generates code for Scala 3 | ||
|
||
#### Add the dependencies, e.g.: | ||
``` | ||
"com.julianpeeters" %% "dc10-compile" % "0.1.0-SNAPSHOT" | ||
```scala | ||
"com.julianpeeters" %% "dc10-<module>" % "0.0.0" | ||
``` | ||
|
||
### Usage | ||
|
||
#### `dc10-scala` | ||
### `dc10-core` | ||
The `compile` package provides abstractions for defining and rendering code: | ||
|
||
<details><summary>Compiler</summary> | ||
|
||
``` | ||
package dc10.compile | ||
trait Compiler[ | ||
F[_], // Error functor in ctx | ||
G[_], // Output unit, e.g., List, Id, etc. | ||
E, // Error type | ||
A, // Code level, representing symbols introduced into ctx | ||
B // File level, representing source files with path and ast | ||
]: | ||
type Ctx[_[_],_,_] // Monadic context, to build up ASTs and then compile them | ||
extension [C, D] (ast: Ctx[F, List[D], C]) | ||
def compile: F[List[D]] | ||
extension (res: F[G[A]]) | ||
def toString[V](using R: Renderer[V, E, G[A]]): String | ||
extension (res: F[G[A]]) | ||
def toStringOrError[V](using R: Renderer[V, E, G[A]]): F[String] | ||
extension (res: F[G[B]]) | ||
def toVirtualFile[V](using R: Renderer[V, E, G[A]]): F[List[VirtualFile]] | ||
``` | ||
</details> | ||
|
||
<details><summary>Renderer</summary> | ||
|
||
``` | ||
package dc10.compile | ||
trait Renderer[V, E, A]: | ||
def render(input: A): String | ||
def renderErrors(errors: List[E]): String | ||
def version: V | ||
``` | ||
</details> | ||
|
||
Use the dsl to define some Scala code: | ||
<details><summary>VirtualFile</summary> | ||
|
||
``` | ||
package dc10.compile | ||
import java.nio.file.Path | ||
case class VirtualFile(path: Path, contents: String) | ||
``` | ||
</details> | ||
|
||
### `dc10-io` | ||
The `io` package provides extension methods to write files using fs2: | ||
|
||
```scala | ||
_.toFile["scala-3.3.1"] | ||
``` | ||
|
||
### `dc10-scala` | ||
|
||
Use the dsl to define Scala code: | ||
|
||
```scala | ||
import cats.data.StateT | ||
import dc10.scala.ast.Statement | ||
import dc10.scala.dsl.{*, given} | ||
import dc10.scala.error.ErrorF | ||
import scala.language.implicitConversions // for literals, e.g. "hello, world" | ||
|
||
val snippet: StateT[ErrorF, List[Statement], Unit] = | ||
for | ||
s <- VAL("str", STRING, "hello, world") | ||
_ <- VAL("msg", STRING, s) | ||
yield () | ||
``` | ||
|
||
Use the compiler impl to check and render code to `String` or `VirtualFile`: | ||
|
||
```scala | ||
import dc10.scala.compiler.{compile, toString} | ||
import dc10.scala.version.`3.3.1` | ||
|
||
val result: String = snippet.compile.toString["scala-3.3.1"] | ||
// result: String = """val str: String = "hello, world" | ||
// val msg: String = str""" | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
# dc10 | ||
A ***D**efinitional* ***C**ompiler* for generating Scala code. | ||
- [`dc10-core`](#dc10-core): Core models and abstractions for defining a language implementation | ||
- [`dc10-io`](#dc10-io): Fs2 integration for evaluating metaprograms into source files | ||
- [`dc10-scala`](#dc10-scala): AST and dsl for defining and rendering Scala programs | ||
|
||
### Getting Started | ||
- Libraries for Scala @SCALA@ (JVM only) | ||
- Generates code for Scala @SCALA@ | ||
|
||
```scala | ||
"com.julianpeeters" %% "dc10-<module>" % "@VERSION@" | ||
``` | ||
|
||
### Usage | ||
|
||
### `dc10-core` | ||
The `compile` package provides abstractions for defining and rendering code: | ||
|
||
<details><summary>Compiler</summary> | ||
|
||
``` | ||
package dc10.compile | ||
trait Compiler[ | ||
F[_], // Error functor in ctx | ||
G[_], // Output unit, e.g., List, Id, etc. | ||
E, // Error type | ||
A, // Code level, representing symbols introduced into ctx | ||
B // File level, representing source files with path and ast | ||
]: | ||
type Ctx[_[_],_,_] // Monadic context, to build up ASTs and then compile them | ||
extension [C, D] (ast: Ctx[F, List[D], C]) | ||
def compile: F[List[D]] | ||
extension (res: F[G[A]]) | ||
def toString[V](using R: Renderer[V, E, G[A]]): String | ||
extension (res: F[G[A]]) | ||
def toStringOrError[V](using R: Renderer[V, E, G[A]]): F[String] | ||
extension (res: F[G[B]]) | ||
def toVirtualFile[V](using R: Renderer[V, E, G[A]]): F[List[VirtualFile]] | ||
``` | ||
</details> | ||
|
||
<details><summary>Renderer</summary> | ||
|
||
``` | ||
package dc10.compile | ||
trait Renderer[V, E, A]: | ||
def render(input: A): String | ||
def renderErrors(errors: List[E]): String | ||
def version: V | ||
``` | ||
</details> | ||
|
||
<details><summary>VirtualFile</summary> | ||
|
||
``` | ||
package dc10.compile | ||
import java.nio.file.Path | ||
case class VirtualFile(path: Path, contents: String) | ||
``` | ||
</details> | ||
|
||
### `dc10-io` | ||
The `io` package provides extension methods to write files using fs2: | ||
|
||
```scala | ||
_.toFile["scala-3.3.1"] | ||
``` | ||
|
||
### `dc10-scala` | ||
|
||
Use the dsl to define Scala code: | ||
|
||
```scala mdoc:silent | ||
import cats.data.StateT | ||
import dc10.scala.ast.Statement | ||
import dc10.scala.dsl.{*, given} | ||
import dc10.scala.error.ErrorF | ||
import scala.language.implicitConversions // for literals, e.g. "hello, world" | ||
|
||
val snippet: StateT[ErrorF, List[Statement], Unit] = | ||
for | ||
s <- VAL("str", STRING, "hello, world") | ||
_ <- VAL("msg", STRING, s) | ||
yield () | ||
``` | ||
|
||
Use the compiler impl to check and render code to `String` or `VirtualFile`: | ||
|
||
```scala mdoc | ||
import dc10.scala.compiler.{compile, toString} | ||
import dc10.scala.version.`3.3.1` | ||
|
||
val result: String = snippet.compile.toString["scala-3.3.1"] | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.