Class method AST and grammar
This commit is contained in:
@@ -89,6 +89,15 @@ pub struct ClassConstructor {
|
||||
pub body: Block,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct ClassMethod {
|
||||
export: bool,
|
||||
name: String,
|
||||
params: ParamList,
|
||||
return_type: TypeExpr,
|
||||
body: Block,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub enum Postfix {
|
||||
FieldAccess(String),
|
||||
|
||||
@@ -26,7 +26,13 @@ class_constructor = {
|
||||
|
||||
class_fields = { var_decl_statement* }
|
||||
|
||||
class_methods = { function_decl* }
|
||||
class_methods = { method* }
|
||||
|
||||
self_param = { "self" ~ mutable? ~ deref_px? }
|
||||
|
||||
method = {
|
||||
export? ~ type_expr ~ identifier ~ "(" ~ self_param? ~ param_list? ~ ")" ~ block
|
||||
}
|
||||
|
||||
class_decl = {
|
||||
"class" ~ identifier ~ "{" ~ class_fields ~ class_constructor ~ class_methods ~ "}"
|
||||
@@ -167,7 +173,7 @@ prefix = {
|
||||
deref_px
|
||||
| mut_ref_px
|
||||
| ref_px
|
||||
| new_px
|
||||
| new_px
|
||||
}
|
||||
|
||||
deref_px = { "*" }
|
||||
|
||||
Reference in New Issue
Block a user