Prefix
This commit is contained in:
+2
-2
@@ -73,7 +73,7 @@ pub enum Postfix {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize)]
|
#[derive(Debug, Clone, Serialize)]
|
||||||
pub enum PreFix {
|
pub enum Prefix {
|
||||||
Ref,
|
Ref,
|
||||||
RefMut,
|
RefMut,
|
||||||
Deref,
|
Deref,
|
||||||
@@ -144,7 +144,7 @@ pub enum Expression {
|
|||||||
StringLiteral(String),
|
StringLiteral(String),
|
||||||
Fix {
|
Fix {
|
||||||
initial: Box<Expression>,
|
initial: Box<Expression>,
|
||||||
prefixes: Vec<PreFix>,
|
prefixes: Vec<Prefix>,
|
||||||
postfixes: Vec<Postfix>,
|
postfixes: Vec<Postfix>,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -282,7 +282,7 @@ impl From<pest::iterators::Pair<'_, Rule>> for Expression {
|
|||||||
.map(|v| v.as_rule() == Rule::prefix)
|
.map(|v| v.as_rule() == Rule::prefix)
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
{
|
{
|
||||||
prefixes.push(PreFix::from(inner.next().unwrap()));
|
prefixes.push(Prefix::from(inner.next().unwrap()));
|
||||||
}
|
}
|
||||||
|
|
||||||
println!("{:#?}", prefixes);
|
println!("{:#?}", prefixes);
|
||||||
@@ -326,7 +326,7 @@ impl From<pest::iterators::Pair<'_, Rule>> for Expression {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<pest::iterators::Pair<'_, Rule>> for PreFix {
|
impl From<pest::iterators::Pair<'_, Rule>> for Prefix {
|
||||||
fn from(pair: pest::iterators::Pair<Rule>) -> Self {
|
fn from(pair: pest::iterators::Pair<Rule>) -> Self {
|
||||||
match pair.as_rule() {
|
match pair.as_rule() {
|
||||||
Rule::prefix => Self::from(pair.into_inner().next().unwrap()),
|
Rule::prefix => Self::from(pair.into_inner().next().unwrap()),
|
||||||
|
|||||||
+20
-3
@@ -1,6 +1,6 @@
|
|||||||
use parser::ast::{
|
use parser::ast::{
|
||||||
BinaryOp, Block, Expression, IfStmt, Postfix, Statement, StaticPath, TopLevel, TypeExpr,
|
BinaryOp, Block, Expression, IfStmt, Postfix, Prefix, Statement, StaticPath, TopLevel,
|
||||||
TypeExprKind, TypePostfix, VarAssignStmt, VarDecl, VarDeclStmt, WhileStmt,
|
TypeExpr, TypeExprKind, TypePostfix, VarAssignStmt, VarDecl, VarDeclStmt, WhileStmt,
|
||||||
};
|
};
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
@@ -118,11 +118,28 @@ impl GetRust for Expression {
|
|||||||
initial,
|
initial,
|
||||||
prefixes,
|
prefixes,
|
||||||
postfixes,
|
postfixes,
|
||||||
} => initial.get_rust() + &postfixes.get_rust(),
|
} => prefixes.get_rust() + &initial.get_rust() + &postfixes.get_rust(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl GetRust for Prefix {
|
||||||
|
fn get_rust(&self) -> String {
|
||||||
|
match self {
|
||||||
|
Self::Deref => "*",
|
||||||
|
Self::Ref => "&",
|
||||||
|
Self::RefMut => "&mut ",
|
||||||
|
}
|
||||||
|
.to_string()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl GetRust for [Prefix] {
|
||||||
|
fn get_rust(&self) -> String {
|
||||||
|
self.iter().map(Prefix::get_rust).collect()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl GetRust for Postfix {
|
impl GetRust for Postfix {
|
||||||
fn get_rust(&self) -> String {
|
fn get_rust(&self) -> String {
|
||||||
match self {
|
match self {
|
||||||
|
|||||||
Reference in New Issue
Block a user