Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing public interfaces to ASG #31

Merged
merged 1 commit into from
Jan 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions crates/oq3_semantics/src/asg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,18 +294,29 @@ impl IndexExpression {

#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct IndexedIdentifier {
identifer: SymbolIdResult,
identifier: SymbolIdResult,
indexes: Vec<IndexOperator>,
}

impl IndexedIdentifier {
pub fn new(identifer: SymbolIdResult, indexes: Vec<IndexOperator>) -> IndexedIdentifier {
IndexedIdentifier { identifer, indexes }
pub fn new(identifier: SymbolIdResult, indexes: Vec<IndexOperator>) -> IndexedIdentifier {
IndexedIdentifier {
identifier,
indexes,
}
}

pub fn to_texpr(self) -> TExpr {
TExpr::new(Expr::IndexedIdentifier(self), Type::ToDo)
}

pub fn identifier(&self) -> &SymbolIdResult {
&self.identifier
}
Comment on lines +313 to +315
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fwiw, this return type isn't ideal from an interface, but it's consistent with the rest of the library for now so we can fix the rest later.

Ideally, all the Result objects would get resolved (or auto-unwrapped) and SymbolId would derive Copy (since it's just a usize), then the return type would be SymbolId (or something more strongly typed). If the Result is kept, then Result<&T, &E> is the more useful return type than &Result<T, E>, and you can go from the latter to the former with Result::as_ref, but that's also doable from downstream code, so not the end of the world.


pub fn indexes(&self) -> &[IndexOperator] {
&self.indexes
}
}

#[derive(Clone, Debug, PartialEq, Eq, Hash)]
Expand Down Expand Up @@ -392,6 +403,10 @@ impl SetExpression {
pub fn new(expressions: Vec<TExpr>) -> SetExpression {
SetExpression { expressions }
}

pub fn expressions(&self) -> &[TExpr] {
&self.expressions
}
}

#[derive(Clone, Debug, PartialEq, Eq, Hash)]
Expand Down