MCPcopy Index your code
hub / github.com/borgo-lang/borgo

github.com/borgo-lang/borgo @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
629 symbols 2,022 edges 22 files 46 documented · 7%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

The Borgo Programming Language

Borgo sits between Go and Rust


build

I want a language for writing applications that is more expressive than Go but less complex than Rust.

Go is simple and straightforward, but I often wish it offered more type safety. Rust is very nice to work with (at least for single threaded code) but it's too broad and complex, sometimes painfully so.

Borgo is a new language that transpiles to Go. It's fully compatible with existing Go packages.

Borgo syntax is similar to Rust, with optional semi-colons.

Tutorial

Check out the online playground for a tour of the language.

You can also take a look at test files for working Borgo code:

Features

Algebraic data types and pattern matching

use fmt

enum NetworkState {
    Loading,
    Failed(int),
    Success(string),
}

let msg = match state {
    NetworkState.Loading => "still loading",
    NetworkState.Failed(code) => fmt.Sprintf("Got error code: %d", code),
    NetworkState.Success(res) => res,
}

Option<T> instead of nil

// import packages from Go stdlib
use fmt
use os

let key = os.LookupEnv("HOME")

match key {
    Some(s) => fmt.Println("home dir:", s),
    None => fmt.Println("Not found in env"),
}

Result<T, E> instead of multiple return values

use fmt
use net.http

fn makeRequest() -> Result<int, error> {
    let request = http.Get("http://example.com")

    match request {
        Ok(resp) => Ok(resp.StatusCode),
        Err(err) => Err(fmt.Errorf("failed http request %w", err))
    }
}

Error handling with ? operator

use fmt
use io
use os

fn copyFile(src: string, dst: string) -> Result<(), error> {
    let stat = os.Stat(src)?

    if !stat.Mode().IsRegular() {
        return Err(fmt.Errorf("%s is not a regular file", src))
    }

    let source = os.Open(src)?
    defer source.Close()

    let destination = os.Create(dst)?
    defer destination.Close()

    // ignore number of bytes copied
    let _ = io.Copy(destination, source)?

    Ok(())
}

Guessing game example

Small game from the Rust book, implemented in Borgo.

Things to note:

  • import packages from Go stdlib
  • strconv.Atoi returns an Option<int>
  • Reader.ReadString returns a Result<string, error> (which can be unwrapped)
use bufio
use fmt
use math.rand
use os
use strconv
use strings

fn main() {
    let reader = bufio.NewReader(os.Stdin)

    let secret = rand.Intn(100) + 1

    loop {
        fmt.Println("Please input your guess.")

        let text = reader.ReadString('\n').Unwrap()
        let text = strings.TrimSpace(text)

        let guess = match strconv.Atoi(text) {
            Ok(n) => n,
            Err(_) => continue,
        }

        fmt.Println("You guessed: ", guess)

        if guess < secret {
            fmt.Println("Too small!")
        } else if guess > secret {
            fmt.Println("Too big!")
        } else {
            fmt.Println("Correct!")
            break
        }
    }
}

Running locally

Borgo is written in Rust, so you'll need cargo.

To compile all .brg files in the current folder:

$ cargo run -- build

The compiler will generate .go files, which you can run as normal:

# generate a go.mod file if needed
# $ go mod init foo
$ go run .

Extension points exported contracts — how you extend this code

FileSystem (Interface)
(no doc) [3 implementers]
compiler/src/fs.rs
Type (Interface)
(no doc) [2 implementers]
importer/importer.go
NoEmbedded (Interface)
(no doc)
importer/testpkg/testpkg.go
Foo (Interface)
(no doc)
importer/testpkg/testpkg.go

Core symbols most depended-on inside this repo

emit
called by 94
compiler/src/codegen.rs
next
called by 71
compiler/src/parser.rs
fresh_ty_var
called by 50
compiler/src/infer.rs
make_span
called by 47
compiler/src/parser.rs
expect
called by 46
compiler/src/parser.rs
add_constraint
called by 46
compiler/src/infer.rs
substitute
called by 43
compiler/src/infer.rs
emitter
called by 42
compiler/src/codegen.rs

Shape

Method 403
Function 117
Class 55
Enum 32
Struct 15
Interface 4
TypeAlias 3

Languages

Rust82%
Go12%
TypeScript6%

Modules by API surface

compiler/src/parser.rs103 symbols
compiler/src/codegen.rs97 symbols
compiler/src/infer.rs93 symbols
compiler/src/ast.rs60 symbols
importer/importer.go48 symbols
compiler/src/type_.rs43 symbols
compiler/src/lexer.rs39 symbols
compiler/src/global_state.rs32 symbols
importer/testpkg/testpkg.go25 symbols
compiler/test/runner.ts25 symbols
compiler/src/exhaustive.rs24 symbols
playground/wasm-index.js8 symbols

For agents

$ claude mcp add borgo \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact