Refactor publicity system

This commit is contained in:
2026-05-13 05:48:59 +02:00
parent e416af3403
commit c1cb9bd7bf
9 changed files with 49 additions and 44 deletions
+6 -6
View File
@@ -2,7 +2,7 @@ use <super::task>;
use <super::logger>; use <super::logger>;
use <super::event>; use <super::event>;
public class Application { pub class Application {
String name; String name;
Vec<task::Task> tasks; Vec<task::Task> tasks;
@@ -13,7 +13,7 @@ public class Application {
bool running; bool running;
i32 ticks; i32 ticks;
public constructor(str* name) { pub constructor(str* name) {
self.name = name.to_string(); self.name = name.to_string();
self.tasks = new Vec(); self.tasks = new Vec();
@@ -25,7 +25,7 @@ public class Application {
self.ticks = 0; self.ticks = 0;
} }
public void boot(self mut*) { pub void boot(self mut*) {
self.logger.info("booting application"); self.logger.info("booting application");
self.running = true; self.running = true;
@@ -33,7 +33,7 @@ public class Application {
self.emit(event::Event::Startup); self.emit(event::Event::Startup);
} }
public void run(self mut*) { pub void run(self mut*) {
while(self.running) { while(self.running) {
self.tick(); self.tick();
@@ -55,7 +55,7 @@ public class Application {
println!("tasks: {}", self.tasks.len()); println!("tasks: {}", self.tasks.len());
} }
public void shutdown(self mut*) { pub void shutdown(self mut*) {
self.emit(event::Event::Shutdown); self.emit(event::Event::Shutdown);
self.logger.warning("shutdown"); self.logger.warning("shutdown");
@@ -63,7 +63,7 @@ public class Application {
self.running = false; self.running = false;
} }
public void register_plugin(self mut*, String name) { pub void register_plugin(self mut*, String name) {
self.plugins.push(name.clone()); self.plugins.push(name.clone());
self.emit(event::Event::PluginLoaded(name)); self.emit(event::Event::PluginLoaded(name));
+1 -1
View File
@@ -1,4 +1,4 @@
public enum Event { pub enum Event {
Startup, Startup,
Shutdown, Shutdown,
TaskExecuted(String), TaskExecuted(String),
+7 -7
View File
@@ -1,10 +1,10 @@
use <std::fmt>; use <std::fmt>;
public trait TestLogging<T: fmt::Display>: fmt::Display { pub trait TestLogging<T: fmt::Display>: fmt::Display {
String get(); String get();
} }
public enum LogLevel { pub enum LogLevel {
Info, Info,
Warning, Warning,
Error, Error,
@@ -28,22 +28,22 @@ impl fmt::Display for LogLevel {
} }
} }
public class Logger { pub class Logger {
String prefix; String prefix;
public constructor(str* prefix) { pub constructor(str* prefix) {
self.prefix = prefix.to_string(); self.prefix = prefix.to_string();
} }
public void info(self*, str* message) { pub void info(self*, str* message) {
self.log(LogLevel::Info, message); self.log(LogLevel::Info, message);
} }
public void warning(self*, str* message) { pub void warning(self*, str* message) {
self.log(LogLevel::Warning, message); self.log(LogLevel::Warning, message);
} }
public void error(self*, str* message) { pub void error(self*, str* message) {
self.log(LogLevel::Error, message); self.log(LogLevel::Error, message);
} }
+6 -6
View File
@@ -1,16 +1,16 @@
public struct PluginInfo { pub struct PluginInfo {
public String name, pub String name,
public String version, pub String version,
} }
public class PluginRegistry<T> { pub class PluginRegistry<T> {
T plugins; T plugins;
public constructor(T plugins) { pub constructor(T plugins) {
self.plugins = plugins; self.plugins = plugins;
} }
public T plugins(self) { pub T plugins(self) {
return self.plugins; return self.plugins;
} }
} }
+6 -6
View File
@@ -1,17 +1,17 @@
public enum TaskState { pub enum TaskState {
Pending, Pending,
Running, Running,
Finished, Finished,
Failed, Failed,
} }
public struct Task { pub struct Task {
public String name, pub String name,
public TaskState state, pub TaskState state,
public i32 executions, pub i32 executions,
} }
public Task create_task(str* name) { pub Task create_task(str* name) {
return Task { return Task {
name: name.to_string(), name: name.to_string(),
state: TaskState::Pending, state: TaskState::Pending,
+1
View File
@@ -20,6 +20,7 @@ pub enum TypePostfix {
#[derive(Debug, Clone, Serialize)] #[derive(Debug, Clone, Serialize)]
pub enum Visibility { pub enum Visibility {
Public, Public,
PublicTarget(Path),
Private, Private,
} }
+10 -10
View File
@@ -48,7 +48,7 @@ program = {
// MODIFIERS // MODIFIERS
// ====================================================== // ======================================================
export = { "public" } visibility = { "pub" ~ ("(" ~ static_path ~ ")")? }
mutable = { "mut" } mutable = { "mut" }
var = { "var" } var = { "var" }
@@ -154,7 +154,7 @@ var_decl = {
} }
field = { field = {
export? ~ type_expr ~ identifier visibility? ~ type_expr ~ identifier
} }
field_list = { field_list = {
@@ -182,7 +182,7 @@ mod_package = {
// ====================================================== // ======================================================
struct_decl = { struct_decl = {
export? ~ "struct" ~ identifier ~ generics? ~ "{" ~ field_list? ~ "}" visibility? ~ "struct" ~ identifier ~ generics? ~ "{" ~ field_list? ~ "}"
} }
// ====================================================== // ======================================================
@@ -212,7 +212,7 @@ enum_fields = _{
} }
enum_decl = { enum_decl = {
export? ~ "enum" ~ identifier ~ generics? ~ "{" ~ enum_fields ~ "}" visibility? ~ "enum" ~ identifier ~ generics? ~ "{" ~ enum_fields ~ "}"
} }
// ====================================================== // ======================================================
@@ -220,7 +220,7 @@ enum_decl = {
// ====================================================== // ======================================================
class_constructor = { class_constructor = {
export? ~ "constructor" ~ generics? ~ "(" ~ param_list? ~ ")" ~ block visibility? ~ "constructor" ~ generics? ~ "(" ~ param_list? ~ ")" ~ block
} }
class_fields = { class_fields = {
@@ -236,7 +236,7 @@ self_param = {
} }
method = { method = {
export? ~ type_expr ~ identifier ~ generics? ~ "(" ~ self_param? ~ ("," ~ param_list?)? ~ ")" ~ block visibility? ~ type_expr ~ identifier ~ generics? ~ "(" ~ self_param? ~ ("," ~ param_list?)? ~ ")" ~ block
} }
class_item = _{ class_item = _{
@@ -245,7 +245,7 @@ class_item = _{
} }
class_decl = { class_decl = {
export? ~ "class" ~ identifier ~ generics? ~ "{" ~ class_fields ~ class_constructor ~ class_item* ~ "}" visibility? ~ "class" ~ identifier ~ generics? ~ "{" ~ class_fields ~ class_constructor ~ class_item* ~ "}"
} }
// ====================================================== // ======================================================
@@ -265,7 +265,7 @@ impl_decl = {
trait_requirements = { ":" ~ type_expr_param ~ ("+" ~ type_expr_param)* } trait_requirements = { ":" ~ type_expr_param ~ ("+" ~ type_expr_param)* }
method_no_body = { method_no_body = {
export? ~ type_expr ~ identifier ~ generics? ~ "(" ~ self_param? ~ ("," ~ param_list?)? ~ ")" ~ semicolon visibility? ~ type_expr ~ identifier ~ generics? ~ "(" ~ self_param? ~ ("," ~ param_list?)? ~ ")" ~ semicolon
} }
trait_item = _{ trait_item = _{
@@ -274,7 +274,7 @@ trait_item = _{
} }
trait_decl = { trait_decl = {
export? ~ "trait" ~ identifier ~ generics? ~ trait_requirements? ~ "{" ~ trait_item* ~ "}" visibility? ~ "trait" ~ identifier ~ generics? ~ trait_requirements? ~ "{" ~ trait_item* ~ "}"
} }
// ====================================================== // ======================================================
@@ -282,7 +282,7 @@ trait_decl = {
// ====================================================== // ======================================================
function_decl = { function_decl = {
export? ~ type_expr ~ identifier ~ "(" ~ param_list? ~ ")" ~ block visibility? ~ type_expr ~ identifier ~ "(" ~ param_list? ~ ")" ~ block
} }
// ====================================================== // ======================================================
+9 -5
View File
@@ -791,11 +791,15 @@ impl From<pest::iterators::Pair<'_, Rule>> for FunctionDecl {
impl From<&mut pest::iterators::Pairs<'_, Rule>> for Visibility { impl From<&mut pest::iterators::Pairs<'_, Rule>> for Visibility {
fn from(pairs: &mut pest::iterators::Pairs<'_, Rule>) -> Self { fn from(pairs: &mut pest::iterators::Pairs<'_, Rule>) -> Self {
if listen_rule(pairs, Rule::export) { consume_rule(pairs, Rule::visibility)
Visibility::Public .map(|pair| {
} else { if let Some(path) = pair.into_inner().next() {
Visibility::Private Visibility::PublicTarget(Path::from(path))
} } else {
Visibility::Public
}
})
.unwrap_or_else(|| Visibility::Private)
} }
} }
+3 -3
View File
@@ -739,10 +739,10 @@ impl GetRust for TypePostfix {
impl GetRust for Visibility { impl GetRust for Visibility {
fn get_rust(&self) -> String { fn get_rust(&self) -> String {
match self { match self {
Visibility::Public => "pub ", Visibility::Public => "pub ".to_string(),
Visibility::Private => "", Visibility::PublicTarget(path) => format!("pub({}) ", path.get_rust()),
Visibility::Private => "".to_string(),
} }
.to_string()
} }
} }