diff --git a/mps-interpreter/src/interpretor.rs b/mps-interpreter/src/interpretor.rs index c4c3166..c1732c5 100644 --- a/mps-interpreter/src/interpretor.rs +++ b/mps-interpreter/src/interpretor.rs @@ -162,9 +162,9 @@ pub(crate) fn standard_vocab(vocabulary: &mut MpsLanguageDictionary) { // sorters .add(crate::lang::vocabulary::sorters::empty_sort()) .add(crate::lang::vocabulary::sorters::shuffle_sort()) // accepts ~(shuffle) - .add(crate::lang::vocabulary::sorters::field_sort()) // accepts any ~(something) .add(crate::lang::vocabulary::sorters::bliss_sort()) .add(crate::lang::vocabulary::sorters::bliss_next_sort()) + .add(crate::lang::vocabulary::sorters::field_sort()) // accepts any ~(something) // iter blocks .add( crate::lang::MpsItemBlockFactory::new() diff --git a/mps-interpreter/src/lang/vocabulary/filters/field_filter.rs b/mps-interpreter/src/lang/vocabulary/filters/field_filter.rs index 0572001..a3c3bea 100644 --- a/mps-interpreter/src/lang/vocabulary/filters/field_filter.rs +++ b/mps-interpreter/src/lang/vocabulary/filters/field_filter.rs @@ -2,7 +2,7 @@ use std::collections::VecDeque; use std::fmt::{Debug, Display, Error, Formatter}; use super::utility::{assert_comparison_operator, comparison_op}; -use crate::lang::utility::{assert_token, assert_type, check_is_type, assert_empty}; +use crate::lang::utility::{assert_token, assert_type, check_is_type}; use crate::lang::MpsLanguageDictionary; use crate::lang::MpsTypePrimitive; use crate::lang::{MpsFilterFactory, MpsFilterPredicate, MpsFilterStatementFactory}; @@ -104,16 +104,15 @@ pub struct FieldFilterFactory; impl MpsFilterFactory for FieldFilterFactory { fn is_filter(&self, tokens: &VecDeque<&MpsToken>) -> bool { let tokens_len = tokens.len(); - (tokens_len >= 3 + (tokens_len >= 2 // field > variable OR field < variable && tokens[0].is_name() - && (tokens[1].is_open_angle_bracket() || tokens[1].is_close_angle_bracket()) - && (tokens[2].is_name() || check_is_type(tokens[2]))) - || (tokens_len >= 4 // field >= variable OR field <= variable OR field != variable + && (tokens[1].is_open_angle_bracket() || tokens[1].is_close_angle_bracket())) + || (tokens_len >= 3 // field >= variable OR field <= variable OR field != variable && tokens[0].is_name() && (tokens[1].is_open_angle_bracket() || tokens[1].is_close_angle_bracket() || tokens[1].is_equals() || tokens[1].is_exclamation()) && tokens[2].is_equals() - && (tokens[3].is_name() || check_is_type(tokens[3]))) + && !(tokens_len > 3 && tokens[3].is_equals())) } fn build_filter( @@ -132,7 +131,7 @@ impl MpsFilterFactory for FieldFilterFactory { let compare_operator = assert_comparison_operator(tokens)?; if check_is_type(&tokens[0]) { let value = VariableOrValue::Value(assert_type(tokens)?); - assert_empty(tokens)?; + //assert_empty(tokens)?; Ok(FieldFilter { field_name: field, field_errors: FieldFilterErrorHandling::Error, @@ -149,7 +148,7 @@ impl MpsFilterFactory for FieldFilterFactory { MpsToken::Name("variable_name".into()), tokens, )?); - assert_empty(tokens)?; + //assert_empty(tokens)?; Ok(FieldFilter { field_name: field, field_errors: FieldFilterErrorHandling::Error, diff --git a/mps-interpreter/src/lang/vocabulary/filters/field_filter_maybe.rs b/mps-interpreter/src/lang/vocabulary/filters/field_filter_maybe.rs index 0202a5f..622057a 100644 --- a/mps-interpreter/src/lang/vocabulary/filters/field_filter_maybe.rs +++ b/mps-interpreter/src/lang/vocabulary/filters/field_filter_maybe.rs @@ -2,7 +2,7 @@ use std::collections::VecDeque; use super::utility::assert_comparison_operator; use super::{field_filter::VariableOrValue, FieldFilter, FieldFilterErrorHandling}; -use crate::lang::utility::{assert_token, assert_token_raw, assert_type, check_is_type, assert_empty}; +use crate::lang::utility::{assert_token, assert_token_raw, assert_type, check_is_type}; use crate::lang::MpsLanguageDictionary; use crate::lang::SyntaxError; use crate::lang::{MpsFilterFactory, MpsFilterStatementFactory}; @@ -13,17 +13,15 @@ pub struct FieldFilterMaybeFactory; impl MpsFilterFactory for FieldFilterMaybeFactory { fn is_filter(&self, tokens: &VecDeque<&MpsToken>) -> bool { let tokens_len = tokens.len(); - (tokens_len >= 4 // field > variable OR field < variable + (tokens_len >= 3 // field > variable OR field < variable && tokens[0].is_name() && (tokens[1].is_interrogation() || tokens[1].is_exclamation()) - && (tokens[2].is_open_angle_bracket() || tokens[2].is_close_angle_bracket()) - && (tokens[3].is_name() || check_is_type(tokens[3]))) - || (tokens_len >= 5 // field >= variable OR field <= variable OR field != variable + && (tokens[2].is_open_angle_bracket() || tokens[2].is_close_angle_bracket())) + || (tokens_len >= 4 // field >= variable OR field <= variable OR field != variable && tokens[0].is_name() && (tokens[1].is_interrogation() || tokens[1].is_exclamation()) && (tokens[2].is_open_angle_bracket() || tokens[2].is_close_angle_bracket() || tokens[2].is_equals() || tokens[2].is_exclamation()) - && tokens[3].is_equals() - && (tokens[4].is_name() || check_is_type(tokens[4]))) + && tokens[3].is_equals()) } fn build_filter( @@ -53,7 +51,7 @@ impl MpsFilterFactory for FieldFilterMaybeFactory { let compare_operator = assert_comparison_operator(tokens)?; if check_is_type(&tokens[0]) { let value = VariableOrValue::Value(assert_type(tokens)?); - assert_empty(tokens)?; + //assert_empty(tokens)?; Ok(FieldFilter { field_name: field, field_errors: error_f, @@ -70,7 +68,7 @@ impl MpsFilterFactory for FieldFilterMaybeFactory { MpsToken::Name("variable_name".into()), tokens, )?); - assert_empty(tokens)?; + //assert_empty(tokens)?; Ok(FieldFilter { field_name: field, field_errors: error_f, diff --git a/mps-interpreter/src/lang/vocabulary/filters/field_like_filter.rs b/mps-interpreter/src/lang/vocabulary/filters/field_like_filter.rs index 749468b..d40d4f6 100644 --- a/mps-interpreter/src/lang/vocabulary/filters/field_like_filter.rs +++ b/mps-interpreter/src/lang/vocabulary/filters/field_like_filter.rs @@ -2,7 +2,7 @@ use std::collections::VecDeque; use std::fmt::{Debug, Display, Error, Formatter}; use super::field_filter::{FieldFilterErrorHandling, VariableOrValue}; -use crate::lang::utility::{assert_name, assert_token, assert_token_raw, check_name, assert_empty}; +use crate::lang::utility::{assert_name, assert_token, assert_token_raw, check_name}; use crate::lang::MpsLanguageDictionary; use crate::lang::MpsTypePrimitive; use crate::lang::{MpsFilterFactory, MpsFilterPredicate, MpsFilterStatementFactory}; @@ -72,15 +72,13 @@ pub struct FieldLikeFilterFactory; impl MpsFilterFactory for FieldLikeFilterFactory { fn is_filter(&self, tokens: &VecDeque<&MpsToken>) -> bool { let tokens_len = tokens.len(); - (tokens_len >= 3 // field like variable + (tokens_len >= 2 // field like variable && tokens[0].is_name() - && check_name("like", tokens[1]) - && (tokens[2].is_name() || tokens[2].is_literal())) - || (tokens_len >= 4 // field? like variable OR field! like variable + && check_name("like", tokens[1])) + || (tokens_len >= 3 // field? like variable OR field! like variable && tokens[0].is_name() && (tokens[1].is_interrogation() || tokens[1].is_exclamation()) - && check_name("like", tokens[2]) - && (tokens[3].is_name() || tokens[3].is_literal())) + && check_name("like", tokens[2])) } fn build_filter( @@ -116,7 +114,7 @@ impl MpsFilterFactory for FieldLikeFilterFactory { tokens, )?; let value = VariableOrValue::Value(MpsTypePrimitive::String(literal)); - assert_empty(tokens)?; + //assert_empty(tokens)?; Ok(FieldLikeFilter { field_name: field, field_errors: error_handling, @@ -131,7 +129,7 @@ impl MpsFilterFactory for FieldLikeFilterFactory { MpsToken::Name("variable_name".into()), tokens, )?); - assert_empty(tokens)?; + //assert_empty(tokens)?; Ok(FieldLikeFilter { field_name: field, field_errors: FieldFilterErrorHandling::Error, diff --git a/mps-interpreter/src/lang/vocabulary/filters/field_match_filter.rs b/mps-interpreter/src/lang/vocabulary/filters/field_match_filter.rs index 82032a2..ff32faa 100644 --- a/mps-interpreter/src/lang/vocabulary/filters/field_match_filter.rs +++ b/mps-interpreter/src/lang/vocabulary/filters/field_match_filter.rs @@ -4,7 +4,7 @@ use std::fmt::{Debug, Display, Error, Formatter}; use regex::Regex; use super::field_filter::{FieldFilterErrorHandling, VariableOrValue}; -use crate::lang::utility::{assert_name, assert_token, assert_token_raw, check_name, assert_empty}; +use crate::lang::utility::{assert_name, assert_token, assert_token_raw, check_name}; use crate::lang::MpsLanguageDictionary; use crate::lang::MpsTypePrimitive; use crate::lang::{MpsFilterFactory, MpsFilterPredicate, MpsFilterStatementFactory}; @@ -83,15 +83,13 @@ pub struct FieldRegexFilterFactory; impl MpsFilterFactory for FieldRegexFilterFactory { fn is_filter(&self, tokens: &VecDeque<&MpsToken>) -> bool { let tokens_len = tokens.len(); - (tokens_len >= 3 // field like variable + (tokens_len >= 2 // field like variable && tokens[0].is_name() - && check_name("matches", tokens[1]) - && (tokens[2].is_name() || tokens[2].is_literal())) - || (tokens_len >= 4 // field? like variable OR field! like variable + && check_name("matches", tokens[1])) + || (tokens_len >= 3 // field? like variable OR field! like variable && tokens[0].is_name() && (tokens[1].is_interrogation() || tokens[1].is_exclamation()) - && check_name("matches", tokens[2]) - && (tokens[3].is_name() || tokens[3].is_literal())) + && check_name("matches", tokens[2])) } fn build_filter( @@ -133,7 +131,7 @@ impl MpsFilterFactory for FieldRegexFilterFactory { })?; let compiled_cache = (literal.clone(), regex_c); let value = VariableOrValue::Value(MpsTypePrimitive::String(literal)); - assert_empty(tokens)?; + //assert_empty(tokens)?; Ok(FieldRegexFilter { field_name: field, field_errors: error_handling, @@ -149,7 +147,7 @@ impl MpsFilterFactory for FieldRegexFilterFactory { MpsToken::Name("variable_name".into()), tokens, )?); - assert_empty(tokens)?; + //assert_empty(tokens)?; Ok(FieldRegexFilter { field_name: field, field_errors: FieldFilterErrorHandling::Error, diff --git a/mps-interpreter/src/lang/vocabulary/filters/range_filter.rs b/mps-interpreter/src/lang/vocabulary/filters/range_filter.rs index 28e229b..2ba8353 100644 --- a/mps-interpreter/src/lang/vocabulary/filters/range_filter.rs +++ b/mps-interpreter/src/lang/vocabulary/filters/range_filter.rs @@ -101,40 +101,12 @@ pub struct RangeFilterFactory; impl MpsFilterFactory for RangeFilterFactory { fn is_filter(&self, tokens: &VecDeque<&MpsToken>) -> bool { - ( - // .. - tokens.len() == 2 && tokens[0].is_dot() && tokens[1].is_dot() - ) || (tokens.len() == 3 - && (( - // ..number - tokens[0].is_dot() && tokens[1].is_dot() && Lookup::check_is(tokens[2]) - ) || ( - // number.. - Lookup::check_is(tokens[0]) && tokens[1].is_dot() && tokens[2].is_dot() - ))) - || (tokens.len() == 4 - && (( - // number..number - Lookup::check_is(tokens[0]) - && tokens[1].is_dot() - && tokens[2].is_dot() - && Lookup::check_is(tokens[3]) - ) || ( - // ..=number - tokens[0].is_dot() - && tokens[1].is_dot() - && tokens[2].is_equals() - && Lookup::check_is(tokens[3]) - ))) - || ( - // number..=number - tokens.len() == 5 + tokens.len() >= 2 + && ((tokens.len() >= 2 && tokens[0].is_dot() && tokens[1].is_dot()) + || (tokens.len() >= 3 && Lookup::check_is(tokens[0]) && tokens[1].is_dot() - && tokens[2].is_dot() - && tokens[3].is_equals() - && Lookup::check_is(tokens[4]) - ) + && tokens[2].is_dot())) } fn build_filter( diff --git a/mps-interpreter/src/lang/vocabulary/filters/unique.rs b/mps-interpreter/src/lang/vocabulary/filters/unique.rs index 3e3ea23..da7ca3b 100644 --- a/mps-interpreter/src/lang/vocabulary/filters/unique.rs +++ b/mps-interpreter/src/lang/vocabulary/filters/unique.rs @@ -90,9 +90,7 @@ pub struct UniqueFilterFactory; impl MpsFilterFactory for UniqueFilterFactory { fn is_filter(&self, tokens: &VecDeque<&MpsToken>) -> bool { - (tokens.len() == 2 || tokens.len() == 3) - && check_name("unique", &tokens[0]) - && tokens[1].is_name() + tokens.len() >= 2 && check_name("unique", &tokens[0]) } fn build_filter( diff --git a/mps-interpreter/src/lang/vocabulary/sorters/bliss_next_sorter.rs b/mps-interpreter/src/lang/vocabulary/sorters/bliss_next_sorter.rs index b21e107..5d046f6 100644 --- a/mps-interpreter/src/lang/vocabulary/sorters/bliss_next_sorter.rs +++ b/mps-interpreter/src/lang/vocabulary/sorters/bliss_next_sorter.rs @@ -147,9 +147,7 @@ pub struct BlissNextSorterFactory; impl MpsSorterFactory for BlissNextSorterFactory { fn is_sorter(&self, tokens: &VecDeque<&MpsToken>) -> bool { - tokens.len() == 2 - && check_name("advanced", tokens[0]) - && check_name("bliss_next", tokens[1]) + tokens.len() > 1 && check_name("advanced", tokens[0]) && check_name("bliss_next", tokens[1]) } fn build_sorter( diff --git a/mps-interpreter/src/lang/vocabulary/sorters/bliss_sorter.rs b/mps-interpreter/src/lang/vocabulary/sorters/bliss_sorter.rs index 4495f0e..13307f4 100644 --- a/mps-interpreter/src/lang/vocabulary/sorters/bliss_sorter.rs +++ b/mps-interpreter/src/lang/vocabulary/sorters/bliss_sorter.rs @@ -141,7 +141,7 @@ pub struct BlissSorterFactory; impl MpsSorterFactory for BlissSorterFactory { fn is_sorter(&self, tokens: &VecDeque<&MpsToken>) -> bool { - tokens.len() == 2 + tokens.len() > 1 && check_name("advanced", tokens[0]) && check_name("bliss_first", tokens[1]) } diff --git a/mps-interpreter/src/lang/vocabulary/sorters/field_sorter.rs b/mps-interpreter/src/lang/vocabulary/sorters/field_sorter.rs index 1b239a6..3a0f510 100644 --- a/mps-interpreter/src/lang/vocabulary/sorters/field_sorter.rs +++ b/mps-interpreter/src/lang/vocabulary/sorters/field_sorter.rs @@ -60,7 +60,7 @@ pub struct FieldSorterFactory; impl MpsSorterFactory for FieldSorterFactory { fn is_sorter(&self, tokens: &VecDeque<&MpsToken>) -> bool { - tokens.len() == 1 && tokens[0].is_name() + !tokens.is_empty() && tokens[0].is_name() } fn build_sorter( diff --git a/mps-interpreter/src/lang/vocabulary/sorters/shuffle.rs b/mps-interpreter/src/lang/vocabulary/sorters/shuffle.rs index 0e0c235..3afbf9a 100644 --- a/mps-interpreter/src/lang/vocabulary/sorters/shuffle.rs +++ b/mps-interpreter/src/lang/vocabulary/sorters/shuffle.rs @@ -71,8 +71,8 @@ pub struct ShuffleSorterFactory; impl MpsSorterFactory for ShuffleSorterFactory { fn is_sorter(&self, tokens: &VecDeque<&MpsToken>) -> bool { - (tokens.len() == 1 && check_name("shuffle", &tokens[0])) - || (tokens.len() == 2 + (!tokens.is_empty() && check_name("shuffle", &tokens[0])) + || (tokens.len() > 1 && check_name("random", &tokens[0]) && check_name("shuffle", &tokens[1])) }