Fix parser

This commit is contained in:
2026-05-05 01:57:25 +02:00
parent 528b07e54a
commit 06654b428d
3 changed files with 92 additions and 5 deletions
+1
View File
@@ -8,6 +8,7 @@ target
# MSVC Windows builds of rustc generate these, which store debugging information # MSVC Windows builds of rustc generate these, which store debugging information
*.pdb *.pdb
*.exe
# Generated by cargo mutants # Generated by cargo mutants
# Contains mutation testing data # Contains mutation testing data
+3 -3
View File
@@ -90,8 +90,8 @@ macro_inner_v = {
tuple = { "(" ~ (expr ~ ("," ~ expr)*)? ~ ")" } tuple = { "(" ~ (expr ~ ("," ~ expr)*)? ~ ")" }
primary = { primary = {
integer float
| float | integer
| boolean | boolean
| string_lit | string_lit
| static_path | static_path
@@ -110,7 +110,7 @@ postfix = {
field_px = { "." ~ identifier } field_px = { "." ~ identifier }
call_px = { "(" ~ (expr ~ ("," ~ expr)*)? ~ ")" } call_px = { "(" ~ (expr ~ ("," ~ expr)*)? ~ ")" }
macro_call_px = { "!" ~ "(" ~ macro_inner_v* ~ ")" } macro_call_px = { "!" ~ "(" ~ macro_inner_v* ~ ")" }
struct_px = { "{" ~ (struct_field_decl ~ ("," ~ struct_field_decl)*)? ~ "}" } struct_px = { "{" ~ (struct_field_decl ~ ("," ~ struct_field_decl)*)? ~ ","? ~ "}" }
index_px = { "[" ~ expr ~ "]" } index_px = { "[" ~ expr ~ "]" }
binary_px = { bin_op ~ expr } binary_px = { bin_op ~ expr }
bin_op = { "+" | "-" | "*" | "/" | "%" | "==" | "!=" | "<" | ">" | "<=" | ">=" } bin_op = { "+" | "-" | "*" | "/" | "%" | "==" | "!=" | "<" | ">" | "<=" | ">=" }
+88 -2
View File
@@ -1,3 +1,89 @@
void main() { #include <std::math>
(i32, i32, str*) my_tuple = (10, 20, "hello, world"); #include <std::io>
public struct Vec2 {
f32 x,
f32 y,
}
public struct Body {
Vec2 pos,
Vec2 vel,
f32 mass,
}
public struct World {
Body bodies,
}
// ---------- Utility Functions ----------
public Vec2 add(Vec2 a, Vec2 b) {
return Vec2{ x: a.x + b.x, y: a.y + b.y };
}
public Vec2 scale(Vec2 v, f32 s) {
return Vec2{ x: v.x * s, y: v.y * s };
}
public f32 length(Vec2 v) {
return std::math::sqrt(v.x * v.x + v.y * v.y);
}
// ---------- Physics Step ----------
public void integrate(Body mut* body, f32 dt) {
body.pos = add(body.pos, scale(body.vel, dt));
}
public void apply_gravity(Body mut* body) {
// simple constant gravity
body.vel.y = body.vel.y - 9.81;
}
// ---------- Simulation ----------
public void simulate(World mut* world, i32 steps, f32 dt) {
i32 i = 0;
while (i < steps) {
i = i + 1;
// pretend we have an array-like world.bodies
i32 j = 0;
while (j < 10) {
Body b = world.bodies[j];
apply_gravity(&mut b);
integrate(&mut b, dt);
world.bodies[j] = b;
j = j + 1;
}
}
}
// ---------- Debug / Logging ----------
public void debug_body(Body b) {
std::io::println!("Body -> pos(", b.pos.x, ", ", b.pos.y, ")");
}
// ---------- Entry Point ----------
public void main() {
Body player = Body{
pos: Vec2{ x: 0.0, y: 10.0 },
vel: Vec2{ x: 1.0, y: 0.0 },
mass: 1.0,
};
World world = World{
bodies: player
};
simulate(&mut world, 60, 0.016);
debug_body(world.bodies[0]);
} }