https://github.com/marinasundstrom/raven
A modern programming language for .NET - Compiler inspired by the .NET Roslyn compiler architecture.
https://github.com/marinasundstrom/raven
compiler compiler-construction csharp dotnet roslyn
Last synced: 5 months ago
JSON representation
A modern programming language for .NET - Compiler inspired by the .NET Roslyn compiler architecture.
- Host: GitHub
- URL: https://github.com/marinasundstrom/raven
- Owner: marinasundstrom
- License: mit
- Created: 2024-08-14T08:41:34.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2026-01-11T19:47:32.000Z (5 months ago)
- Last Synced: 2026-01-11T20:32:06.927Z (5 months ago)
- Topics: compiler, compiler-construction, csharp, dotnet, roslyn
- Language: C#
- Homepage:
- Size: 6.25 MB
- Stars: 61
- Watchers: 2
- Forks: 1
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Agents: AGENTS.md
Awesome Lists containing this project
README
# Raven Programming Language
[](LICENSE)
[](docs/)
**Raven** is a modern programming language and experimental compiler inspired by the [.NET Roslyn](https://github.com/dotnet/roslyn) architecture.
β¨ **Key traits**:
- **Familiar yet fresh syntax** β looks like Swift, with ideas borrowed from Rust, F#, and C#
- **Targets the .NET runtime** β compiles directly to IL and integrates with the .NET ecosystem
- **Immutable, service-oriented design** β a compiler built as an API, following the "Compiler-as-a-Service" philosophy
Raven is primarily a **learning and exploration project**, aimed at:
- Understanding modern compiler construction
- Experimenting with language design
- Providing a clean API for syntax manipulation and analysis
## π° Language Overview
Raven is a general-purpose, expression-oriented language with an expression-first design that blends functional and imperative paradigms. Its type system supports union and literal types with flow-sensitive typing similar to TypeScript, and it uses `unit` instead of `void`. As a .NET language, Raven interops seamlessly with C#, even shipping a C# analyzer for type unions. The compiler follows the Roslyn "compiler-as-a-service" architecture.
### Example
```raven
import System.Console.*
import System.Collections.Generic.List
import System.Linq.*
alias LedgerEntry = (label: string, value: int)
func shape(values: List) -> List {
val result = List()
for each value in values {
val label = if value < 0 "debit" else "credit"
result.Add((label: label, value: value))
}
return result
}
func summarize(readings: List) -> string {
val shaped = shape(readings)
val total = shaped.Aggregate(0, (acc, entry) => acc + entry.value)
val verdict = if total > 0
"net positive"
else if total < 0
"net negative"
else
"balanced"
return $"processed ${shaped.Count()} items -> ${verdict} (${total})"
}
var ledger = List()
ledger.Add(25)
ledger.Add(-10)
ledger.Add(5)
ledger.Add(0)
WriteLine(summarize(ledger))
```
**Highlights**:
* Expression-first control flow and file-scope functions
* `val` vs `var` (immutable vs mutable) with tuple-shaped data
* Lambdas and LINQ interop against .NET collection types
* String interpolation with tuple element access
* Direct interop with .NET libraries
Read the full [Introduction](docs/introduction.md) for a more detailed overview.
---
## πͺΆ Why the Name "Raven"?
Ravens are remarkable birds, known for their intelligence and adaptability.
In Old Norse mythology, ravens held significant importance as messengers of Odin. His two ravens, **Huginn** ("thought") and **Muninn** ("memory/mind"), symbolized intellect and reflectionβqualities that align with the goals of this language.
The name reflects both the **mythological roots** and the **clever traits** of these birds.
Alternative names considered: Old Norse **"Hrafn"** or Danish **"Ravn."**
---
## π― Project Goals
- **Create a Programming Language** β build a language from the ground up, covering design and implementation.
- **Focus on Parsing & Semantics** β implement parsing, binding, and analysis as the backbone of compilation.
- **Serve as a Reference** β provide a well-documented example for compiler enthusiasts.
- **Pragmatic Scope** β aim for a practical subset of Roslyn-like features, not full parity.
---
## β¨ Syntax
See the pseudo-specification [here](/docs/lang/spec/language-specification.md).
More [samples](samples/).
---
## π§© API
* Compiler API reference: [docs/compiler/api](docs/compiler/api)
* Example usage: [Raven.Compiler project](src/Raven.Compiler/Program.cs)
---
## π Prerequisites
* [.NET SDK 9.0](https://dotnet.microsoft.com/)
* Optional: [DocFX](https://dotnet.github.io/docfx/) for docs
---
## π Quick Start
```bash
# Restore packages
dotnet restore
# Generate syntax nodes (run from the Syntax directory)
cd src/Raven.CodeAnalysis/Syntax
dotnet run --project ../../../tools/NodeGenerator # add `-- -f` to force regeneration
cd ../../..
# Build the compiler, tests, and Raven.Core (the Option/Result standard library built with ravc)
dotnet build Raven.sln
dotnet test
```
### Run the compiler
Command:
```bash
dotnet run --project src/Raven.Compiler -- -o
```
Options:
- `--framework ` β target framework
- `--refs ` β additional metadata reference (repeatable)
- `--raven-core ` β reference a specific `Raven.Core.dll`
- `--emit-core-types-only` β embed Raven core shims instead of using `Raven.Core.dll`
- `-o ` β output assembly path
- `-s` β display the syntax tree (single file only)
- `-d [plain|pretty[:no-diagnostics]]` β dump syntax (`plain` for raw text, `pretty` for highlighted syntax; append `:no-diagnostics` to skip underlines, single file only)
- `--highlight` β display diagnostics with highlighted source snippets and severity-coloured underlines (covers
compiler, analyzer, and emit diagnostics)
- `-r` β print the raw source (single file only)
- `-b` β print the binder tree (single file only)
- `-bt` β print the binder and bound tree (single file only)
- `--symbols [list|hierarchy]` β inspect source symbols (`list` dumps properties, `hierarchy` prints the tree)
- `-h`, `--help` β show help
`ravc` now ships with and references `Raven.Core.dll` by default. The library is copied next to `ravc` during build, and any compilation also copies it to the output directory of the produced assembly. Use `--raven-core` to point to a different build of Raven.Core, or `--emit-core-types-only` to embed the shimmed core types instead of referencing the DLL.
Creating a `.debug/` directory in the current or parent folder causes the
compiler to emit per-file dumps (syntax tree, highlighted syntax, raw source,
bound tree, and binder tree) into that directory. The debug options above will additionally
write to the console when compiling a single file.
> β οΈ **When the arguments are omitted**, there is a hardcoded input file, and a hardcoded output file path (`test.dll`).
### Run the editor
```bash
dotnet run --project src/Raven.Editor --
```
When a file path is supplied, the editor opens the file and displays its name in the window title.
---
## π Repository Structure
```
src/
Raven.CodeAnalysis/ # Compiler core: syntax, binder, semantic model, code gen
Raven.Compiler/ # Command-line compiler
Raven.CodeAnalysis.Testing/ # Diagnostic test helpers
TypeUnionAnalyzer/ # Analyzer for C# type unions
TestDep/ # Auxiliary test project
test/ # Unit tests
samples/ # Example Raven programs and CLI demos
tools/
NodeGenerator/ # Generates syntax node code from Model.xml
Generator/ # Shared Roslyn generator framework
docs/ # Language spec & design docs
```
---
## π§ Development Notes
* The `RunNodeGenerator` target in `Raven.CodeAnalysis.csproj` runs automatically, but if generated files are missing, run the command manually.
* Generated files reside in `Syntax/generated/` and `Syntax/InternalSyntax/generated/` β **do not edit by hand**.
* Always run `dotnet build` and `dotnet test` before committing.
---
## π€ Contributing
Contributions are welcome!
See [CONTRIBUTING.md](CONTRIBUTING.md) for coding standards, git conventions, and workflow.
---
## π Documentation
* Full documentation: [docs/](docs/)
* Unit tests for the language: [Raven.CodeAnalysis.Tests](test/Raven.CodeAnalysis.Tests)
---
π‘ *Raven is a playground for exploring compilers and language design β your ideas and contributions can directly shape its evolution!*