Impl grammar
This commit is contained in:
@@ -1,9 +1,29 @@
|
||||
use <std::fmt>;
|
||||
|
||||
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;
|
||||
|
||||
|
||||
+18
-2
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user