Initial commit

This commit is contained in:
Aleksandr 2024-07-30 23:43:47 +03:00
commit 0a9dc80583
13 changed files with 239 additions and 0 deletions

9
crates/parser/Cargo.toml Normal file
View file

@ -0,0 +1,9 @@
[package]
name = "saja-parser"
version = "0.1.0"
edition = "2021"
[dependencies]
chumsky = "0.9.3"
compact_str.workspace = true

3
crates/parser/src/lib.rs Normal file
View file

@ -0,0 +1,3 @@
pub mod stmt;
pub mod types;

View file

@ -0,0 +1,8 @@
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub enum Stmt {
BgLoad(bgload::BgLoad),
SetImg(setimg::SetImg),
}
pub mod bgload;
pub mod setimg;

View file

@ -0,0 +1,9 @@
use compact_str::CompactString;
use crate::types::Fadetime;
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub struct BgLoad {
pub file: CompactString,
pub fadetime: Option<Fadetime>,
}

View file

@ -0,0 +1,9 @@
use compact_str::CompactString;
use crate::types::Position;
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub struct SetImg {
pub file: CompactString,
pub position: Position,
}

View file

@ -0,0 +1,21 @@
use std::num::NonZeroU16;
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
#[repr(transparent)]
pub struct Fadetime(pub NonZeroU16);
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
#[repr(transparent)]
pub struct Coord(pub i16);
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub struct Position(pub Coord, pub Coord);
impl Position {
pub const fn offset(self, Offset(dx, dy): Offset) -> Self {
Self(Coord(self.0 .0 + dx.0), Coord(self.1 .0 + dy.0))
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub struct Offset(pub Coord, pub Coord);