Natural Language Source Compiler - Compile .nl specs to executable code
Project description
Natural Language Source (NLS)
The source code is English. The compiled artifact is Python.
NLS is a programming language where specifications are written in plain English that anyone can read—managers, auditors, domain experts—not just programmers. The nlsc compiler translates .nl files into executable Python with full type hints, validation, and documentation.
Installation
# Install from PyPI
pip install nlsc
# With tree-sitter parser (faster, better error recovery)
pip install "nlsc[treesitter]"
# For development (from source)
git clone https://github.com/Mnehmos/mnehmos.nls.lang.git
cd mnehmos.nls.lang
pip install -e ".[dev,treesitter]"
Windows File Association
Get custom icons for .nl files in Windows Explorer:
# Download and run the installer from GitHub Releases
# Or use the CLI:
nlsc assoc --user # Current user (no admin)
nlsc assoc # System-wide (requires admin)
Then right-click any .nl file → Open with → select the NLS launcher and check "Always use this app".
Quick Start
# Initialize a new project
nlsc init my-project
cd my-project
# Create your first .nl file
cat > src/calculator.nl << 'EOF'
@module calculator
@target python
[add]
PURPOSE: Add two numbers together
INPUTS:
- a: number
- b: number
RETURNS: a + b
[divide]
PURPOSE: Divide two numbers safely
INPUTS:
- numerator: number
- divisor: number
GUARDS:
- divisor must not be zero -> ValueError("Cannot divide by zero")
RETURNS: numerator / divisor
@test [add] {
add(2, 3) == 5
add(-1, 1) == 0
}
EOF
# Compile to Python
nlsc compile src/calculator.nl
# Run the tests
nlsc test src/calculator.nl
Example
Input: math.nl
@module math
@version 1.0.0
@target python
@type Point {
x: number
y: number
}
[distance]
PURPOSE: Calculate distance between two points
INPUTS:
- p1: Point
- p2: Point
LOGIC:
1. dx = p2.x - p1.x
2. dy = p2.y - p1.y
3. squared = dx * dx + dy * dy
RETURNS: sqrt(squared)
DEPENDS: [sqrt]
@test [distance] {
distance(Point(0, 0), Point(3, 4)) == 5.0
}
Output: math.py
"""math module - Generated by nlsc"""
from dataclasses import dataclass
from math import sqrt
@dataclass
class Point:
"""Point type"""
x: float
y: float
def distance(p1: Point, p2: Point) -> float:
"""Calculate distance between two points"""
dx = p2.x - p1.x
dy = p2.y - p1.y
squared = dx * dx + dy * dy
return sqrt(squared)
CLI Reference
| Command | Description |
|---|---|
nlsc init <path> |
Initialize new NLS project |
nlsc compile <file> |
Compile .nl to Python |
nlsc verify <file> |
Validate syntax and dependencies |
nlsc test <file> |
Run @test specifications |
nlsc graph <file> |
Generate dependency diagrams |
nlsc diff <file> |
Show changes since last compile |
nlsc watch <dir> |
Continuous compilation on file changes |
nlsc atomize <file.py> |
Extract ANLUs from existing Python |
nlsc assoc |
Install Windows file association |
nlsc lsp |
Start the NLS language server |
Global Options
--parser {regex,treesitter} # Parser backend (default: regex)
--version # Show version
--help # Show help
Examples
# Compile with tree-sitter parser
nlsc --parser treesitter compile src/auth.nl
# Generate Mermaid dependency diagram
nlsc graph src/order.nl --format mermaid
# Visualize dataflow for specific function
nlsc graph src/order.nl --anlu process-order --dataflow
# Watch directory and run tests on changes
nlsc watch src/ --test
# Show what changed since last compile
nlsc diff src/api.nl --full
GitHub Action
Use the NLS Compiler Action in your CI/CD pipelines for zero-config validation:
# .github/workflows/nls.yml
name: NLS Validation
on: [push, pull_request]
jobs:
validate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: Mnehmos/mnehmos.nls.lang/action@master
with:
verify: 'true' # Verify all .nl files parse correctly
compile: 'false' # Compile .nl files to Python
test: 'false' # Run @test blocks
lock-check: 'false' # Verify lockfiles are current
path: '.' # Path to search for .nl files
Action Inputs
| Input | Default | Description |
|---|---|---|
verify |
true |
Verify all .nl files parse correctly |
compile |
false |
Compile .nl files to target language |
test |
false |
Run @test blocks from .nl files |
lock-check |
false |
Check that lockfiles are up to date |
path |
. |
Path to search for .nl files |
python-version |
3.12 |
Python version to use |
fail-on-warning |
false |
Fail the action if there are warnings |
Action Outputs
| Output | Description |
|---|---|
verified-files |
Number of verified .nl files |
compiled-files |
List of compiled output files |
test-results |
Test pass/fail summary |
warnings |
Number of warnings |
Language Features
ANLU Blocks (Functions)
[function-name]
PURPOSE: What this function does
INPUTS:
- param1: type
- param2: type, optional
GUARDS:
- validation condition -> ErrorType("message")
LOGIC:
1. step description -> variable
2. another step
EDGE CASES:
- condition -> behavior
RETURNS: expression
DEPENDS: [other-function], [another]
Type Definitions
@type Order {
id: string, required
items: list of OrderItem
total: number, "Order total in cents"
status: string
}
@type OrderItem extends BaseItem {
quantity: number
price: number
}
Test Specifications
@test [add] {
add(1, 2) == 3
add(0, 0) == 0
add(-5, 5) == 0
}
Property-Based Testing
@property [add] {
add(a, b) == add(b, a) # commutativity
add(a, 0) == a # identity
forall x: number -> add(x, -x) == 0
}
Type Invariants
@type Account {
balance: number
owner: string
}
@invariant Account {
balance >= 0
len(owner) > 0
}
Directives
@module name # Module name
@version 1.0.0 # Semantic version
@target python # Target language
@imports other_module # Import dependencies
The Philosophy
"The conversation is the programming. The
.nlfile is the receipt. The code is the artifact."
.nlfiles — Human-readable specifications anyone can review.pyfiles — Compiled artifacts (like assembly from C).nl.lockfiles — Deterministic hashes for reproducible builds
Why NLS?
- Readable by everyone — Non-programmers can review business logic
- Auditable — Clear mapping from intent to implementation
- Testable — Specifications include test cases
- Versionable — Lock files ensure reproducibility
- Toolable — Tree-sitter grammar enables IDE support
Project Status
| Component | Status |
|---|---|
| Parser (regex) | ✅ Complete |
| Parser (tree-sitter) | ✅ Complete |
| Python emitter | ✅ Complete |
| Type generation | ✅ Complete |
| Guard validation | ✅ Complete |
| Dataflow analysis | ✅ Complete |
| Test runner | ✅ Complete |
| Property-based testing | ✅ Complete |
| Type invariants | ✅ Complete |
| Watch mode | ✅ Complete |
| GitHub Action | ✅ Complete |
| PyPI distribution | ✅ Complete |
| VS Code extension | ✅ Complete |
| LSP server | ✅ Complete |
| Windows installer | ✅ Complete |
| TypeScript target | 🔜 Planned |
239 tests passing — Production-ready for Python target. See GitHub Issues for roadmap.
Documentation
📚 Full Documentation — Hosted on GitHub Pages
Contributing
# Clone and install
git clone https://github.com/Mnehmos/mnehmos.nls.lang.git
cd mnehmos.nls.lang
pip install -e ".[dev,treesitter]"
# Run tests
pytest tests/ -v
# Run tree-sitter grammar tests
cd tree-sitter-nl && npx tree-sitter test
License
MIT
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file nlsc-0.2.2.tar.gz.
File metadata
- Download URL: nlsc-0.2.2.tar.gz
- Upload date:
- Size: 108.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1c1e514b030135adb5660ff7905a3eb2c004670ec557f6bb1633973062fb30fa
|
|
| MD5 |
74700cd4c94283b9fd1b8fb18179fc09
|
|
| BLAKE2b-256 |
a0aa303e8bf5e393e9be911d27ca50ce87b56cb917d3552a9edfedcd3215fa8d
|
Provenance
The following attestation bundles were made for nlsc-0.2.2.tar.gz:
Publisher:
publish.yml on Mnehmos/mnehmos.nls.lang
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
nlsc-0.2.2.tar.gz -
Subject digest:
1c1e514b030135adb5660ff7905a3eb2c004670ec557f6bb1633973062fb30fa - Sigstore transparency entry: 833855447
- Sigstore integration time:
-
Permalink:
Mnehmos/mnehmos.nls.lang@7e9d51fb4df3b3a472859cf2cb9a020df74cd036 -
Branch / Tag:
refs/tags/v0.2.2 - Owner: https://github.com/Mnehmos
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@7e9d51fb4df3b3a472859cf2cb9a020df74cd036 -
Trigger Event:
release
-
Statement type:
File details
Details for the file nlsc-0.2.2-py3-none-any.whl.
File metadata
- Download URL: nlsc-0.2.2-py3-none-any.whl
- Upload date:
- Size: 78.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cc507edb845450e138e5c7e4b960e03e84d632322de035d065038de1a457427f
|
|
| MD5 |
fd021177128e3a26a4fb9f8def05d799
|
|
| BLAKE2b-256 |
de85391f41b39826a94908d68277ea5bdb5e69d47cc1b926a3532732a6e348fe
|
Provenance
The following attestation bundles were made for nlsc-0.2.2-py3-none-any.whl:
Publisher:
publish.yml on Mnehmos/mnehmos.nls.lang
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
nlsc-0.2.2-py3-none-any.whl -
Subject digest:
cc507edb845450e138e5c7e4b960e03e84d632322de035d065038de1a457427f - Sigstore transparency entry: 833855448
- Sigstore integration time:
-
Permalink:
Mnehmos/mnehmos.nls.lang@7e9d51fb4df3b3a472859cf2cb9a020df74cd036 -
Branch / Tag:
refs/tags/v0.2.2 - Owner: https://github.com/Mnehmos
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@7e9d51fb4df3b3a472859cf2cb9a020df74cd036 -
Trigger Event:
release
-
Statement type: