Skip to content

CoderKuo/NovaLang

Repository files navigation

NovaLang

English | 简体中文

A modern scripting language running on the JVM

Kotlin-inspired syntax · Seamless Java interop · Async/await · TypeScript-friendly

FeaturesQuick StartExamplesDocumentationArchitecture


Features

Modern Syntax

Kotlin-inspired syntax that's concise, expressive, and easy to learn.

val name = "Nova"
var count = 0

fun greet(who: String): String {
    return "Hello, $who!"
}

class Point(val x: Int, val y: Int) {
    fun distance(): Double = sqrt(x * x + y * y)
}

Async/Await Support

Built-in asynchronous programming with async/await.

val result = async {
    // concurrent computation
    heavyComputation()
}

println(await result)

Java Interoperability

Seamlessly call Java classes and implement Java interfaces.

import java java.util.ArrayList
import java java.lang.Runnable

val list = ArrayList<String>()
list.add("Hello")

val runner = object : Runnable {
    fun run() {
        println("Running from Nova!")
    }
}

Rich Type System

  • Classes, interfaces, enums, and objects
  • Generic types with reified type parameters
  • Extension functions
  • Nullable types with safe operators (?., ?:, !!)

Standard Library

Comprehensive stdlib with collections, I/O, JSON, HTTP, and more.

val numbers = [1, 2, 3, 4, 5]
val doubled = numbers.map { it * 2 }
val filtered = numbers.filter { it > 2 }

val json = parseJson("{\"name\": \"Nova\"}")
println(json["name"])

Multiple Execution Modes

  • REPL: Interactive shell for experimentation
  • Script: Execute .nova files directly
  • Embedded: Use as a library in Java/Kotlin applications
  • JSR-223: Standard scripting engine integration

Quick Start

Prerequisites

  • JDK 8 or higher
  • Gradle 7.x (or use the included wrapper)

Build

./gradlew build

Run REPL

./gradlew :nova-cli:run

Execute Script

./gradlew :nova-cli:run --args="path/to/script.nova"

Examples

Variables & Functions

val PI = 3.14159
var counter = 0

fun factorial(n: Int): Int {
    if (n <= 1) return 1
    return n * factorial(n - 1)
}

println(factorial(5))  // 120

Control Flow

// If expression
val result = if (x > 0) "positive" else "non-positive"

// When expression (pattern matching)
fun describe(n: Int): String = when (n) {
    0 -> "zero"
    1, 2 -> "small"
    in 3..10 -> "medium"
    else -> "large"
}

// For loop with range
for (i in 1..10) {
    println(i)
}

Collections

// List literal
val items = [1, 2, 3, 4, 5]

// Map literal
val person = #{"name": "Alice", "age": 30}

// Set literal
val unique = #{1, 2, 3}

// Higher-order functions
val squared = items.map { it * it }
val evens = items.filter { it % 2 == 0 }
val sum = items.reduce { a, b -> a + b }

Classes & Objects

class User(val name: String, var age: Int) {
    fun greet(): String = "Hi, I'm $name"
}

val user = User("Alice", 25)
println(user.greet())

// Singleton object
object Database {
    fun connect() { println("Connected") }
}
Database.connect()

Enums

enum Color {
    RED, GREEN, BLUE
}

fun paint(color: Color) {
    when (color) {
        Color.RED -> println("Painting red")
        else -> println("Painting other")
    }
}

Extension Functions

fun String.shout(): String = this.toUpperCase() + "!"

val msg = "hello"
println(msg.shout())  // HELLO!

Nullable Types

val name: String? = maybeNull()

// Safe call
val length = name?.length()

// Elvis operator
val len = name?.length() ?: 0

// Safe index
val first = list?[0]

Documentation

Document Description
Syntax Specification Complete EBNF grammar
Usage Guide How to use NovaLang
Java Interop Java integration guide
Standard Library Built-in modules
Reflection API Runtime type introspection
Annotation System Custom annotations

Architecture

NovaLang
├── nova-runtime-api    # Core types (NovaValue, NovaClass, etc.)
├── nova-compiler       # Lexer, Parser, AST
├── nova-ir             # HIR/MIR + Optimization passes
├── nova-runtime        # Interpreter + Stdlib
├── nova-cli            # Command-line interface
├── nova-script         # JSR-223 script engine
├── nova-lsp            # Language Server Protocol
└── vscode-nova         # VS Code extension

Compilation Pipeline

Source Code → Lexer → Parser → AST → HIR → MIR → Interpreter
                                         ↓
                                   Optimization Passes
                                   (CSE, DCE, Inlining, etc.)

VS Code Extension

NovaLang provides a VS Code extension with:

  • Syntax highlighting
  • Code completion
  • Go to definition
  • Error diagnostics

Located in vscode-nova/ directory.


Security

NovaLang includes a configurable security sandbox:

# Run with sandbox
nova --sandbox STANDARD script.nova

# Sandbox levels
UNRESTRICTED  # No restrictions
STANDARD      # Block dangerous operations
STRICT        # Minimal permissions

Project Status

NovaLang is under active development. Current version: 0.1.0-SNAPSHOT


License

MIT License


Contributing

Contributions are welcome! Please feel free to submit issues and pull requests.

About

Drop-in scripting for JVM apps — Kotlin-like syntax, zero boilerplate, full Java interop.

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors