npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

brett-compiler

v1.0.31

Published

Een compiler voor de .Brett taal

Downloads

1,831

Readme

Brett Language Server & Compiler

Naam student: Brett Deswert
Vak: Programmeren 3 – 2025–2026

Dit project bevat een compiler en een VS Code Language Server Extension voor de zelf ontworpen programmeertaal Brett.

De focus ligt op:

  • Diagnostics (syntax & semantiek)
  • Code completion
  • Een duidelijke grammatica (EBNF)
  • Integratie met VS Code via LSP

Projectstructuur

Compiler Project

Compiler/
├─ .idea/
├─ dist/
├─ node_modules/
├─ pictures/
├─ src/
├─ test/
├─ .gitignore
├─ antlr-4.13.2-complete.jar
├─ generate-compiler.js
├─ generate-compiler.ps1
├─ package.json
├─ package-lock.json
├─ README.md
└─ vite.config.js

Extension Project

EXTENSION/
├─ .vscode/
├─ client/
│  ├─ node_modules/
│  ├─ out/
│  ├─ src/
│  │  └─ test/
│  │     └─ extension.ts
│  ├─ testFixture/
│  ├─ package-lock.json
│  ├─ package.json
│  ├─ tsconfig.json
│  └─ tsconfig.tsbuildinfo
├─ scripts/
│  └─ e2e.sh
├─ server/
│  ├─ node_modules/
│  ├─ out/
│  └─ src/
│     └─ server.ts
├─ .gitignore
├─ eslint.config.mjs
├─ package-lock.json
├─ package.json
├─ tsconfig.json
├─ tsconfig.tsbuildinfo
├─ README.md
└─  tsconfig.json

Build & Run

Compiler builden

cd Compiler
npm ci --include=dev
npm run build

Dit voert automatisch uit:

  • generatie van de parser via ANTLR (antlrci)
  • build van de compiler naar Compiler/dist/

De gegenereerde code wordt gebruikt door de SemanticAnalyserVisitor.


Tests uitvoeren (compiler)

cd Compiler
npm ci --include=dev
npm run antlrci
npm test

VS Code extension starten

cd extension
npm install
npm run compile

De package.json haalt de package op via npm, en gebruikt de geuploade package.

De package wordt bij elke build automatisch naar npm geupload.

Dit is een link naar de npm package: https://www.npmjs.com/package/brett-compiler

Start daarna de extension via Run Extension in VS Code.


Voorbeeldbroncode (alle ondersteunde syntax)

let count: number = 10;
const isActive: bool = true;
let message: string = "Hallo Brett";

def add(a: number, b: number): number {
    return a + b;
}

let result = add(5, 7);

if (result > 10) {
    message = "Groter dan tien";
} else {
    message = "Tien of kleiner";
}

while (count > 0) {
    count--;
}

for (let i: number = 0; i < 5; i = i + 1) {
    result = result + i;
}

do {
    count++;
} while (count < 3);

switch {
    case result == 0 => {
        message = "Nul";
    }
    default => {
        message = "Niet nul";
    }
}

let numbers = [1, 2, 3];
let person = {
    name: "Alice",
    age: 30
};

try {
    let value = numbers[10];
} catch (err: any) {
    message = "Fout opgetreden";
} finally {
    message = "Klaar";
}

Diagnostics

Syntax diagnostics (Error)

  • Ontbrekende ;
  • Foutieve blokstructuur
  • Ongeldige expressies

Worden weergegeven als Error diagnostics.


Semantische diagnostics (Error)

  • Typefouten
    let x: number = "tekst";
  • Dubbele declaraties in dezelfde scope
  • Ongekende functies of variabelen

Semantische diagnostics (Warning)

  • Naamgevingsconventies
    let MyAge: number = 30;

Errors en warnings werken rond verschillende semantiek (types, scope, naamgeving).


Code Completion

Vorm 1: Keywords & identifiers

  • Variabelen
  • Functies
  • Parameters
  • Types
  • Keywords (let, const, def, return, if, while, …)

Vorm 2: Live Templates (Snippets)

  • if...else
  • def-func

Functies worden automatisch aangevuld met ().


Grammatica (EBNF)

program           = { statement } ;
block             = "{" { statement } "}" ;

statement         = variableDeclaration
                  | functionDeclaration
                  | ifStatement
                  | whileStatement
                  | forStatement
                  | switchStatement
                  | returnStatement
                  | expressionStatement
                  | block
                  | breakStatement
                  | continueStatement
                  | doWhileStatement
                  | tryCatchStatement ;

