diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2024-05-01 16:09:34 +0200 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2024-05-01 16:09:34 +0200 |
commit | 284564933c991d2f65f7c81bd8f4cf525ad93408 (patch) | |
tree | b937fb81460d0a11b12122976b05b20c01a2bdf5 /crates | |
parent | 8d15e1ab1c3c3bca3c794c5f1499e0108d60d42f (diff) | |
download | rebel-284564933c991d2f65f7c81bd8f4cf525ad93408.tar rebel-284564933c991d2f65f7c81bd8f4cf525ad93408.zip |
rebel-parse, rebel-lang: rename base "expr"/"pat" fields to "base" in index/field projection
Diffstat (limited to 'crates')
-rw-r--r-- | crates/rebel-lang/src/scope.rs | 16 | ||||
-rw-r--r-- | crates/rebel-lang/src/typing.rs | 16 | ||||
-rw-r--r-- | crates/rebel-lang/src/value.rs | 16 | ||||
-rw-r--r-- | crates/rebel-parse/src/ast/expr.rs | 26 | ||||
-rw-r--r-- | crates/rebel-parse/src/ast/pat.rs | 10 | ||||
-rw-r--r-- | crates/rebel-parse/src/grammar/recipe.rs | 12 |
6 files changed, 48 insertions, 48 deletions
diff --git a/crates/rebel-lang/src/scope.rs b/crates/rebel-lang/src/scope.rs index 1c6d52f..01c71ad 100644 --- a/crates/rebel-lang/src/scope.rs +++ b/crates/rebel-lang/src/scope.rs @@ -114,14 +114,14 @@ impl Context { fn lookup_destr_pat_var_type_mut(&mut self, pat: &pat::DestrPat) -> Result<&mut Type> { Ok(match pat { - pat::DestrPat::Index { pat, index: _ } => { - match self.lookup_destr_pat_var_type_mut(pat)? { + pat::DestrPat::Index { base, index: _ } => { + match self.lookup_destr_pat_var_type_mut(base)? { Type::Array(inner) => inner.as_mut(), _ => return Err(LookupError), } } - pat::DestrPat::Field { pat, field } => { - match self.lookup_destr_pat_var_type_mut(pat)? { + pat::DestrPat::Field { base, field } => { + match self.lookup_destr_pat_var_type_mut(base)? { Type::Struct(entries) => entries.get_mut(field.name).ok_or(LookupError)?, _ => return Err(LookupError), } @@ -136,7 +136,7 @@ impl Context { pat: &pat::DestrPat, ) -> Result<(&mut Type, ValueSlot)> { Ok(match pat { - pat::DestrPat::Index { pat, index } => { + pat::DestrPat::Index { base, index } => { let index = usize::try_from(match Value::eval(self, index).or(Err(LookupError))? { Value::Int(index) => index, @@ -145,7 +145,7 @@ impl Context { } }) .or(Err(LookupError))?; - let (typ, value) = self.lookup_destr_pat_var_type_value_mut(pat)?; + let (typ, value) = self.lookup_destr_pat_var_type_value_mut(base)?; let (inner_type, inner_value) = match (typ, value.into_inner().ok_or(LookupError)?) { (Type::Array(inner_type), Value::Array(inner_value)) => ( @@ -156,8 +156,8 @@ impl Context { }; (inner_type, ValueSlot::Value(inner_value)) } - pat::DestrPat::Field { pat, field } => { - let (typ, value) = self.lookup_destr_pat_var_type_value_mut(pat)?; + pat::DestrPat::Field { base, field } => { + let (typ, value) = self.lookup_destr_pat_var_type_value_mut(base)?; let (inner_type, inner_value) = match (typ, value.into_inner().ok_or(LookupError)?) { (Type::Struct(type_entries), Value::Struct(value_entries)) => ( diff --git a/crates/rebel-lang/src/typing.rs b/crates/rebel-lang/src/typing.rs index a441b1c..c826acf 100644 --- a/crates/rebel-lang/src/typing.rs +++ b/crates/rebel-lang/src/typing.rs @@ -129,8 +129,8 @@ impl Type { method, params, } => Self::method_expr_type(ctx, expr, method, params)?, - Index { expr, index } => Self::index_expr_type(ctx, expr, index)?, - Field { expr, field } => Self::field_expr_type(ctx, expr, field)?, + Index { base, index } => Self::index_expr_type(ctx, base, index)?, + Field { base, field } => Self::field_expr_type(ctx, base, field)?, Paren(subexpr) => Self::ast_expr_type(ctx, subexpr)?, Path(path) => Self::path_expr_type(ctx, path)?, Literal(lit) => Self::literal_expr_type(ctx, lit)?, @@ -198,15 +198,15 @@ impl Type { fn index_expr_type( ctx: &Context, - expr: &expr::Expr<'_>, + base: &expr::Expr<'_>, index: &expr::Expr<'_>, ) -> Result<Type> { use Type::*; - let expr_type = Self::ast_expr_type(ctx, expr)?; + let base_type = Self::ast_expr_type(ctx, base)?; let index_type = Self::ast_expr_type(ctx, index)?; - let Array(elem_type) = expr_type else { + let Array(elem_type) = base_type else { return Err(TypeError); }; if index_type != Int { @@ -273,15 +273,15 @@ impl Type { fn field_expr_type( ctx: &Context, - expr: &expr::Expr<'_>, + base: &expr::Expr<'_>, field: &ast::Ident<'_>, ) -> Result<Type> { use Type::*; - let expr_type = Self::ast_expr_type(ctx, expr)?; + let base_type = Self::ast_expr_type(ctx, base)?; let name = field.name; - Ok(match expr_type { + Ok(match base_type { Tuple(elems) => { let index: usize = name.parse().or(Err(TypeError))?; elems.into_iter().nth(index).ok_or(TypeError)? diff --git a/crates/rebel-lang/src/value.rs b/crates/rebel-lang/src/value.rs index f7bffbb..5b56815 100644 --- a/crates/rebel-lang/src/value.rs +++ b/crates/rebel-lang/src/value.rs @@ -71,8 +71,8 @@ impl Value { method, params, } => Self::eval_method(ctx, expr, method, params)?, - Index { expr, index } => Self::eval_index(ctx, expr, index)?, - Field { expr, field } => Self::eval_field(ctx, expr, field)?, + Index { base, index } => Self::eval_index(ctx, base, index)?, + Field { base, field } => Self::eval_field(ctx, base, field)?, Paren(subexpr) => Self::eval(ctx, subexpr)?, Path(path) => Self::eval_path(ctx, path)?, Literal(lit) => Self::eval_literal(ctx, lit)?, @@ -134,13 +134,13 @@ impl Value { }) } - fn eval_index(ctx: &Context, expr: &expr::Expr<'_>, index: &expr::Expr<'_>) -> Result<Value> { + fn eval_index(ctx: &Context, base: &expr::Expr<'_>, index: &expr::Expr<'_>) -> Result<Value> { use Value::*; - let expr_value = Self::eval(ctx, expr)?; + let base_value = Self::eval(ctx, base)?; let index_value = Self::eval(ctx, index)?; - let Array(elems) = expr_value else { + let Array(elems) = base_value else { return Err(EvalError); }; let Int(index) = index_value else { @@ -228,13 +228,13 @@ impl Value { } } - fn eval_field(ctx: &Context, expr: &expr::Expr<'_>, field: &ast::Ident<'_>) -> Result<Value> { + fn eval_field(ctx: &Context, base: &expr::Expr<'_>, field: &ast::Ident<'_>) -> Result<Value> { use Value::*; - let expr_value = Self::eval(ctx, expr)?; + let base_value = Self::eval(ctx, base)?; let name = field.name; - Ok(match expr_value { + Ok(match base_value { Tuple(elems) => { let index: usize = name.parse().or(Err(EvalError))?; elems.into_iter().nth(index).ok_or(EvalError)? diff --git a/crates/rebel-parse/src/ast/expr.rs b/crates/rebel-parse/src/ast/expr.rs index fda37e8..429dfa2 100644 --- a/crates/rebel-parse/src/ast/expr.rs +++ b/crates/rebel-parse/src/ast/expr.rs @@ -26,11 +26,11 @@ pub enum Expr<'a> { params: Vec<Expr<'a>>, }, Index { - expr: Box<Expr<'a>>, + base: Box<Expr<'a>>, index: Box<Expr<'a>>, }, Field { - expr: Box<Expr<'a>>, + base: Box<Expr<'a>>, field: Ident<'a>, }, Paren(Box<Expr<'a>>), @@ -69,16 +69,16 @@ impl<'a> Expr<'a> { } } - pub(crate) fn index(expr: Expr<'a>, index: Expr<'a>) -> Self { + pub(crate) fn index(base: Expr<'a>, index: Expr<'a>) -> Self { Expr::Index { - expr: Box::new(expr), + base: Box::new(base), index: Box::new(index), } } - pub(crate) fn field(expr: Expr<'a>, field: Ident<'a>) -> Self { + pub(crate) fn field(base: Expr<'a>, field: Ident<'a>) -> Self { Expr::Field { - expr: Box::new(expr), + base: Box::new(base), field, } } @@ -117,11 +117,11 @@ impl<'a> Expr<'a> { } expr.validate() } - Expr::Index { expr, index } => { + Expr::Index { base, index } => { index.validate()?; - expr.validate() + base.validate() } - Expr::Field { expr, field: _ } => expr.validate(), + Expr::Field { base, field: _ } => base.validate(), Expr::Paren(expr) => expr.validate(), Expr::Path(_) => Ok(()), Expr::Literal(lit) => lit.validate(), @@ -145,12 +145,12 @@ impl<'a> Expr<'a> { impl<'a> From<&DestrPat<'a>> for Expr<'a> { fn from(value: &DestrPat<'a>) -> Self { match value { - DestrPat::Index { pat, index } => Expr::Index { - expr: Box::new(pat.as_ref().into()), + DestrPat::Index { base, index } => Expr::Index { + base: Box::new(base.as_ref().into()), index: index.clone(), }, - DestrPat::Field { pat, field } => Expr::Field { - expr: Box::new(pat.as_ref().into()), + DestrPat::Field { base, field } => Expr::Field { + base: Box::new(base.as_ref().into()), field: *field, }, DestrPat::Paren(pat) => Expr::Paren(Box::new(pat.as_ref().into())), diff --git a/crates/rebel-parse/src/ast/pat.rs b/crates/rebel-parse/src/ast/pat.rs index 1a48372..7365b19 100644 --- a/crates/rebel-parse/src/ast/pat.rs +++ b/crates/rebel-parse/src/ast/pat.rs @@ -18,11 +18,11 @@ impl<'a> Pat<'a> { #[derive(Debug, Clone, PartialEq, Eq)] pub enum DestrPat<'a> { Index { - pat: Box<DestrPat<'a>>, + base: Box<DestrPat<'a>>, index: Box<Expr<'a>>, }, Field { - pat: Box<DestrPat<'a>>, + base: Box<DestrPat<'a>>, field: Ident<'a>, }, Paren(Box<DestrPat<'a>>), @@ -32,12 +32,12 @@ pub enum DestrPat<'a> { impl<'a> DestrPat<'a> { pub fn validate(&self) -> Result<(), ValidationError> { match self { - DestrPat::Index { pat, index } => { - pat.validate()?; + DestrPat::Index { base, index } => { + base.validate()?; index.validate()?; Ok(()) } - DestrPat::Field { pat, field: _ } => pat.validate(), + DestrPat::Field { base, field: _ } => base.validate(), DestrPat::Paren(pat) => pat.validate(), DestrPat::Path(_) => Ok(()), } diff --git a/crates/rebel-parse/src/grammar/recipe.rs b/crates/rebel-parse/src/grammar/recipe.rs index 8903eec..2aa665a 100644 --- a/crates/rebel-parse/src/grammar/recipe.rs +++ b/crates/rebel-parse/src/grammar/recipe.rs @@ -84,12 +84,12 @@ peg::parser! { / ident:ident() { Pat::Ident(ident) } pub rule destr_pat() -> DestrPat<'a> = precedence! { - pat:@ p('[') index:expr() p(']') { - DestrPat::Index { pat: Box::new(pat), index: Box::new(index) } + base:@ p('[') index:expr() p(']') { + DestrPat::Index { base: Box::new(base), index: Box::new(index) } } -- - pat:@ p('.') field:field() { - DestrPat::Field { pat: Box::new(pat), field } + base:@ p('.') field:field() { + DestrPat::Field { base: Box::new(base), field } } -- p('(') pat:destr_pat() p(')') { DestrPat::Paren(Box::new(pat)) } @@ -126,12 +126,12 @@ peg::parser! { expr:@ p('(') params:call_params() p(')') { Expr::apply(expr, params) } - expr:@ p('[') index:expr() p(']') { Expr::index(expr, index) } + base:@ p('[') index:expr() p(']') { Expr::index(base, index) } -- expr:@ p('.') method:field() p('(') params:call_params() p(')') { Expr::method(expr, method, params) } - expr:@ p('.') field:field() { Expr::field(expr, field) } + base:@ p('.') field:field() { Expr::field(base, field) } -- p('(') e:expr() p(')') { Expr::paren(e) } e:atom() { e } |