Merge pull request #27 from mist-go/refactor-visibility
Refactor visibility
This commit is contained in:
@@ -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,4 +1,4 @@
|
|||||||
public enum Event {
|
pub enum Event {
|
||||||
Startup,
|
Startup,
|
||||||
Shutdown,
|
Shutdown,
|
||||||
TaskExecuted(String),
|
TaskExecuted(String),
|
||||||
|
|||||||
@@ -1,17 +1,18 @@
|
|||||||
|
use <std::fmt::Formatter>;
|
||||||
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,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for LogLevel {
|
impl fmt::Display for LogLevel {
|
||||||
std::fmt::Result fmt(self*, std::fmt::Formatter<'_> mut* f) {
|
fmt::Result fmt(self*, Formatter<'_> mut* f) {
|
||||||
match (self) {
|
match (self) {
|
||||||
LogLevel::Info => {
|
LogLevel::Info => {
|
||||||
return write!(f, "[INFO]");
|
return write!(f, "[INFO]");
|
||||||
@@ -28,22 +29,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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,7 +65,7 @@ public class Logger {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display {
|
impl fmt::Display {
|
||||||
std::fmt::Result fmt(self*, std::fmt::Formatter<'_> mut* f) {
|
fmt::Result fmt(self*, Formatter<'_> mut* f) {
|
||||||
return write!(f, "logger ({})", self.prefix);
|
return write!(f, "logger ({})", self.prefix);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
mod app;
|
pub mod app;
|
||||||
mod task;
|
pub mod task;
|
||||||
mod plugin;
|
pub mod plugin;
|
||||||
mod logger;
|
pub mod logger;
|
||||||
mod event;
|
pub mod event;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
var mut app_instance = new app::Application("mist-app");
|
var mut app_instance = new app::Application("mist-app");
|
||||||
|
|||||||
@@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -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,
|
||||||
|
|||||||
+3
-2
@@ -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,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,8 +73,8 @@ pub struct TopLevel(pub TopLevelKind, pub Vec<Attribute>);
|
|||||||
#[derive(Debug, Clone, Serialize)]
|
#[derive(Debug, Clone, Serialize)]
|
||||||
pub enum TopLevelKind {
|
pub enum TopLevelKind {
|
||||||
ModAttribute,
|
ModAttribute,
|
||||||
Import(Path),
|
Import(Visibility, Path),
|
||||||
Mod(Identifier),
|
Mod(Visibility, Identifier),
|
||||||
ImplDecl(ImplDecl),
|
ImplDecl(ImplDecl),
|
||||||
TraitDecl {
|
TraitDecl {
|
||||||
visibility: Visibility,
|
visibility: Visibility,
|
||||||
|
|||||||
+14
-14
@@ -48,9 +48,9 @@ program = {
|
|||||||
// MODIFIERS
|
// MODIFIERS
|
||||||
// ======================================================
|
// ======================================================
|
||||||
|
|
||||||
export = { "public" }
|
visibility = { "pub" ~ ("(" ~ static_path ~ ")")? }
|
||||||
mutable = { "mut" }
|
mutable = { "mut" }
|
||||||
var = { "var" }
|
var = { "var" }
|
||||||
|
|
||||||
// ======================================================
|
// ======================================================
|
||||||
// GENERICS
|
// GENERICS
|
||||||
@@ -154,7 +154,7 @@ var_decl = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
field = {
|
field = {
|
||||||
export? ~ type_expr ~ identifier
|
visibility? ~ type_expr ~ identifier
|
||||||
}
|
}
|
||||||
|
|
||||||
field_list = {
|
field_list = {
|
||||||
@@ -170,11 +170,11 @@ param_list = {
|
|||||||
// ======================================================
|
// ======================================================
|
||||||
|
|
||||||
import = {
|
import = {
|
||||||
"use" ~ "<" ~ static_path ~ ">" ~ semicolon
|
visibility? ~ "use" ~ "<" ~ static_path ~ ">" ~ semicolon
|
||||||
}
|
}
|
||||||
|
|
||||||
mod_package = {
|
mod_package = {
|
||||||
"mod" ~ identifier ~ semicolon
|
visibility? ~ "mod" ~ identifier ~ semicolon
|
||||||
}
|
}
|
||||||
|
|
||||||
// ======================================================
|
// ======================================================
|
||||||
@@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
// ======================================================
|
// ======================================================
|
||||||
|
|||||||
+17
-7
@@ -260,7 +260,10 @@ impl From<pest::iterators::Pair<'_, Rule>> for TopLevelKind {
|
|||||||
let mut inner = pair.clone().into_inner();
|
let mut inner = pair.clone().into_inner();
|
||||||
|
|
||||||
match rule {
|
match rule {
|
||||||
Rule::import => TopLevelKind::Import(Path::from(inner.next().unwrap())),
|
Rule::import => TopLevelKind::Import(
|
||||||
|
Visibility::from(&mut inner),
|
||||||
|
Path::from(inner.next().unwrap()),
|
||||||
|
),
|
||||||
|
|
||||||
Rule::function_decl => TopLevelKind::FunctionDecl(FunctionDecl::from(pair)),
|
Rule::function_decl => TopLevelKind::FunctionDecl(FunctionDecl::from(pair)),
|
||||||
|
|
||||||
@@ -301,7 +304,10 @@ impl From<pest::iterators::Pair<'_, Rule>> for TopLevelKind {
|
|||||||
fields: inner.map(EnumItem::from).collect(),
|
fields: inner.map(EnumItem::from).collect(),
|
||||||
},
|
},
|
||||||
|
|
||||||
Rule::mod_package => TopLevelKind::Mod(Identifier::from(inner.next().unwrap())),
|
Rule::mod_package => TopLevelKind::Mod(
|
||||||
|
Visibility::from(&mut inner),
|
||||||
|
Identifier::from(inner.next().unwrap()),
|
||||||
|
),
|
||||||
|
|
||||||
Rule::impl_for_decl | Rule::impl_decl => TopLevelKind::ImplDecl(ImplDecl::from(pair)),
|
Rule::impl_for_decl | Rule::impl_decl => TopLevelKind::ImplDecl(ImplDecl::from(pair)),
|
||||||
|
|
||||||
@@ -791,11 +797,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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+7
-5
@@ -312,8 +312,10 @@ impl ToRust for TopLevelKind {
|
|||||||
fn to_rust(&self, cg: &mut RustCodegen) {
|
fn to_rust(&self, cg: &mut RustCodegen) {
|
||||||
match self {
|
match self {
|
||||||
Self::ModAttribute => {}
|
Self::ModAttribute => {}
|
||||||
Self::Import(path) => cg.addln(&format!("use {};", path.get_rust())),
|
Self::Import(vis, path) => {
|
||||||
Self::Mod(id) => cg.addln(&format!("mod {};", id.get_rust())),
|
cg.addln(&format!("{} use {};", vis.get_rust(), path.get_rust()))
|
||||||
|
}
|
||||||
|
Self::Mod(vis, id) => cg.addln(&format!("{} mod {};", vis.get_rust(), id.get_rust())),
|
||||||
Self::FunctionDecl(decl) => decl.to_rust(cg),
|
Self::FunctionDecl(decl) => decl.to_rust(cg),
|
||||||
Self::ImplDecl(impl_) => impl_.to_rust(cg),
|
Self::ImplDecl(impl_) => impl_.to_rust(cg),
|
||||||
Self::StructDecl {
|
Self::StructDecl {
|
||||||
@@ -739,10 +741,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()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user