Skip to content

Simplify BergValue interface #44

Description

@jkeiser

Replace infix, prefix, etc. with one method:

pub trait BergValue<'a> {
    ...
    /// Perform an operation on this BergValue, and return the result as well
    /// as the updated BergValue.
    /// 
    /// Returns:
    /// - `Err(error)` if there was an error performing this operation.
    /// - `Ok((current, new_self))` if the operation worked out fine.
    fn operate(self, operation: Operation<impl BergValue<'a>>) -> BergResult<'a, (BergResult<'a>, BergResult<'a>)>;
}

pub enum Operation<Operand> {
    Infix { operator: IdentifierIndex, is_assign: bool, right: Operand },
    Postfix { operator: IdentifierIndex },
    Prefix { operator: IdentifierIndex },
    SubExpression { boundary: ExpressionBoundary },
    Field { field: IdentifierIndex },
    SetField { field: IdentifierIndex, value: Operand },
    NextVal
}

The intent is threefold:

  • Make lazy values and proxies easier (since they are so prevalent)
  • Unify all operations so they follow the same pattern, so that typechecking will be clearer
  • Simplify BergValue implementors

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions