| Crates.io | verbena |
| lib.rs | verbena |
| version | 0.2.0 |
| created_at | 2025-03-17 06:06:14.108158+00 |
| updated_at | 2025-04-06 20:25:39.563286+00 |
| description | Scripting language |
| homepage | |
| repository | https://github.com/russellw/verbena |
| max_upload_size | |
| id | 1595083 |
| size | 113,725 |
A lightweight, expressive scripting language that compiles to JavaScript, designed for simplicity and readability.
# Clone the repository
git clone https://github.com/russellw/verbena
cd verbena
# Build the compiler
cargo build --release
# Add to your PATH (optional)
export PATH=$PATH:$(pwd)/target/release
Dynamically typed. Variable declaration is implicit upon assignment.
# Variables are dynamically typed
name = "Verbena"
is_awesome = true
# Data structures
numbers = [1, 2, 3, 4, 5]
settings = {
"debug": true,
"port": 8080,
"host": "localhost"
}
Standard arithmetic, comparison, and logical operators:
# Arithmetic
sum = a + b
difference = a - b
product = a * b
quotient = a / b
remainder = a % b
power = a ** b
# Compound assignment
count += 1
total *= factor
# Comparison
is_equal = a == b
is_not_equal = a != b
is_greater = a > b
is_less = a < b
# Logical
result = condition1 && condition2
result = condition1 || condition2
result = !condition
# If statements
if x > 0
print "Positive"
elif x < 0
print "Negative"
else
print "Zero"
end
# While loops
while count < 10
count += 1
print count
end
# Do-while loops
dowhile condition
# Code executed at least once
end
# For loops
for item : collection
print item
end
# For loops with index
for i, item : collection
print i, item
end
# Case statement (similar to switch)
case value
| 1, 2, 3
print "Small number"
| 4, 5, 6
print "Medium number"
else
print "Large number"
end
fn greet(name)
print "Hello, " + name + "!"
end
fn add(a, b)
return a + b
end
# Call functions
greet("World")
result = add(5, 3)
try
# Code that might throw an error
result = risky_operation()
catch error
# Handle the error
eprint "Error: " + error
end
# Throw an error
throw "Something went wrong"
# Assertions
assert x > 0, "x must be positive"
Verbena allows you to explicitly declare variables from outer scopes that a function needs access to:
count = 0
fn increment()
outer count
count += 1
end
# Access array elements
first = array[0]
# Slices (similar to Python)
subset = array[1:4] # Elements 1, 2, 3
beginning = array[:5] # First 5 elements
end = array[5:] # Elements from index 5 to the end
if typeof(value) == "string"
print "Value is a string: " + value
end
Verbena includes several built-in functions for common operations:
len() - Get the length of a collectionpush() - Add an element to an arrayrepr() - Get string representationstring() - Convert to stringrange() - Generate a sequence of numbers# Compile a Verbena file to JavaScript
verbena -o output.js input.va
# Run the compiled JavaScript
node output.js
Usage: Verbena [OPTIONS] <file>
Arguments:
<file> Source file
Options:
-o <file> Output file [default: a.js]
-h, --help Print help
-V, --version Print version
print "Hello, Verbena!"
fn factorial(n)
if n <= 1
return 1
else
return n * factorial(n - 1)
end
end
for i : range(1, 11)
print i, "! =", factorial(i)
end
fn divide(a, b)
if b == 0
throw "Division by zero"
end
return a / b
end
try
result = divide(10, 0)
print "Result:", result
catch error
print "Error caught:", error
end
This project is licensed under either of:
at your option.