pattern grammar and ast
This commit is contained in:
@@ -92,6 +92,14 @@ pub enum TopLevelKind {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize)]
|
||||||
|
pub enum Pattern {
|
||||||
|
Tuple(Path, Vec<Identifier>),
|
||||||
|
Struct(Path, Vec<Identifier>),
|
||||||
|
Path(Path),
|
||||||
|
Id(Identifier),
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize)]
|
#[derive(Debug, Clone, Serialize)]
|
||||||
pub enum EnumItem {
|
pub enum EnumItem {
|
||||||
Named(Identifier),
|
Named(Identifier),
|
||||||
|
|||||||
@@ -12,10 +12,15 @@ string_lit = { "\"" ~ inner_str ~ "\"" }
|
|||||||
inner_str = @{ (!"\"" ~ ("\\\"" | ANY))* }
|
inner_str = @{ (!"\"" ~ ("\\\"" | ANY))* }
|
||||||
static_path = { identifier ~ ("::" ~ identifier)* }
|
static_path = { identifier ~ ("::" ~ identifier)* }
|
||||||
|
|
||||||
|
// pattern
|
||||||
|
tuple_pattern = { static_path ~ "(" ~ (identifier ~ ("," ~ identifier)*)? ~ ")" }
|
||||||
|
struct_pattern = { static_path ~ "{" ~ (identifier ~ ("," ~ identifier)*)? ~ "}" }
|
||||||
|
pattern = _{ tuple_pattern | struct_pattern | identifier }
|
||||||
|
|
||||||
export = { "public" }
|
export = { "public" }
|
||||||
mutable = { "mut" }
|
mutable = { "mut" }
|
||||||
var = { "var" }
|
var = { "var" }
|
||||||
var_decl = { (var | type_expr) ~ mutable? ~ identifier }
|
var_decl = { (var | type_expr) ~ mutable? ~ pattern }
|
||||||
semicolon = _{ ";" }
|
semicolon = _{ ";" }
|
||||||
|
|
||||||
// ================= CLASS =================
|
// ================= CLASS =================
|
||||||
|
|||||||
Reference in New Issue
Block a user