Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,5 @@ aya-obj = "0.2.1"
caps = "0.5.5"
io-uring = "0.7.10"
enum_dispatch = "0.3.13"
pest = "2.8.1"
pest_derive = "2.8.1"
46 changes: 46 additions & 0 deletions src/script/ast.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
use std::collections::HashMap;

#[derive(Debug, Clone, PartialEq)]
pub enum Arg {
/// Simple constant
Const { text: String },

/// Variable available at runtime
Var { name: String },

/// Helper like random_path
Dynamic { name: String, args: Vec<Arg> },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh lord, self referential structs/enums, this is going to be fun.

Mandatory "if you get into trouble you should read https://rust-unofficial.github.io/too-many-lists/" PSA.

Copy link
Collaborator Author

@erthalion erthalion Feb 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm? The page you've posted doesn't mention self referential structures at all, am I missing something?
And even if it's somehow bad in Rust, what is your suggestion? Parsing AST without self references is like trying to hammer a nail without an actual hammer -- you probably can do this, but it will likely be very awkward.

}

#[derive(Debug, Clone, PartialEq)]
pub enum Instruction {
Task { name: Arg, args: Vec<Arg> },
Open { path: Arg },
Debug { text: Arg },
Ping { server: Arg },
}

#[derive(Debug, Clone, PartialEq)]
pub enum MachineInstruction {
Server { port: u16 },
Profile { target: String },
Path { value: String },
}

#[derive(Debug, Clone, PartialEq)]
pub enum Dist {
Exp { rate: f64 },
}

#[derive(Debug, Clone)]
pub enum Node {
Machine {
m_instructions: Vec<MachineInstruction>,
},
Work {
name: String,
args: HashMap<String, String>,
instructions: Vec<Instruction>,
dist: Option<Dist>,
},
}
102 changes: 102 additions & 0 deletions src/script/grammar.peg
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
WHITESPACE = _{" " | "\t" | NEWLINE}
COMMENT = _{"//" ~ (!NEWLINE ~ ANY)*}

ident_char = {ASCII_ALPHA | "_" | "$"}
ident = @{ident_char ~ (ASCII_DIGIT | ident_char)*}

constant = {
"\"" ~ value ~ "\""
| ASCII_DIGIT*
}

randomPath = { "random_path" }
randomString = { "random_string" }

dynamicName = {
randomPath
| randomString
}

dynamic = {dynamicName ~ args}

// constant should be the last
arg = {
dynamic
| ident
| constant
}

args = {"(" ~ (arg ~ ("," ~ arg)* ~ ","?)? ~ ")"}
value = {(ASCII_ALPHANUMERIC| "." | " " | "/" | ":")*}

param = {ident ~ "=" ~ value}
params = {"(" ~ (param ~ ("," ~ param)* ~ ","?)? ~ ")"}

task = { "task" }
network = { "network" }
port = { "port" }
open = { "open" }
ping = { "ping" }
debug = { "debug" }

funcName = {
task
| network
| port
| open
| ping
| debug
}

exp = { "exp" }
zipf = { "zipf" }
uniform = { "uniform" }

distName = {
exp
| zipf
| uniform
}

expr = {
function
| instruction
}

opt = {ident ~ "=" ~ value ~ ";" }

dist = {":" ~ distName ~ "{" ~ opt* ~ "}"}

work = {ident ~ params?}

instruction = {funcName ~ args? ~ ";"}

instructions = { expr* }

function = {
work
~ "{" ~ instructions ~ "}"
~ dist?
}

server = { "server" }
load = { "load" }
memory = { "memory" }
profile = { "profile" }
path = { "path" }

mInstrName = {
server
| load
| memory
| profile
| path
}

machineInstruction = {mInstrName ~ args? ~ ";"}

machine = {"machine" ~ "{" ~ machineInstruction* ~ "}"}

file = {
SOI ~ machine? ~ (expr*) ~ EOI
}
3 changes: 3 additions & 0 deletions src/script/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub mod ast;
pub mod parser;
pub mod rules;
Loading