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

Feature/stk 3020 upgrade haystack 4 #21

Merged
merged 13 commits into from
Jan 6, 2025
4 changes: 2 additions & 2 deletions src/c_api/datetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use std::os::raw::c_char;
/// - result The Value to be updated with the result DateTime.
/// # Returns
/// - 1 (True) if the operation was successful, -1 otherwise in which case the [last_error_message](super::err::last_error_message)
/// can be called to get the error message.
/// can be called to get the error message.
/// # Example
/// ```rust
/// # use crate::libhaystack::val::Value;
Expand Down Expand Up @@ -79,7 +79,7 @@ pub unsafe extern "C" fn haystack_value_get_datetime_date(
/// - result The Value to be updated with the result Time.
/// # Returns
/// - 1 (True) if the operation was successful, -1 otherwise in which case the [last_error_message](super::err::last_error_message)
/// can be called to get the error message.
/// can be called to get the error message.
/// # Example
/// ```rust
/// # use crate::libhaystack::val::Value;
Expand Down
10 changes: 5 additions & 5 deletions src/c_api/dict.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use crate::{haystack::val::Value, val::List};
/// # Returns
/// - number of elements
/// - -1 if there was an error getting the length, in which case the [last_error_message](super::err::last_error_message)
/// can be called to get the error message.
/// can be called to get the error message.
/// # Example
/// ```rust
/// # use crate::libhaystack::val::Value;
Expand Down Expand Up @@ -53,7 +53,7 @@ pub unsafe extern "C" fn haystack_value_get_dict_len(val: *const Value) -> usize
/// - result The Value to be updated with the result Str List.
/// # Returns
/// - 1 (True) if the operation was successful, -1 otherwise in which case the [last_error_message](super::err::last_error_message)
/// can be called to get the error message.
/// can be called to get the error message.
/// # Example
/// ```rust
/// # use crate::libhaystack::val::Value;
Expand Down Expand Up @@ -113,7 +113,7 @@ pub unsafe extern "C" fn haystack_value_get_dict_keys(
/// - entry A [Value](crate::val::Value) to be inserted into the dict
/// # Returns
/// - 1 (True) if the operation was successful, -1 otherwise in which case the [last_error_message](super::err::last_error_message)
/// can be called to get the error message.
/// can be called to get the error message.
/// # Example
/// ```rust
/// # use crate::libhaystack::val::Value;
Expand Down Expand Up @@ -170,7 +170,7 @@ pub unsafe extern "C" fn haystack_value_insert_dict_entry(
/// - result The Value to be updated.
/// # Returns
/// - 1 (True) if the operation was successful, 0 (false) if no element found, -1 otherwise in which case the [last_error_message](super::err::last_error_message)
/// can be called to get the error message.
/// can be called to get the error message.
/// # Example
/// ```rust
/// # use crate::libhaystack::val::Value;
Expand Down Expand Up @@ -230,7 +230,7 @@ pub unsafe extern "C" fn haystack_value_get_dict_entry(
/// - key The key to be removed
/// # Returns
/// - 1 (True) if the operation was successful, -1 otherwise in which case the [last_error_message](super::err::last_error_message)
/// can be called to get the error message.
/// can be called to get the error message.
/// # Example
/// ```rust
/// # use crate::libhaystack::val::Value;
Expand Down
4 changes: 2 additions & 2 deletions src/c_api/grid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub unsafe extern "C" fn haystack_value_get_grid_len(val: *const Value) -> usize
/// [Dict](crate::val::Dict) [Value](crate::val::Value)s
/// # Arguments
/// - rows List](crate::val::List) [Value](crate::val::Value) of
/// [Dict](crate::val::Dict) [Value](crate::val::Value)s
/// [Dict](crate::val::Dict) [Value](crate::val::Value)s
/// # Returns
/// - The value pointer
/// - None if there was an error, in which case use [last_error_message](super::err::last_error_message)
Expand Down Expand Up @@ -112,7 +112,7 @@ pub unsafe extern "C" fn haystack_value_make_grid_from_rows(
/// [Dict](crate::val::Dict) [Value](crate::val::Value)s
/// # Arguments
/// - rows a [List](crate::val::List) [Value](crate::val::Value) of
/// [Dict](crate::val::Dict) [Value](crate::val::Value)s
/// [Dict](crate::val::Dict) [Value](crate::val::Value)s
/// # Returns
/// - The value pointer
/// - None if there was an error, in which case use [last_error_message](super::err::last_error_message)
Expand Down
8 changes: 4 additions & 4 deletions src/c_api/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub unsafe extern "C" fn haystack_value_get_list_len(val: *mut Value) -> usize {
/// - entry A [Value](crate::val::Value) to be inserted into the list
/// # Returns
/// - 1 (True) if the operation was successful, -1 otherwise in which case the [last_error_message](super::err::last_error_message)
/// can be called to get the error message.
/// can be called to get the error message.
/// # Example
/// ```rust
/// # use crate::libhaystack::val::Value;
Expand Down Expand Up @@ -92,7 +92,7 @@ pub unsafe extern "C" fn haystack_value_push_list_entry(
/// - result The Value to be updated with the result.
/// # Returns
/// - 1 (True) if the operation was successful, -1 otherwise in which case the [last_error_message](super::err::last_error_message)
/// can be called to get the error message.
/// can be called to get the error message.
/// # Example
/// ```rust
/// # use crate::libhaystack::val::Value;
Expand Down Expand Up @@ -146,7 +146,7 @@ pub unsafe extern "C" fn haystack_value_get_list_entry_at(
/// - element A [Value](crate::val::Value)
/// # Returns
/// - 1 (True) if the operation was successful, -1 otherwise in which case the [last_error_message](super::err::last_error_message)
/// can be called to get the error message.
/// can be called to get the error message.
/// # Example
/// ```rust
/// # use crate::libhaystack::val::Value;
Expand Down Expand Up @@ -206,7 +206,7 @@ pub unsafe extern "C" fn haystack_value_set_list_entry_at(
/// - index The index were to inset the value at
/// # Returns
/// - 1 (True) if the operation was successful, -1 otherwise in which case the [last_error_message](super::err::last_error_message)
/// can be called to get the error message.
/// can be called to get the error message.
/// # Example
/// ```rust
/// # use crate::libhaystack::val::Value;
Expand Down
2 changes: 1 addition & 1 deletion src/c_api/number.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub unsafe extern "C" fn haystack_value_get_number_value(val: *const Value) -> f
/// # Returns
/// - 1 if has unit, 0 otherwise
/// - -1 if there was an error, in which case the [last_error_message](super::err::last_error_message)
/// can be called to get the error message.
/// can be called to get the error message.
/// # Example
/// ```rust
/// # use crate::libhaystack::val::Value;
Expand Down
44 changes: 31 additions & 13 deletions src/haystack/defs/namespace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ impl<'a> Namespace<'a> {
}

/// Returns the supertypes of a def or an empty list if it can't be found.
pub fn supertypes_of(&'a self, symbol: &Symbol) -> MapReadRef<Symbol, Vec<&'a Dict>> {
pub fn supertypes_of(&'a self, symbol: &Symbol) -> MapReadRef<'a, Symbol, Vec<&'a Dict>> {
if let Some(super_types) = self.supertypes_of_cache.get(symbol) {
super_types
} else {
Expand Down Expand Up @@ -315,8 +315,12 @@ impl<'a> Namespace<'a> {

/// Returns a list of choices for def.
pub fn choices_for(&self, symbol: &Symbol) -> &Vec<Dict> {
if let Some(of) = self.get(symbol).and_then(|def| def.get_symbol("of")) {
self.subtypes_of(of)
if self
.get(symbol)
.and_then(|def| self.is_choice(def).then_some(Some(true)))
garethj2 marked this conversation as resolved.
Show resolved Hide resolved
.is_some()
{
self.subtypes_of(symbol)
} else {
&EMPTY_VEC_DICT
}
Expand All @@ -326,13 +330,22 @@ impl<'a> Namespace<'a> {
/// all defs that are choices.
fn compute_choices(&mut self) {
for (sym, def) in &self.defs {
if def.get_symbol("of").is_some() {
// A choice extends directly from 'choice'.
if self.is_choice(def) {
self.choices
.insert(sym.clone(), self.choices_for(sym).clone());
}
}
}

fn is_choice(&self, def: &Dict) -> bool {
if let Some(is_a_list) = def.get_list("is") {
garethj2 marked this conversation as resolved.
Show resolved Hide resolved
is_a_list.iter().any(|v| v == &Value::make_symbol("choice"))
} else {
false
}
}

/// Compute a list of the features names.
fn compute_feature_names(&mut self) {
let mut features = HashSet::<&str>::new();
Expand Down Expand Up @@ -386,7 +399,7 @@ impl<'a> Namespace<'a> {
}

/// Return the defs inheritance as a flattened array of defs.
pub fn inheritance(&'a self, symbol: &Symbol) -> MapReadRef<Symbol, Vec<&'a Dict>> {
pub fn inheritance(&'a self, symbol: &Symbol) -> MapReadRef<'a, Symbol, Vec<&'a Dict>> {
if let Some(inheritance) = self.inheritance_of_cache.get(symbol) {
inheritance
} else {
Expand All @@ -410,7 +423,7 @@ impl<'a> Namespace<'a> {
/// - parent The parent def.
/// - association The association.
///
pub fn associations(&'a self, parent: &Symbol, association: &Symbol) -> Vec<&Dict> {
pub fn associations(&'a self, parent: &Symbol, association: &Symbol) -> Vec<&'a Dict> {
if let Some(association_def) = self.get(association) {
// Make sure the association exists and is an association.
if matches!(
Expand All @@ -424,7 +437,7 @@ impl<'a> Namespace<'a> {

// If the association isn't computed then just get the associated defs.
// For instance, this will return here if the association is 'tagOn'.
if !association_def.has("computed") {
if !association_def.has("computedFromReciprocal") {
return self
.get(parent)
.and_then(|def| def.get_list(&association.value))
Expand Down Expand Up @@ -457,7 +470,7 @@ impl<'a> Namespace<'a> {
&'a self,
parent: &Symbol,
reciprocal_of: &Symbol,
) -> Vec<&Dict> {
) -> Vec<&'a Dict> {
let inheritance = self.inheritance(parent);

let mut matches = HashSet::<&Dict>::new();
Expand All @@ -484,7 +497,7 @@ impl<'a> Namespace<'a> {
/// - parent The parent def
/// # Return
/// The `is` association defs
pub fn is(&'a self, parent: &Symbol) -> Vec<&Dict> {
pub fn is(&'a self, parent: &Symbol) -> Vec<&'a Dict> {
self.associations(parent, &Symbol::from("is"))
}

Expand All @@ -493,7 +506,7 @@ impl<'a> Namespace<'a> {
/// - parent The parent def
/// # Return
/// The `tagOn` association defs
pub fn tag_on(&'a self, parent: &Symbol) -> Vec<&Dict> {
pub fn tag_on(&'a self, parent: &Symbol) -> Vec<&'a Dict> {
self.associations(parent, &Symbol::from("tagOn"))
}

Expand All @@ -502,7 +515,7 @@ impl<'a> Namespace<'a> {
/// - parent The parent def
/// # Return
/// The `tags` association defs
pub fn tags(&'a self, parent: &Symbol) -> Vec<&Dict> {
pub fn tags(&'a self, parent: &Symbol) -> Vec<&'a Dict> {
self.associations(parent, &Symbol::from("tags"))
}

Expand All @@ -511,7 +524,7 @@ impl<'a> Namespace<'a> {
/// - subject The subject to reflect
/// # Return
/// The reflected defs
pub fn reflect(&'a self, subject: &Dict) -> Reflection {
pub fn reflect<'b>(&'a self, subject: &'b Dict) -> Reflection<'a> {
let mut defs = Vec::<&Dict>::new();
let mut markers = HashSet::<&str>::new();

Expand Down Expand Up @@ -700,7 +713,12 @@ impl<'a> Namespace<'a> {
.keys()
.map(|name| self.protos_from_def(parent, name))
.fold(Vec::new(), |mut vec, cur| {
vec.extend(cur);
for x in cur.into_iter() {
if !vec.contains(&x) {
garethj2 marked this conversation as resolved.
Show resolved Hide resolved
vec.push(x);
}
}

vec
})
}
Expand Down
7 changes: 0 additions & 7 deletions src/haystack/encoding/zinc/decode/complex/grid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,6 @@ use super::dict::parse_dict_parts;
use crate::haystack::val::{Column, Dict, Grid, Value};
use std::io::{Error, Read};

// Zinc [Grid](crate::val::Grid) meta
#[derive(PartialEq, PartialOrd, Clone, Debug)]
struct GridMeta {
ver: String,
meta: Option<Dict>,
}

/// Parses a Zinc [Grid](crate::val::Grid)
/// # Arguments
/// - a generic ParserType
Expand Down
7 changes: 4 additions & 3 deletions src/haystack/encoding/zinc/decode/id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
//! Zinc identifier decoding

use super::scanner::Scanner;
use std::fmt::Display;
use std::io::{Error, Read};
use std::string::ToString;

Expand All @@ -21,9 +22,9 @@ impl From<&str> for Id {
}
}

impl ToString for Id {
fn to_string(&self) -> String {
self.value.clone()
impl Display for Id {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "{}", self.value.clone())
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/haystack/encoding/zinc/decode/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ impl<'a, R: Read> Lexer<Scanner<'a, R>> {
}
}

impl<'a, R: Read> Iterator for Lexer<Scanner<'a, R>> {
impl<R: Read> Iterator for Lexer<Scanner<'_, R>> {
type Item = Result<LexerToken, Error>;

fn next(&mut self) -> Option<Self::Item> {
Expand Down
4 changes: 2 additions & 2 deletions src/haystack/encoding/zinc/decode/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ pub struct Parser<Lexer> {
pub(super) lexer: Lexer,
}

impl<'a, 'b: 'a, R: Read> Parser<Lexer<Scanner<'b, R>>> {
impl<'a, R: Read> Parser<Lexer<Scanner<'a, R>>> {
/// Constructs a [Parser](self::Parser) for the provided [Read](std::io::Read)
pub fn make(input: &'b mut R) -> Result<Self, Error> {
pub fn make(input: &'a mut R) -> Result<Self, Error> {
let mut lexer = Lexer::make(input)?;
// Advance lexer to first token
lexer.read()?;
Expand Down
4 changes: 2 additions & 2 deletions src/haystack/filter/eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub trait Eval {
/// # Arguments
/// * `dict` - the Dict to match the Filter against
/// * `resolver` - a generic `PathResolver` that resolves `Path`s
/// indirection specified in the `Filter`
/// indirection specified in the `Filter`
fn eval<R: PathResolver>(&self, context: &EvalContext<R>) -> bool;
}

Expand All @@ -34,7 +34,7 @@ impl<'a, 'b: 'a, R: PathResolver> EvalContext<'a, 'b, R> {
/// * `dict` - the Dict to match the Filter against
/// * `ns` - the Def namespace to match symbol definitions against
/// * `resolver` - a generic `PathResolver` that resolves `Path`s
/// indirection specified in the `Filter`
/// indirection specified in the `Filter`
pub fn make(dict: &'a Dict, ns: &'b Namespace<'b>, resolver: &'a R) -> Self {
Self { dict, ns, resolver }
}
Expand Down
Loading
Loading