variableDeclaration
                  = "let" IDENTIFIER [ ":" type ] [ "=" expression ] ";"
                  | "const" IDENTIFIER ":" type "=" expression ";" ;

functionDeclaration
                  = "def" IDENTIFIER "(" [ parameterList ] ")" [ ":" type ] block ;

parameterList     = parameter { "," parameter } ;
parameter         = IDENTIFIER [ ":" type ] ;

ifStatement       = "if" "(" expression ")" block [ "else" block ] ;
whileStatement    = "while" "(" expression ")" block ;
doWhileStatement  = "do" block "while" "(" expression ")" ";" ;
forStatement      = "for" "(" [ variableDeclaration | expressionStatement ]
                    [ expression ] ";" [ expression ] ")" block ;

switchStatement   = "switch" "{" { switchCase } [ defaultCase ] "}" ;
switchCase        = "case" expression "=>" block ;
defaultCase       = "default" "=>" block ;

tryCatchStatement = "try" block "catch" "(" IDENTIFIER [ ":" type ] ")" block
                    [ "finally" block ] ;

returnStatement   = "return" [ expression ] ";" ;
breakStatement    = "break" ";" ;
continueStatement = "continue" ";" ;
expressionStatement = expression ";" ;

type              = baseType { "[]" } ;
baseType          = "string" | "number" | "bool" | "any" | "void" | IDENTIFIER ;

expression        = assignment ;
assignment        = [ IDENTIFIER "=" ] comparison ;
comparison        = term { ( "==" | "!=" | "<" | "<=" | ">" | ">=" ) term } ;
term              = factor { ( "+" | "-" ) factor } ;
factor            = unary { ( "*" | "/" ) unary } ;
unary             = ( "++" | "--" ) unary | postfix ;
postfix           = primary { "++" | "--" | "[" expression "]" | "." IDENTIFIER } ;

primary           = NUMBER
                  | STRING
                  | "true"
                  | "false"
                  | "nil"
                  | IDENTIFIER
                  | "(" expression ")"
                  | IDENTIFIER "(" [ argList ] ")"
                  | arrayLiteral
                  | objectLiteral
                  | "new" IDENTIFIER "(" [ argList ] ")" ;

arrayLiteral      = "[" [ expression { "," expression } ] "]" ;
objectLiteral     = "{" [ property { "," property } ] "}" ;
property          = ( IDENTIFIER | STRING ) ":" expression ;
argList           = expression { "," expression } ;

(Volledige grammatica wordt geïmplementeerd via ANTLR.)


Compiler-architectuur

  • Lexer + Parser: ANTLR
  • Opbouw van CST
  • Semantische analyse:
    • symbol tables
    • scope-analyse
    • type checking
  • Gestructureerde foutafhandeling met locatie-informatie

VS Code Language Server

  • Zet compiler-resultaten om naar:
    • Diagnostics in de editor
    • Completion items
  • Gebruikt vscode-languageserver

Testing

  • Unit tests voor parser (CST)
  • Tests voor syntax errors
  • End-to-end tests voor semantische analyse
  • End-to-end tests voor code completion data

Code om warnings en errors mee te testen

De volgende code moet geschreven worden in een bestand genaamd index.brett om de verschillende warnings, errors en code completions te testen.

// ===================================
// SECTION 1: SYNTAX ERRORS
// ===================================

let x: number = 10; 
const MyVariable: any = 5;

def calculate(a: number, b: number) { 
    return a + b;
}

if (true) { 
    let z = 5;
}
    


// ===================================
// SECTION 2: SEMANTIC ERRORS
// ===================================

let MyAge: number = 30; // (Warning)

let myValue: number = "hello"; // ERROR 6

def testScope() {
    let localVar: number = 1;
    let localVar: string = "oops"; // ERROR 7
}

def anotherFunction() {
    let result = calculate(10, 20); 
    
    // 👇 FOUTEN DIE MOETEN VERSCHIJNEN
    let total = sum(1, 2); // Function 'sum' is not found.

    total = unknown + 1; // Variable 'unknown' is niet gevonden in deze scope.
}

Screenshots

  • error diagnostics error diagnostics

  • warning diagnostics warning diagnostics

  • completion popup in VS Code

    code completion popup 2 code completion popup 1 code completion popup 3