The AffineScript CLI provides commands for compiling, testing, and managing projects.
# Install from source
git clone https://github.com/hyperpolymath/affinescript
cd affinescript
dune build && dune install
# Or with opam (planned)
opam install affinescriptThe main compiler executable:
# Lex a file (output tokens)
affinescript lex <file.affine>
# Parse a file (output AST)
affinescript parse <file.affine>
# Type-check a file
affinescript check <file.affine>
# Compile to WASM
affinescript compile <file.affine> -o output.wasm
# Run directly
affinescript run <file.affine>--help, -h Show help message
--version, -v Show version
--verbose Verbose output
--quiet, -q Suppress output
--color <auto|always|never> Color outputLexical analysis - tokenize source file:
affinescript lex src/main.affine
# Output format
affinescript lex --format json src/main.affine
affinescript lex --format pretty src/main.affineExample output:
FN @ 1:1-1:3
IDENT("main") @ 1:4-1:8
LPAREN @ 1:8-1:9
RPAREN @ 1:9-1:10
ARROW @ 1:11-1:13
IDENT("Unit") @ 1:14-1:18
LBRACE @ 1:19-1:20
...
Parse source file to AST:
affinescript parse src/main.affine
# Output options
affinescript parse --format sexp src/main.affine
affinescript parse --format json src/main.affine
affinescript parse --format pretty src/main.affineType-check without compiling:
affinescript check src/main.affine
# Check entire project
affinescript check .
# Show inferred types
affinescript check --show-types src/main.affineCompile to WebAssembly:
# Basic compilation
affinescript compile src/main.affine -o output.wasm
# With optimizations
affinescript compile --release src/main.affine -o output.wasm
# Emit text format
affinescript compile --emit wat src/main.affine -o output.wat
# Debug info
affinescript compile --debug src/main.affine -o output.wasm
# Target options
affinescript compile --target wasm32 src/main.affineCompile and run:
# Run with default WASM runtime
affinescript run src/main.affine
# Pass arguments
affinescript run src/main.affine -- arg1 arg2
# With specific runtime
affinescript run --runtime wasmtime src/main.affineAffineScript Package Manager (planned):
# Create new project
aspm init my-project
aspm init --lib my-library
# Build project
aspm build
aspm build --release
# Run main
aspm run
# Clean build artifacts
aspm clean# Add dependency
aspm add json
aspm add http@2.0
# Remove dependency
aspm remove json
# Update dependencies
aspm update
aspm update json# Run all tests
aspm test
# Run specific tests
aspm test --filter "test_parser"
# With coverage
aspm test --coverage
# Verbose
aspm test --verbose# Generate docs
aspm doc
# Open in browser
aspm doc --open
# Include private items
aspm doc --document-private-items# Login to registry
aspm login
# Publish package
aspm publish
# Check before publishing
aspm publish --dry-runLanguage Server Protocol implementation (planned):
# Start LSP server
aslsp
# With logging
aslsp --log-level debug
# Specify port (for TCP mode)
aslsp --port 5007Code formatter (planned):
# Format file
asfmt src/main.affine
# Format in place
asfmt --write src/main.affine
# Format all files
asfmt --write .
# Check formatting
asfmt --check src/main.affine
# Diff mode
asfmt --diff src/main.affineConfiguration (.asfmt.toml):
max_width = 100
indent_size = 2
use_tabs = false
trailing_comma = trueStatic analysis (planned):
# Run all lints
aslint src/
# Specific rules
aslint --warn unused_variables src/
aslint --deny unsafe_code src/
# Fix automatically
aslint --fix src/| Variable | Description |
|---|---|
AFFINE_HOME |
Installation directory |
AFFINE_CACHE |
Cache directory |
AFFINE_LOG |
Log level (error, warn, info, debug, trace) |
NO_COLOR |
Disable colored output |
| Code | Meaning |
|---|---|
| 0 | Success |
| 1 | General error |
| 2 | Command-line usage error |
| 101 | Compilation failed |
| 102 | Type error |
| 103 | Borrow check error |
- Installation - Setup guide
- Package Manager - aspm details
- LSP - Editor integration