Crates.io | pawc |
lib.rs | pawc |
version | |
source | src |
created_at | 2025-05-01 03:36:55.901142+00 |
updated_at | 2025-05-07 20:22:09.994737+00 |
description | š¾ PawScript interpreter |
homepage | https://github.com/KinLeoapple/pawc |
repository | https://github.com/KinLeoapple/pawc |
max_upload_size | |
id | 1655821 |
Cargo.toml error: | TOML parse error at line 18, column 1 | 18 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
Welcome to PawScript ā a ācute yet practicalā staticallyātyped, functional scripting language. This README covers all v0.1 syntax, including Record (struct), Optional types, async/await, error handling, module import, and more.
Clone and build:
git clone https://github.com/KinLeoapple/pawc.git
cd pawc
cargo build --release
Run a script:
target/release/pawc hello.paw
PawScript Interpreter supports adjusting the backup stack size for the main thread via a CLI flag (in MiB) to accommodate deepārecursion scenarios.
# Default: maināthread backup stack 1 MiB
target/release/pawc script.paw
# Custom: maināthread backup stack 4 MiB
target/release/pawc --stack-size 4 script.paw
A PawScript program consists of statements and function declarations executed in order.
Int
, Long
, Float
, Double
, Bool
, Char
, String
Array<T>
Any
(dynamic), Optional<T>
(nullable, can also be written T?
)PawScript supports optional types to represent possibly missing values.
Declare an optional type by appending ?
, e.g. Int?
is Optional<Int>
.
The null literal is nopaw
.
Assigning nopaw
to a nonāoptional type is a compileātime error.
Example:
let maybeNum: Int? = nopaw
if maybeNum == nopaw {
say "No number provided"
}
let x: Int = 10
let y: Int? = nopaw # optional type
x = x + 1 # reassignment
+ - * / %
== != < <= > >=
&& || !
"Hi " + name + "!"
await <asyncCall>
(a + b) * c
let
/ =
say <expr>
ask "prompt"
or let x: String <- ask "?"
return <expr>
or return
if cond {
ā¦
} else if cond2 {
ā¦
} else {
ā¦
}
loop forever { ⦠}
loop cond { ⦠}
loop i in start..end { ⦠}
loop item in array { ⦠}
break
exits the nearest loop.continue
skips to the next iteration.fun add(a: Int, b: Int): Int {
return a + b
}
let result: Int = add(1, 2)
PawScript supports defining asynchronous functions and awaiting their results, enabling nonāblocking I/O and concurrent tasks.
To define an asynchronous function, prefix the signature with the async
keyword:
async fun fetchData(url: String): String {
// ... perform asynchronous operations ...
bark "Fetched data from " + url
return "data"
}
async
must appear before the fun
keyword.Future<T>
internally.Use await
to suspend until a Future
completes:
let content: String = await fetchData("http://example.com/data")
say "Received: " + content
await
may be used at topālevel or within async functions.let a: Array<Int> = [1, 2, 3]
say a[0] # index access
say a.length() # length property
PawScript supports userādefined composite types called Record (struct).
record Point {
x: Int
y: Int
}
let p: Point = Point { y: 4, x: 3 }
say p.x # 3
say p.y # 4
Use as
for explicit casts:
let i: Int = 3
let f: Float = i as Float
say f + 1.5
Int ā Long ā Float ā Double
.# singleāline comment
let x: Int = 5 # endāofāline comment
Keyword | Purpose |
---|---|
bark |
throw error |
sniff |
try block |
snatch |
catch block |
lastly |
finally block |
sniff {
ā¦
} snatch (e) {
say "Caught: " + e
} lastly {
say "Cleanup"
}
import utils.math # binds module to `math`
import utils.math as m # binds module to alias `m`
import utils.math as m
import string
say "=== Record & Async Example ==="
# Record
record Point { x: Int, y: Int }
let p: Point = Point { y: 4, x: 3 }
say "p.x + p.y = " + (p.x + p.y)
# Async
async fun fetchData(url: String): String {
bark "network not implemented"
return "data"
}
let result: String = await fetchData("http://example.com")
# Loop with break/continue
let sum: Int = 0
loop i in 1..10 {
if i == 5 {
continue
}
if i == 8 {
break
}
sum = sum + i
}
say "sum = " + sum
Enjoy coding in PawScript ā cute yet powerful!