A small, expressive scripting language in C++ focused on personalization.
- Custom keyword-style callables with
def(write APIs that read like language keywords) - Pass expressions and blocks as arguments with
%exprand$block - Named block arguments like
pass: { ... },fail: { ... } - Functions, classes, inheritance, loops, imports, and stdlib I/O
./build.sh
# run a normal .dsr script directly
./build/dscript --run examples/18_def_keyword_showcase.dsr--run works for both source scripts and built artifacts.
dscript supports these modes:
./build/dscript --repl
./build/dscript --run <script_or_artifact> [args...]
./build/dscript --build <entry_script> [artifact_path]
./build/dscript --help
./build/dscript --versionRun a script directly:
./build/dscript --run examples/01_literals_and_ops.dsrBackward-compatible script invocation still works:
./build/dscript examples/18_def_keyword_showcase.dsr
# pass script arguments (available as io.program_args)
./build/dscript --run examples/18_def_keyword_showcase.dsr one two--build resolves modules and emits a self-contained JSON artifact that can be run on another system without source files.
Default output naming:
- Input
foo.dsr-> outputfoo.dsar - You can override with an explicit
artifact_path
Typical flow:
# Build artifact
./build/dscript --build examples/23_imports_and_modules.dsr
# Run artifact
./build/dscript --run examples/23_imports_and_modules.dsarArtifact contents include:
- Entry module ID
- Full AST for each module
- Resolved locals metadata used by runtime variable resolution
- Module import mapping for cross-module execution
- Runtime artifact imports (
import './other.dsar' as mod) from scripts or other artifacts
def lets you build callables that are invoked in keyword-like style:
def shout(msg) {
log('shout: ' + msg);
}
shout 'hello';You can create APIs that read like mini-language constructs:
def guard(cond) (pass: $pass_block, fail: $fail_block) {
if cond then {
if $pass_block is not none then $pass_block();
} else {
if $fail_block is not none then $fail_block();
}
}
guard energy > 3 pass: {
log('allowed');
} fail: {
log('blocked');
}dscript supports expression and block parameters directly:
fn x(%expr) ($block) {
%expr();
$block();
}
x i = 10 {
log(i);
}%namereceives an expression/callable argument$namereceives a block argument- Named blocks can be optional (
none) and checked at runtime
dscript classes support a private-field declaration block and an init shorthand:
class Reader {
(
idx = 0,
script,
)
fn init(script) = def;
}- Fields listed in
(...)are private to the declaring class methods. fn init(a, b, ...) = def;expands to assigning each parameter toself(self.a = a,self.b = b, ...).- Private fields can include default values (
name = expr) or omit them (defaults tonone).
- Literals/operators:
examples/01_literals_and_ops.dsr - Variables/scope:
examples/02_variables_assignment_scope.dsr - Conditionals/loops:
examples/03_if_else_and_logic.dsrtoexamples/06_functions_and_return.dsr defkeyword callables:examples/07_def_callable_keyword.dsr,examples/18_def_keyword_showcase.dsr- Expr/block identifiers:
examples/10_expr_and_block_identifiers.dsr - Named blocks:
examples/12_named_blocks_and_none.dsr - Classes/inheritance:
examples/08_classes_fields_methods.dsr,examples/09_inheritance_super_self.dsr - Private members + default initializer:
examples/29_private_members.dsr,examples/30_default_initializer.dsr - Imports/modules:
examples/23_imports_and_modules.dsr - Artifact imports:
examples/31_artifact_imports.dsr(buildexamples/lib/math.dsrtoexamples/lib/math.dsarfirst) - Stdlib I/O:
examples/24_stdlib_io.dsr - Stdlib random:
examples/32_stdlib_random.dsr - Stdlib math:
examples/33_stdlib_math.dsr - DScript stdlib authoring:
examples/35_dscript_stdlib.dsr
You can author stdlibs in dscript and import them by module name.
- Place DScript stdlib sources under
./stdlibs/dsr/ - Build artifacts are emitted under
./stdlibs/dsar/ - Import by name, for example:
import text as text; - Runtime lookup for
import name:- Native stdlib named
name ./stdlibs/dsr/name.dsr./stdlibs/dsar/name.dsar
- Native stdlib named
import 'std:name' as mod;is also supported and uses the same DScript stdlib lookup.
This keeps native stdlibs (io, math, etc.) working while allowing dscript-authored stdlibs.
Folder split for clarity:
- C++ stdlibs live in
./runtime/stdlibs/ - DScript stdlib sources live in
./stdlibs/dsr/ - DScript stdlib artifacts live in
./stdlibs/dsar/
During CMake builds, all ./stdlibs/dsr/*.dsr modules are precompiled to ./stdlibs/dsar/*.dsar. If any precompile step fails, the build fails.
- Dev build:
./build.sh [BuildType] [BuildDir] - Release matrix build:
./build_release.sh [BuildRoot]
- Artifact extension is configured in
app/cli.cppvia a preprocessor definition nearVersion.
lexing/tokenizationparsing/AST + parserresolving/name/scope resolutionruntime/VM, values, objects, stdlibs