diff --git a/mist-test/src/app.mist b/mist-test/src/app.mist new file mode 100644 index 0000000..25f64b3 --- /dev/null +++ b/mist-test/src/app.mist @@ -0,0 +1,95 @@ +use ; +use ; +use ; + +pub class Application { + String name; + + Vec tasks; + Vec plugins; + + logger::Logger logger; + + bool running; + i32 ticks; + + pub constructor(str* name) { + self.name; + + self.tasks = new Vec(); + self.plugins = new Vec(); + + self.logger = new logger::Logger("app"); + + self.running = false; + self.ticks = 0; + } + + pub void boot(self mut*) { + self.logger.info("booting application"); + + self.running = true; + + self.emit(event::Event::Startup); + } + + pub void run(self mut*) { + while(self.running) { + self.tick(); + + if(self.ticks >= 5) { + self.shutdown(); + } + } + } + + void tick(self mut*) { + self.logger.info("tick"); + + self.ticks++; + + var task = task::create_task("background-job"); + + self.tasks.push(task); + + println!("tasks: {}", self.tasks.len()); + } + + pub void shutdown(self mut*) { + self.emit(event::Event::Shutdown); + + self.logger.warning("shutdown"); + + self.running = false; + } + + pub void register_plugin(self mut*, String name) { + self.plugins.push(name.clone()); + + self.emit(event::Event::PluginLoaded(name)); + } + + void emit(self*, event::Event event) { + match(event) { + event::Event::Startup => { + self.logger.info("startup event"); + } + + event::Event::Shutdown => { + self.logger.info("shutdown event"); + } + + event::Event::PluginLoaded[name] => { + println!("plugin loaded: {}", name); + } + + event::Event::TaskExecuted[name] => { + println!("task executed: {}", name); + } + + event::Event::Error[message] => { + self.logger.error(&message); + } + } + } +} \ No newline at end of file diff --git a/mist-test/src/event.mist b/mist-test/src/event.mist new file mode 100644 index 0000000..6340bf4 --- /dev/null +++ b/mist-test/src/event.mist @@ -0,0 +1,7 @@ +pub enum Event { + Startup, + Shutdown, + TaskExecuted(String), + PluginLoaded(String), + Error(String), +} \ No newline at end of file diff --git a/mist-test/src/logger.mist b/mist-test/src/logger.mist new file mode 100644 index 0000000..ab194cd --- /dev/null +++ b/mist-test/src/logger.mist @@ -0,0 +1,78 @@ +use ; +use ; + +pub trait TestLogging: fmt::Display { + String get(self*); +} + +pub enum LogLevel { + Info, + Warning, + Error, +} + +impl fmt::Display for LogLevel { + fmt::Result fmt(self*, Formatter<'_> mut* f) { + match (self) { + LogLevel::Info => { + return write!(f, "[INFO]"); + } + + LogLevel::Warning => { + return write!(f, "[WARN]"); + } + + LogLevel::Error => { + return write!(f, "[ERROR]"); + } + } + } +} + +impl TestLogging for LogLevel { + String get(self*) { + return format!("{self}"); + } +} + +pub class Logger { + String prefix; + + pub constructor(str* prefix) { + self.prefix = prefix.to_string(); + } + + pub void info(self*, str* message) { + self.log(LogLevel::Info, message); + } + + pub void warning(self*, str* message) { + self.log(LogLevel::Warning, message); + } + + pub void error(self*, str* message) { + self.log(LogLevel::Error, message); + } + + void log(self*, LogLevel level, str* message) { + match(level) { + LogLevel::Info => { + println!("{level} {} {}", self.prefix, message); + } + + LogLevel::Warning => { + println!("{} {} {}", level.get(), self.prefix, message); + } + + LogLevel::Error => { + println!("{level} {} {}", self.prefix, message); + } + } + } + + impl fmt::Display { + fmt::Result fmt(self*, Formatter<'_> mut* f) { + return write!(f, "logger ({})", self.prefix); + } + } +} \ No newline at end of file diff --git a/mist-test/src/main.mist b/mist-test/src/main.mist index db84371..3729e97 100644 --- a/mist-test/src/main.mist +++ b/mist-test/src/main.mist @@ -1,17 +1,12 @@ +pub mod app; +pub mod task; +pub mod plugin; +pub mod logger; +pub mod event; + void main() { - i32 mut x = 10; + var mut app_instance = new app::Application("mist-app"); - x = 1 + 1; - - x++; - - if (1 == 1) { - println!("Yes!"); - } - - i32 y = if (x == 3) { 1 } else { 0 }; - - println!("hello, world {x}"); - - println!("{y}") -} + app_instance.boot(); + app_instance.run(); +} \ No newline at end of file diff --git a/mist-test/src/plugin.mist b/mist-test/src/plugin.mist new file mode 100644 index 0000000..a3d16ba --- /dev/null +++ b/mist-test/src/plugin.mist @@ -0,0 +1,16 @@ +pub struct PluginInfo { + pub String name, + pub String version, +} + +pub class PluginRegistry { + T plugins; + + pub constructor(T plugins) { + self.plugins = plugins; + } + + pub T plugins(self) { + return self.plugins; + } +} \ No newline at end of file diff --git a/mist-test/src/task.mist b/mist-test/src/task.mist new file mode 100644 index 0000000..d902258 --- /dev/null +++ b/mist-test/src/task.mist @@ -0,0 +1,20 @@ +pub enum TaskState { + Pending, + Running, + Finished, + Failed, +} + +pub struct Task { + pub String name, + pub TaskState state, + pub i32 executions, +} + +pub Task create_task(str* name) { + return Task { + name: name.to_string(), + state: TaskState::Pending, + executions: 0, + }; +} \ No newline at end of file diff --git a/parser/src/grammar.pest b/parser/src/grammar.pest index a6bac5d..35e60e3 100644 --- a/parser/src/grammar.pest +++ b/parser/src/grammar.pest @@ -29,7 +29,6 @@ keyword = { | "true" | "false" | "dyn" - | "self" } identifier = @{ @@ -343,7 +342,7 @@ block = { } statement_list = { - (statement | (!expr ~ unexpected_statement))* + (statement | (unexpected_statement))* } statement = _{ diff --git a/parser/src/parser/common/expr.rs b/parser/src/parser/common/expr.rs index de33878..86dd684 100644 --- a/parser/src/parser/common/expr.rs +++ b/parser/src/parser/common/expr.rs @@ -78,7 +78,7 @@ impl<'a> TryFrom> for Expression { Rule::static_path => ast_expr!(Expression::Path(pair.try_into())), Rule::literal => ast_expr!(Expression::Literal(pair.try_into())), Rule::expr_path => ast_expr!(Expression::Path(pair.try_into())), - Rule::statement | Rule::basic_stmt | Rule::control_flow => ast_expr!( + Rule::statement | Rule::basic_stmt | Rule::control_flow | Rule::unexpected_statement => ast_expr!( Expression::Statement(pair.try_into().get_map(Box::new).map(Box::new)) ),