diff --git a/mist-test/src/logger.mist b/mist-test/src/logger.mist index 94c4b4a..2b567eb 100644 --- a/mist-test/src/logger.mist +++ b/mist-test/src/logger.mist @@ -1,9 +1,29 @@ +use ; + public enum LogLevel { Info, Warning, Error, } +impl fmt::Display for LogLevel { + std::fmt::Result fmt(self*, std::fmt::Formatter<'_> mut* f) { + match (self) { + LogLevel::Info => { + write!(f, "[INFO]"); + } + + LogLevel::Warning => { + write!(f, "[WARN]"); + } + + LogLevel::Error => { + write!(f, "[ERROR]"); + } + } + } +} + public class Logger { String prefix; diff --git a/parser/src/grammar.pest b/parser/src/grammar.pest index 7d99a5d..afc0ea4 100644 --- a/parser/src/grammar.pest +++ b/parser/src/grammar.pest @@ -239,8 +239,24 @@ method = { export? ~ type_expr ~ identifier ~ generics? ~ "(" ~ self_param? ~ ("," ~ param_list?)? ~ ")" ~ block } +class_item = _{ + impl_decl + | method +} + class_decl = { - export? ~ "class" ~ identifier ~ generics? ~ "{" ~ class_fields ~ class_constructor ~ method* ~ "}" + export? ~ "class" ~ identifier ~ generics? ~ "{" ~ class_fields ~ class_constructor ~ class_item* ~ "}" +} + +// ====================================================== +// IMPL +// ====================================================== +impl_for_decl = { + "impl" ~ generics? ~ type_expr ~ "for" ~ type_expr ~ "{" ~ method* ~ "}" +} + +impl_decl = { + "impl" ~ generics? ~ type_expr ~ "{" ~ method* ~ "}" } // ====================================================== @@ -256,7 +272,7 @@ function_decl = { // ====================================================== top_level = { - (attributes ~ (import | function_decl | struct_decl | enum_decl | class_decl | mod_package)) + (attributes ~ (import | impl_for_decl | impl_decl | function_decl | struct_decl | enum_decl | class_decl | mod_package)) | mod_attribute }