-
-
Notifications
You must be signed in to change notification settings - Fork 2
Core type: Range #521
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
Draft
janiejestemja
wants to merge
20
commits into
release/0.0.7
Choose a base branch
from
feat/ranges
base: release/0.0.7
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+183
−1
Draft
Core type: Range #521
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
9831dfd
add range to core values
janiejestemja 15c593a
add display trait
janiejestemja 63d6549
refactor display and debug
janiejestemja a29e889
outfactor steps from range definition
janiejestemja 15a3efa
add some error handling for fallible ranges
janiejestemja 2855797
outfactor formatting into separate unit tests
janiejestemja e0c27be
add invalid range to unit test cases
janiejestemja b47ecc5
removed test cases for decimals from ranges
janiejestemja 823ca58
remove typed integers and fallible iterator implementations
janiejestemja ff5bbe8
add from frange and partial eq to range definition
janiejestemja 69768a8
move getter and setter from defintion to iterator
janiejestemja 53daa73
add step by function to range
janiejestemja 624b736
edit formatting test case
janiejestemja 41c41b5
removed generics and iterator
janiejestemja d9ddc9e
remove manual impl of partial eq from ranges and add hash derivation …
janiejestemja 9ccf691
WIP ranges marked todo!('OutRanged')
janiejestemja f3c0591
WIP ranges marked panic!('OutRanged')
janiejestemja 2088b9a
WIP ranges lost markers...
janiejestemja 89cacbb
WIP ranges add test for range to ast
janiejestemja 3d61a16
renamed RangeDefinition to Range
janiejestemja File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,5 +5,6 @@ pub mod error; | |
| pub mod integer; | ||
| pub mod list; | ||
| pub mod map; | ||
| pub mod range; | ||
| pub mod text; | ||
| pub mod r#type; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| use crate::values::core_values::integer::Integer; | ||
| use core::fmt; | ||
| use core::ops; | ||
|
|
||
| #[derive(Debug)] | ||
| pub enum RangeError { | ||
| StepOverflow, | ||
| InvalidRange, | ||
| } | ||
|
|
||
| #[derive(Clone, Eq, PartialEq, Hash)] | ||
| pub struct Range { | ||
| // lower bound (inclusive) | ||
| pub start: Integer, | ||
| // upper bound (exclusive) | ||
| pub end: Integer, | ||
| } | ||
|
|
||
| impl From<Range> for ops::Range<Integer> { | ||
| fn from(range: Range) -> Self { | ||
| range.start..range.end | ||
| } | ||
| } | ||
|
|
||
| impl From<ops::Range<Integer>> for Range { | ||
| fn from(range: ops::Range<Integer>) -> Self { | ||
| Range { | ||
| start: range.start, | ||
| end: range.end, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl Range { | ||
| pub fn new(start: Integer, end: Integer) -> Self { | ||
| Range { start, end } | ||
| } | ||
| pub fn is_empty(&self) -> bool { | ||
| self.end <= self.start | ||
| } | ||
| } | ||
|
|
||
| impl fmt::Debug for Range { | ||
| fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
| core::write!(f, "{:?}..{:?}", self.start, self.end) | ||
| } | ||
| } | ||
|
|
||
| impl fmt::Display for Range { | ||
| fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
| core::write!(f, "{}..{}", self.start, self.end) | ||
| } | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
| use crate::values::core_values::integer::Integer; | ||
|
|
||
| fn test_helper() -> (Integer, Integer, Integer) { | ||
| ( | ||
| Integer::from_string("11").unwrap(), | ||
| Integer::from_string("23").unwrap(), | ||
| Integer::from_string("3").unwrap(), | ||
| ) | ||
| } | ||
|
|
||
| #[test] | ||
| pub fn range_from_into() { | ||
| let (begin, ending, _) = test_helper(); | ||
| let dx_range = Range::new(begin, ending.clone()); | ||
| let std_range: ops::Range<Integer> = dx_range.clone().into(); | ||
| let other_dx_range: Range = std_range.clone().into(); | ||
|
|
||
| let other_std_range = ops::Range::from(other_dx_range.clone()); | ||
| let other_dx_range = Range::from(std_range.clone()); | ||
| assert_eq!(dx_range, other_dx_range); | ||
| assert_eq!(std_range, other_std_range); | ||
| } | ||
|
|
||
| #[test] | ||
| pub fn range_formatting() { | ||
| let (begin, ending, _) = test_helper(); | ||
| let range = Range::new(begin, ending.clone()); | ||
|
|
||
| let displayed = format!("{}", range); | ||
| let debugged = format!("{:?}", range); | ||
| assert_eq!(displayed, "11..23"); | ||
| assert_eq!(debugged, "Integer(11)..Integer(23)"); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,6 +13,7 @@ use crate::values::core_values::decimal::typed_decimal::TypedDecimal; | |
| use crate::values::core_values::endpoint::Endpoint; | ||
| use crate::values::core_values::integer::Integer; | ||
| use crate::values::core_values::integer::typed_integer::TypedInteger; | ||
| use crate::values::core_values::range; | ||
| use crate::values::pointer::PointerAddress; | ||
| use crate::visitor::VisitAction; | ||
| use crate::visitor::expression::visitable::{ | ||
|
|
@@ -74,6 +75,9 @@ pub trait ExpressionVisitor<E>: TypeExpressionVisitor<E> { | |
| DatexExpressionData::Integer(i) => { | ||
| self.visit_integer(i, &expr.span) | ||
| } | ||
| DatexExpressionData::Range(range) => { | ||
| self.visit_range_definition(range, &expr.span) | ||
| } | ||
| DatexExpressionData::TypedInteger(ti) => { | ||
| self.visit_typed_integer(ti, &expr.span) | ||
| } | ||
|
|
@@ -559,4 +563,14 @@ pub trait ExpressionVisitor<E>: TypeExpressionVisitor<E> { | |
| let _ = slot; | ||
| Ok(VisitAction::SkipChildren) | ||
| } | ||
|
|
||
| fn visit_range_definition( | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| &mut self, | ||
| range: &range::Range, | ||
| span: &Range<usize>, | ||
| ) -> ExpressionVisitResult<E> { | ||
| let _ = span; | ||
| let _ = range; | ||
| Ok(VisitAction::SkipChildren) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.