From e69514e46e1cea1a5ab6392ae55a2c609a582677 Mon Sep 17 00:00:00 2001 From: zxq5 Date: Thu, 5 Feb 2026 01:26:37 +0000 Subject: [PATCH] modified editor to include syntax for .dsc files --- dsa_editor/src/syntax/dsc.rs | 25 ++++++++++++++ dsa_editor/src/syntax/mod.rs | 1 + emulator/src/emulator/ui/editor.rs | 11 +++---- src/main.rs | 53 ------------------------------ 4 files changed, 30 insertions(+), 60 deletions(-) create mode 100644 dsa_editor/src/syntax/dsc.rs delete mode 100644 src/main.rs diff --git a/dsa_editor/src/syntax/dsc.rs b/dsa_editor/src/syntax/dsc.rs new file mode 100644 index 0000000..185eb1a --- /dev/null +++ b/dsa_editor/src/syntax/dsc.rs @@ -0,0 +1,25 @@ +use super::Syntax; +use std::collections::BTreeSet; + +impl Syntax { + pub fn dsc() -> Self { + Syntax { + language: "Damn Simple Code", + case_sensitive: false, + comment: "//", + comment_multiline: ["/*", "*/"], + hyperlinks: BTreeSet::from(["http"]), + keywords: BTreeSet::from([ + "include", "fn", "let", "const", "static", "if", "else", "while", "for", + "break", "continue", "loop", "return", + ]), + types: BTreeSet::from([ + "u32", "u16", "u8", "i32", "i16", "i8", "str", "char", "bool", "void", + ]), + special: BTreeSet::from([ + ",", ";", ".", ":", "=", "+", "-", "*", "/", "%", "&", "|", "^", "~", + "!", "?", "<", ">", "<<", ">>", "==", "!=", "<=", ">=", "&&", "||", + ]), + } + } +} diff --git a/dsa_editor/src/syntax/mod.rs b/dsa_editor/src/syntax/mod.rs index 12986f2..7a243e8 100644 --- a/dsa_editor/src/syntax/mod.rs +++ b/dsa_editor/src/syntax/mod.rs @@ -1,5 +1,6 @@ #![allow(dead_code)] pub mod dsa; +pub mod dsc; use std::collections::BTreeSet; use std::hash::{Hash, Hasher}; diff --git a/emulator/src/emulator/ui/editor.rs b/emulator/src/emulator/ui/editor.rs index e1d4b4b..47f4fce 100644 --- a/emulator/src/emulator/ui/editor.rs +++ b/emulator/src/emulator/ui/editor.rs @@ -393,8 +393,9 @@ impl Editor { fn render_editor(&mut self, _state: &mut State, ui: &mut Ui, _ctx: &Context) { let available_width = ui.available_width(); let syntax = match self.extension() { - "dsa" => Some(Syntax::new("dsa")), - _ => None, + "dsa" => Syntax::dsa(), + "dsc" => Syntax::dsc(), + _ => Syntax::default(), }; let ed = CodeEditor::default() @@ -402,16 +403,12 @@ impl Editor { .with_fontsize(12.0) .with_rows(0) .with_theme(ColorTheme::default()) - .with_syntax(Syntax::dsa()) + .with_syntax(syntax) .with_numlines(true) .desired_width(available_width - 500.0); let mut editor = ed.clone(); - if let Some(syntax) = syntax { - editor = ed.with_syntax(syntax); - } - editor.show(ui, &mut self.text); } diff --git a/src/main.rs b/src/main.rs deleted file mode 100644 index 5f3e652..0000000 --- a/src/main.rs +++ /dev/null @@ -1,53 +0,0 @@ -use std::{ - sync::{Arc, Mutex}, - thread, -}; - -use dsa_rs::emulator::{ - system::{emulator::run_emulator, memory::MainStore, processor::Processor}, - ui::{ - control_unit::ControlPanel, interface::EmulatorUI, memory_inspector::MemoryInspector, - stack_inspector::StackInspector, - }, -}; - -fn main() -> Result<(), eframe::Error> { - // Initialize Channels - let (cmd_sender, cmd_receiver) = std::sync::mpsc::channel(); - let (state_sender, state_receiver) = std::sync::mpsc::channel(); - - let mainstore = MainStore::new(); - let processor = Processor::new(Box::new(mainstore), vec![]); - - thread::spawn(move || { - run_emulator(&cmd_receiver, &state_sender, processor); - }); - - // Create UI - let mut ui = EmulatorUI::new(cmd_sender.clone(), state_receiver); - - // Create UI modules - let control_unit = ControlPanel::new(cmd_sender.clone()); - ui.add_component(Box::new(control_unit)); - - let mem_inspector = MemoryInspector::new(cmd_sender.clone()); - ui.add_component(Box::new(mem_inspector)); - - let stack_inspector = StackInspector::new(); - ui.add_component(Box::new(stack_inspector)); - - // Run UI - let options = eframe::NativeOptions { - viewport: egui::ViewportBuilder::default().with_inner_size([800.0, 600.0]), - ..Default::default() - }; - - eframe::run_native( - "DSA Simulator (Damn Simple Architecture 🔥)", - options, - Box::new(move |cc| { - cc.egui_ctx.set_visuals(egui::Visuals::default()); - Ok(Box::new(ui)) - }), - ) -}